infobloxopen / terraform-provider-infoblox

Infoblox NIOS Terraform Provider
https://github.com/infobloxopen/terraform-provider-infoblox
Mozilla Public License 2.0
73 stars 81 forks source link

Error: changing the value of 'dns_view' field is not allowed (v2.1.5) #239

Closed simtcrom closed 2 years ago

simtcrom commented 2 years ago

Hello,

I am using v2.1.5 to import a cname record as below,

terraform import infoblox_cname_record.test record:cname/XXXXXXXXXXXXXXXXXXXXXXXXXXXX:helloworldspringbootssl1-dit1.xxx.com/default

{
  "version": 4,
  "terraform_version": "0.15.5",
  "serial": 1,
  "lineage": "xxxxxx-xxx-xx-28cc-xxx",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "infoblox_cname_record",
      "name": "test",
      "provider": "provider[\"fid.com/edu/infoblox\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "alias": null,
            "canonical": null,
            "comment": null,
            "dns_view": null,
            "ext_attrs": null,
            "id": "record:cname/xxxxxxxxxxxxxxxxxxxE:helloworldspringbootssl2-dit1.xxx.com/default",
            "ttl": null
          },
          "sensitive_attributes": [],
          "private": "xxxxxx=="
        }
      ]
    }
  ]
}

And as you see dns_view came as null.

Now when I try to update that record I get error,

Error: changing the value of 'dns_view' field is not allowed

I think this is due to https://github.com/infobloxopen/terraform-provider-infoblox/blob/57c847c46a769c6df9261288817535e94606e5fd/infoblox/resource_infoblox_cname_record.go#L132-L134

If I remove above lines and my issue is resolved. Is that an ok thing to do?

skudriavtsev commented 2 years ago

No, this is not fine. There is a PR pending approval, with some fixes. Besides, changing 'dns_view' field with this lines being removed, actually, changes only your configuration of the resource. The TF state and the object at NIOS side stays unchanged.

simtcrom commented 2 years ago

Any way while importing I can get the dns_view as well come in to state (right now its null)?

If removing that if condition is a problem, then only way I see is,

import destroy apply

skudriavtsev commented 2 years ago

"DNS view" property of CNAME-record is immutable on NIOS side. The Terraform Infoblox provider plugin uses WAPI to communicate with NIOS-server.

simtcrom commented 2 years ago

I am still trying to understand what is the solution for my problem. How can I update imported resource infoblox_cname_record? I keep getting error "Error: changing the value of 'dns_view' field is not allowed" when I try to apply below on the imported resource.

resource "infoblox_cname_record" "infoblox_cname_record" {
    alias = "<IMPORTED CNAME>"
    canonical = "helloworldspringbootssl-xxx.xxxxx.xxx.com"
    ttl = "60"
    comment = "test"
}
simtcrom commented 2 years ago

I tried adding below to resource_infoblox_cname_record.go and now when I import "dns_view": "default" and now I can manage the resource without issues.

func resourceCNAMERecordGet(d *schema.ResourceData, m interface{}) error {
    extAttrJSON := d.Get("ext_attrs").(string)
        d.Set("dns_view", "default")
skudriavtsev commented 2 years ago

During 'import' operation you should specify all the fields, including those which have some default value. Besides, please try the latest code, that was merged couple of days ago.

simtcrom commented 2 years ago

During 'import' operation you should specify all the fields, including those which have some default value. Besides, please try the latest code, that was merged couple of days ago.

Could you please show me how it is done on below command?

terraform import infoblox_cname_record.test record:cname/XXXXXXXXXXXXXXXXXXXXXXXXXXXX:helloworldspringbootssl1-dit1.xxx.com/default