Skip to content

cloudstack_instance: service_offering filtering issue #260

@poddm

Description

@poddm

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

"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:

Example

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"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions