IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
342 stars 673 forks source link

ibm_cbr_rule is not creating correct contexts #4248

Open data-henrik opened 1 year ago

data-henrik commented 1 year ago

Community Note

Terraform CLI and Terraform IBM Provider Version

$ terraform -v
Terraform v1.3.4
on linux_amd64
+ provider registry.terraform.io/ibm-cloud/ibm v1.48.0

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please share a link to the ZIP file.
resource "ibm_cbr_rule" "cbr_rule_COS" {
  contexts {
    attributes {
      name = "networkZoneId"
      value = ibm_cbr_zone.cbr_zone_CE.id
    }
   attributes {
      name = "networkZoneId"
      value = ibm_cbr_zone.homezone2.id
    }

  }
...

Expected Behavior

The rule is created with the two zones as contexts. If there are problems, there should be errors or warnings

Actual Behavior

No warnings, no error messages, the rule is created, but only with a single context.

zhenwan commented 1 year ago

https://github.ibm.com/IAM/cbr-issues/issues/464

zhenwan commented 1 year ago

@data-henrik Terraform's configuration language is based on HCL language, A multiple contexts rule's context in json format is like this:

{
   "contexts":[
      {
         "attributes":[
            {
               "name":"networkZoneId",
               "value":""
            }
         ]
      },
      {
         "attributes":[
            {
               "name":"networkZoneId",
               "value":""
            }
         ]
      }
   ]
}

but this config converted into HCL should be

"contexts" = {
  "attributes" = {
    "name" = "networkZoneId"

    "value" = ""
  }
}

"contexts" = {
  "attributes" = {
    "name" = "networkZoneId"

    "value" = ""
  }
}

so the correct format for our config should be:

resource "ibm_cbr_rule" "cbr_rule_COS" {
  contexts {
    attributes {
      name = "networkZoneId"
      value = ibm_cbr_zone.cbr_zone_CE.id
    }
}

contexts {
   attributes {
      name = "networkZoneId"
      value = ibm_cbr_zone.homezone2.id
    }
}

Please give this a try, and let me know if it works for you.

data-henrik commented 1 year ago

a syntax like that works and it creates two contexts in the rule

soohoowoohoo commented 1 year ago

@data-henrik this issue should now be resolved, please reopen if there are unresolved items with this issue.