hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.85k stars 450 forks source link

Synth changing TerraformVariable map keys to snake case #2473

Open blairham opened 1 year ago

blairham commented 1 year ago

cdktf & Language Versions

language: typescript
cdktf-cli: 0.14.3
node: v16.15.1
cdktf: 0.14.3
constructs: 10.1.215
terraform: 1.1.7

Affected Resource(s)

    const tags = new TerraformVariable(this, "default_tags", {
      type: "map",
      default: {
        BusinessOwner: "Magoo",
        Environment: "sbx",
        Deployment: "Terraform",
      },
    });

Expected Behavior

When creating a map TerraformVariable, it should not modify the keys as the module expects specific case-sensitive values.

In cdktf.json ,

  "variable": {
    "default_tags": {
      "default": {
        "BusinessOwner": "Magoo",
        "Deployment": "Terraform",
        "Environment": "sbx",
      },
      "type": "map"
    }

Actual Behavior

When creating a map TerraformVariable, I the keys are changed to snake case.

  "variable": {
    "default_tags": {
      "default": {
        "business_owner": "Magoo",
        "deployment": "Terraform",
        "environment": "sbx",
      },
      "type": "map"
    }

Steps to Reproduce

jsteinich commented 1 year ago

This sort of thing was briefly mentioned in https://github.com/hashicorp/terraform-cdk/pull/2446#pullrequestreview-1227833208. Should probably just remove the keysToSnakeCase function and explicitly set in the few places where it is still needed.

marcel-tomate commented 5 months ago

Also running into this problem with my custom provider, which is using schema.MapAttribute and it will transform my keys from kebab-case to snake_case, which will break things. For now I can workaround with this:

const ipamProvider = new provider.IpamProvider(
      this,
      "ipamProvider"
      // {
      //   // will result in wrong keys:
      //   staticAssignments: data.staticAssignments,
      // }
    );

    // Hotfix https://github.com/hashicorp/terraform-cdk/pull/395#issuecomment-822786292
    ipamProvider.addOverride("static_assignments", data.staticAssignments);