vmware / terraform-provider-vra

Terraform Provider for VMware Aria Automation
https://registry.terraform.io/providers/vmware/vra/
Mozilla Public License 2.0
103 stars 92 forks source link

vra_flavor_profile does not allow you to specify cpu_count or memory #445

Closed cybrknght closed 2 years ago

cybrknght commented 2 years ago

Code of Conduct

This project has a Code of Conduct that all participants are expected to understand and follow:

vRA Version

vRA version 8.8.1

Terraform Version

Terraform version 1.23

vRA Terraform Provider Version

vra provider version 0.5.1

Affected Resource(s)

Terraform Configuration Files

# Input variable: url
variable "url" {
  description = "The URL of the vRealize Automation environment either vRA 8.x or vRA Cloud"
  type = string
  default = "https://vra-fqdn"
}

# Input variable: refresh_token
variable "refresh_token" {
  description = "The refresh token to connect to the vRealize Automation environment"
  type = string
  default = ""
}

# Input variable: insecure
variable "insecure" {
  description = "Should SSL verification be skipped? true = skip ssl verification"
  type = bool
  default = "false"
}

# Input variable: region_name
variable "region_name" {
  description = "vRA Project Name to be added to the project"
  type = string
  default = ""
}

terraform {
  required_version = ">= 0.13"
  required_providers {
    vra = {
      source  = "vmware/vra"
      version = "0.5.1"
    }
  }
}

provider "vra" {
  url           = var.url
  refresh_token = var.refresh_token
  insecure      = var.insecure
}

data "vra_region" "this" {
  filter = "name eq '${var.region_name}'"
}

resource "vra_flavor_profile" "this" {
  name        = "vCenter"
  description = "flavors/image types vcenter"
  region_id  = "${data.vra_region.this.id}"

  flavor_mapping {
 #   name = "micro"
    instance_type = "t2.micro"
    cpu_count = 1
    memory = 1024
  }
}

Expected Behavior

You should be able to specify flavor_mappings using either name and instance_type or cpu_count and memory. (This is how the API '/iaas/api/flavor-profiles' works.) In addition, for this to work, you should also be able to specify the 'flavor name' along with the name and instance_type or cpu_count and memory. Currently, the name and 'flavor name' are the same, which are two separate things in the API.

Actual Behavior

If you specify the name and cpu_count and memory together, you get the following error:

Error: [POST /iaas/api/flavor-profiles][400] createFlavorProfileBadRequest &{Message:Invalid request: flavorMapping "medium" contains both "name" and "memoryInMB" and/or "cpuCount". Either one should be supplied but not both. StatusCode:400}

However, if you specify only cpu_count and memory, you get an error saying "Error: Missing required argument, The argument "name" is required, but no definition was found.'

Steps to Reproduce

  1. Write a terraform file using the vra_flavor_profile provider, create a vra_flavor_profile with a flavor_mapping that only contains cpu_count and memory, instead of name
  2. terraform apply

Community Note

frodenas commented 2 years ago

The error message returned from the API is confusing, when it says name, it is referring to instance_type (in your example, t2.micro), not the flavor mapping name (in your example, micro).

Flavor mapping name is a mandatory attribute, the attributes that cannot be specified together are instance_type with cpu_count/memory. instance_type should be used when mapping a public cloud instance type, and cpu_count/memory when mapping a private cloud like vSphere. For example:

resource "vra_flavor_profile" "aws" {
  name        = "tf-aws-flavor-profile"
  description = "My AWS flavor"
  region_id   = data.vra_region.aws.id

  flavor_mapping {
    name          = "small"
    instance_type = "t2.small"
  }

  flavor_mapping {
    name          = "medium"
    instance_type = "t2.medium"
  }
}

resource "vra_flavor_profile" "vsphere" {
  name        = "tf-vsphere-flavor-profile"
  description = "My vSphere flavor"
  region_id   = data.vra_region.vsphere.id

  flavor_mapping {
    name      = "small"
    cpu_count = 2
    memory    = 2048
  }

  flavor_mapping {
    name      = "medium"
    cpu_count = 4
    memory    = 4096
  }
}

At #460, I've updated the attribute descriptions, examples, and documentation to reflect this.