CiscoDevNet / terraform-provider-aci

Terraform Cisco ACI provider
https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs
Mozilla Public License 2.0
87 stars 100 forks source link

Commenting out optional parameter is not properly reflected in TF plan (DCNE-126) #202

Open FrederikSuijs opened 3 years ago

FrederikSuijs commented 3 years ago

Community Note

Terraform Version

terraform -v Terraform v0.14.5 provider registry.terraform.io/ciscodevnet/aci v0.5.4

APIC version and APIC Platform

Affected Resource(s)

I have only tested with these two resources, but I am expecting all aci resources are affected by this behavior. I am trying to write some of my own aci resources and observe similar behavior.

Terraform Configuration Files

terraform {
  required_providers {
    aci = {
      source  = "CiscoDevNet/aci"
      version = "0.5.4"
    }
  }
}

provider "aci" {
 username = "admin"
 password = "ciscopsdt"
 url      = "https://sandboxapicdc.cisco.com"
 insecure = true
}

Debug Output

https://gist.github.com/FrederikSuijs/ff3f31f4ea27151b70dae69135b0f11f

Panic Output

Expected Behavior

After commenting out the description field during step 3, the plan should fall back to the default behavior. In this case the description field should be updated to an empty string, to be consistent to the state after step 1.

Actual Behavior

Nothing happens. The Terraform plan/apply seems to calculate a change is not required.

Steps to Reproduce

  1. Create resources
    
    resource "aci_tenant" "debug_tenant" {
    //description = "created from terraform"
    name = "debug_tenant"
    }

resource "aci_vrf" "debug_vrf" { //description = "created from terraform" name = "debug_vrf" tenant_dn = aci_tenant.debug_tenant.id }

`terraform apply`

2. Uncomment description
```hcl
resource "aci_tenant" "debug_tenant" {
    description = "created from terraform"
    name = "debug_tenant"
}

resource "aci_vrf" "debug_vrf" {
    description = "created from terraform"
    name = "debug_vrf"
    tenant_dn = aci_tenant.debug_tenant.id
}

terraform apply

  1. Recomment description
    
    resource "aci_tenant" "debug_tenant" {
    //description = "created from terraform"
    name = "debug_tenant"
    }

resource "aci_vrf" "debug_vrf" { //description = "created from terraform" name = "debug_vrf" tenant_dn = aci_tenant.debug_tenant.id }


`terraform apply`

### Important Factoids

<!--- Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? --->
Not applicable

### References

<!---
Information about referencing Github Issues: https://help.github.com/articles/basic-writing-and-formatting-syntax/#referencing-issues-and-pull-requests

Are there any other GitHub issues (open or closed) or pull requests that should be linked here? Vendor documentation? For example:
--->

* #0000
lhercot commented 3 years ago

This is the normal behavior. As a generic guideline, we do not define any default values for fields in the provider or the SDK. If you want to reset any field to its default value, you have to modify it yourself. This is to avoid re-writing fields that the provider might not be managing yet.

andbyrne commented 2 years ago

This also impacts object relationships. For example in an "aci_leaf_access_bundle_policy_group" resource you can optionally specify a relationship to a policy such as "relation_infra_rs_cdp_if_pol" and it will create that relationship.

Later if you change that value to null or an empty string, the relationship is not removed as one would expect. It is only possible to change the relationship to another valid policy.

Both the GUI and REST API support the removal of relationships. The inability to do this with the ACI provider is a concern for anyone wanting to use it for the ongoing management of objects vs their initial creation.

akinross commented 6 months ago

Resources created with plugin framework resolve this issue, however the plan output will not be rendered properly.

See details of render issue here: https://github.com/hashicorp/terraform/issues/31887#issuecomment-1958832973