nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
101 stars 112 forks source link

Creating project succeeds but subsequent runs (no changes to input data) fails and always wants to make changes within default_subnet_reference #695

Open phillipmacey opened 1 month ago

phillipmacey commented 1 month ago

Nutanix Cluster Information

PC 2024.2

Terraform Version

Terraform v1.9.8 on darwin_arm64

Affected Resource(s)

Terraform Configuration Files


variable "networks" {
  type          = map(object({
    networkType = optional(string,"VLAN"),
    networkId   = number,
    cluster     = string,
    description = optional(string),
    tenants     = set(string)
  }))
  default       = {}
  description   = "List of networks (vlans) that should exist"
}

variable "tenants" {
  type        = map(object({
    name        = string,
    description = string,
  }))
  default     = {}
  description = "List of tenants and their required attributes"
}

tenants = {  
  "testProject"        = {
    name       = "testProject"
    description        = "Test project"
  }
}

networks = {
  "testSubnet"       = {
    networkId   = 1234
    tenants     = []
    cluster     = "my-cluster-name"
    description = "test network"
  }  
} 

cluster = {
  "my-cluster-name": "11111111-1111-1111-1111-111111111111"
}

resource "nutanix_subnet" "networks" {
  for_each      = var.networks
  name          = each.key
  description   = each.value.description
  vlan_id       = each.value.networkId
  subnet_type   = each.value.networkType
  cluster_uuid  = var.cluster[each.value.cluster]
}

resource "nutanix_project" "projects" {
  for_each      = var.tenants
  name          = each.value.name 
  description   = each.value.description
  cluster_uuid  = var.cluster["my-cluster-name"]
  default_subnet_reference {
    uuid = nutanix_subnet.networks["testSubnet"].metadata.uuid
    # Have tried both with and without the name value below.. with it not set, the terraform plan output shows name=null
    # in its proposed list of changes so I added it in to see what changed. The only difference is that the terraform output
    # lists a value rather than null. The same error is still generated
    #name = each.value.name
  } 
}

Debug Output

I have captured full debug logs and can provide them directly to someone if needed however I will not be publishing them on the interwebs.

First run change plan output:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

Terraform will perform the following actions:

  # nutanix_project.projects["testProject"] will be created
  + resource "nutanix_project" "projects" {
      + api_version       = (known after apply)
      + cluster_uuid      = "0006237c-7e50-ebfd-2895-00e0ed6aeeb9"
      + description       = "Test project"
      + id                = (known after apply)
      + is_default        = (known after apply)
      + metadata          = (known after apply)
      + name              = "testProject"
      + owner_reference   = (known after apply)
      + project_reference = (known after apply)
      + state             = (known after apply)

      + account_reference_list (known after apply)

      + categories {
          + name  = "tenant"
          + value = "testProject"
        }

      + cluster_reference_list (known after apply)

      + default_environment_reference (known after apply)

      + default_subnet_reference {
          + kind = "subnet"
          + name = "testSubnet"
          + uuid = "1d04b3d7-2733-401a-9709-ee85616969c4"
        }

      + environment_reference_list (known after apply)

      + external_network_list (known after apply)

      + external_user_group_reference_list (known after apply)

      + subnet_reference_list (known after apply)

      + tunnel_reference_list (known after apply)

      + user_reference_list (known after apply)

      + vpc_reference_list (known after apply)
    }

  # nutanix_subnet.networks["testNetwork"] will be created
  + resource "nutanix_subnet" "networks" {
      + api_version                      = (known after apply)
      + availability_zone_reference      = (known after apply)
      + cluster_name                     = (known after apply)
      + cluster_uuid                     = "0006237c-7e50-ebfd-2895-00e0ed6aeeb9"
      + default_gateway_ip               = (known after apply)
      + description                      = "A test vlan"
      + dhcp_domain_name_server_list     = (known after apply)
      + dhcp_domain_search_list          = (known after apply)
      + dhcp_options                     = (known after apply)
      + dhcp_server_address              = (known after apply)
      + dhcp_server_address_port         = (known after apply)
      + enable_nat                       = (known after apply)
      + id                               = (known after apply)
      + ip_config_pool_list_ranges       = (known after apply)
      + is_external                      = (known after apply)
      + metadata                         = (known after apply)
      + name                             = "testNetwork"
      + network_function_chain_reference = (known after apply)
      + owner_reference                  = (known after apply)
      + prefix_length                    = (known after apply)
      + project_reference                = (known after apply)
      + state                            = (known after apply)
      + subnet_ip                        = (known after apply)
      + subnet_type                      = "VLAN"
      + vlan_id                          = 1234
      + vpc_reference_uuid               = (known after apply)
      + vswitch_name                     = (known after apply)

      + categories (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.
╷
│ Warning: Disabled Providers: ndb, foundation. Please provide required fields in provider configuration to enable them. Refer docs.
│ 
│   with provider["registry.terraform.io/nutanix/nutanix"],
│   on providers.tf line 18, in provider "nutanix":
│   18: provider "nutanix" {
│ 

Second (and third, fourth, etc) run change plan output:

Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # nutanix_project.projects["testProject"] will be updated in-place
  ~ resource "nutanix_project" "projects" {
        id                = "b0a4e17e-fdf3-4e99-b323-b47a75b13ce1"
        name              = "testProject"
        # (8 unchanged attributes hidden)

      ~ default_subnet_reference {
          + kind = "subnet"
            name = null
          + uuid = "1d04b3d7-2733-401a-9709-ee85616969c4"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Resulting error

Since terraform's plan on the second run showed a name = null for the default_subnet_reference, I tried setting a name attribute within there however there was no change in behaviour after doing this (other than terraform listing a value against the name in the plan output). This ultimately generates the error below:

│ Error: error waiting for project(b0a4e17e-fdf3-4e99-b323-b47a75b13ce1) to update: error_detail: , progress_message: update_project
│ 
│   with nutanix_project.projects["testProject"],
│   on main.tf line 29, in resource "nutanix_project" "projects":
│   29: resource "nutanix_project" "projects" {

When running terraform with debug logging enabled (TF_LOG=DEBUG), I can see it reporting the following API call/responses:

GET'ing the project
---[ REQUEST ]---------------------------------------
GET /api/nutanix/v3/projects/b0a4e17e-fdf3-4e99-b323-b47a75b13ce1 HTTP/1.1
---[ RESPONSE ]--------------------------------------
HTTP/1.1 200 OK
{
 "api_version": "3.1",
 "metadata": {
  "last_update_time": "2024-10-23T01:58:31Z",
  "kind": "project",
  "uuid": "b0a4e17e-fdf3-4e99-b323-b47a75b13ce1",
  "project_reference": {
   "kind": "project",
   "name": "testProject",
   "uuid": "b0a4e17e-fdf3-4e99-b323-b47a75b13ce1"
  },
  "spec_version": 1,
  "creation_time": "2024-10-23T01:57:31Z",
  "owner_reference": {
   "kind": "user",
   "uuid": "00000000-0000-0000-0000-000000000000",
   "name": "admin"
  },
  "categories": {},
  "categories_mapping": {}
 },
 "spec": {
  "name": "testProject",
  "resources": {
   "resource_domain": {
    "resources": []
   },
   "account_reference_list": [],
   "environment_reference_list": [],
   "user_reference_list": [],
   "identity_providers_reference_list": [],
   "directory_reference_list": [],
   "tunnel_reference_list": [],
   "external_user_group_reference_list": [],
   "subnet_reference_list": [],
   "cluster_reference_list": [],
   "vpc_reference_list": [],
   "external_network_list": [],
   "enable_directory_and_identity_provider_shortlist": false
  },
  "description": "Test Project"
 },
 "status": {
  "name": "testProject",
  "resources": {
   "account_reference_list": [],
   "identity_providers_reference_list": [],
   "user_reference_list": [],
   "directory_reference_list": [],
   "is_default": false,
   "tunnel_reference_list": [],
   "external_user_group_reference_list": [],
   "cluster_reference_list": [],
   "resource_domain": {
    "resources": []
   },
   "environment_reference_list": [],
   "vpc_reference_list": [],
   "subnet_reference_list": [],
   "external_network_list": [],
   "enable_directory_and_identity_provider_shortlist": false
  },
  "description": "Test Project",
  "state": "ERROR",
  "message_list": [
   {
    "message": "'NoneType' object is not iterable",
    "reason": "INTERNAL_ERROR"
   }
  ],
  "execution_context": {
   "task_uuid": [
    "9332a622-7c14-46ba-8ec6-eb4e6db92bd5"
   ]
  }
 }
}
PUT'ing the project
---[ REQUEST ]---------------------------------------
PUT /api/nutanix/v3/projects/e2d57a2d-0a6e-486d-9409-1fa46557ffe9 HTTP/1.1
{
 "spec": {
  "name": "testProject",
  "resources": {
   "resource_domain": {},
   "default_subnet_reference": {
    "kind": "subnet",
    "uuid": "1d04b3d7-2733-401a-9709-ee85616969c4"
   }
  },
  "description": "Test project"
 },
 "api_version": "3.1",
 "metadata": {
  "last_update_time": "2024-10-25T08:17:17Z",
  "kind": "project",
  "uuid": "e2d57a2d-0a6e-486d-9409-1fa46557ffe9",
  "project_reference": {
   "kind": "project",
   "name": "testProject",
   "uuid": "e2d57a2d-0a6e-486d-9409-1fa46557ffe9"
  },
  "creation_time": "2024-10-25T07:45:41Z",
  "spec_version": 4,
  "owner_reference": {
   "kind": "user",
   "name": "admin",
   "uuid": "00000000-0000-0000-0000-000000000000"
  },
  "categories": {
   "Tenant": "testProject"
  }
 }
}

---[ RESPONSE ]--------------------------------------
HTTP/1.1 202 ACCEPTED

{
 "metadata": {
  "last_update_time": "2024-10-25T08:17:17Z",
  "use_categories_mapping": false,
  "kind": "project",
  "uuid": "e2d57a2d-0a6e-486d-9409-1fa46557ffe9",
  "project_reference": {
   "kind": "project",
   "name": "testProject",
   "uuid": "e2d57a2d-0a6e-486d-9409-1fa46557ffe9"
  },
  "spec_version": 5,
  "creation_time": "2024-10-25T07:45:41Z",
  "categories": {
   "Tenant": "testProject"
  },
  "owner_reference": {
   "kind": "user",
   "name": "admin",
   "uuid": "00000000-0000-0000-0000-000000000000"
  }
 },
 "api_version": "3.1",
 "spec": {
  "name": "testProject",
  "resources": {
   "resource_domain": {},
   "default_subnet_reference": {
    "kind": "subnet",
    "uuid": "1d04b3d7-2733-401a-9709-ee85616969c4"
   },
   "enable_directory_and_identity_provider_shortlist": false
  },
  "description": "Test project"
 },
 "status": {
  "state": "PENDING",
  "execution_context": {
   "task_uuid": "f5f9a682-e404-4459-b381-b058d44a469c"
  }
 }
}

Panic Output

n/a

Expected Behavior

First run should create the project Second run should succeed with no changes

Actual Behavior

First run creates the project successfully. Second run wants to make changes to the project (below) and then generates an error:

  # nutanix_project.projects["testProject"] will be updated in-place
  ~ resource "nutanix_project" "projects" {
        id                = "3dae1888-5b03-483d-be06-37281b6a40cb"
        name              = "testProject"
        # (8 unchanged attributes hidden)

      ~ default_subnet_reference {
          + kind = "subnet"
          + name = null
          + uuid = "1d04b3d7-2733-401a-9709-ee85616969c4"
        }

        # (1 unchanged block hidden)

│ Error: error waiting for project(3dae1888-5b03-483d-be06-37281b6a40cb) to update: error_detail: , progress_message: update_project
│ 
│   with nutanix_project.projects["testProject"],
│   on main.tf line 15, in resource "nutanix_project" "projects":
│   15: resource "nutanix_project" "projects" {

Steps to Reproduce

  1. terraform apply
  2. terraform apply

Important Factors