poddm opened a new issue, #260:
URL: https://github.com/apache/cloudstack-terraform-provider/issues/260

   ## issue
   
   In the `cloudstack_instance` resource, specifying a `service_offering` by 
name does not filter the lookup by zone. This can lead to errors when multiple 
service offerings share the same name but are restricted to specific zones.
   
   For example, you may encounter the following error if a service offering 
name is duplicated across zones:
   
   > Error: Error creating the new instance xyz: CloudStack API error 531 
(CSExceptionErrorCode: 4365): There's no way to confirm Account 
[{"accountName":"PrjAcct-Cloudstack","id":44,"uuid":"ee2d397d-6fa2-4c86-a0fb-22600d7ae7b6"}]
 has access to Service offering 
{"id":198,"name":"standard","uuid":"6af5e24b-2b69-4012-8d4a-864ea7e49bf3"}
   
   This is an interesting way to say you don't have access to this specific 
offering in that zone.
   
   ## code
   
   ```golang
   
   "service_offering": {
        Type:     schema.TypeString,
        Required: true,
   },
   "template": {
        Type:     schema.TypeString,
        Required: true,
        ForceNew: true,
   },
   
   ....
   
   // Retrieve the service_offering ID
   serviceofferingid, e := retrieveID(cs, "service_offering", 
d.Get("service_offering").(string))
   if e != nil {
        return e.Error()
   }
   // Retrieve the template ID
   templateid, e := retrieveTemplateID(cs, zone.Id, d.Get("template").(string))
   if e != nil {
        return e.Error()
   }
   ```
   
   
   
   ## proposed solution
   
   Remove the name-based lookup and filtering for `service_offering` and 
`template` offerings with a typical data pattern. Terraform should not extend 
the `createServiceInstance` API beyond its intended usage, as 
`serviceofferingid` and `templateid` are required fields.
   
   API Reference: 
   - 
https://cloudstack.apache.org/api/apidocs-4.21/apis/createServiceInstance.html
   - 
https://cloudstack.apache.org/api/apidocs-4.21/apis/listServiceOfferings.html
   - https://cloudstack.apache.org/api/apidocs-4.21/apis/listTemplates.html
   
   Example
   
   ```hcl
   data "cloudstack_template" "my_template" {
     template_filter = "featured"
   
     filter {
       name = "name"
       value = "CentOS 7\\.1"
     }
   
     filter {
       name = "hypervisor"
       value = "KVM"
     }
   }
   
   
   data "cloudstack_service_offering" "service-offering-data-source"{
   filter{
     name = "name"
     value = "TestServiceUpdate"
     }  
   }
   
   resource "cloudstack_instance" "web" {
     name                         = example
     service_offering_id = 
data.cloudstack_service_offering.service-offering-data-source
     network_id               = "6eb22f91-7454-4107-89f4-36afcdf33021"
     template                   = data.cloudstack_template.my_template
     zone                          = "zone-1"
   }
   
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to