cdktf / cdktf-tf-module-stack

A drop-in replacement for cdktf.TerraformStack that lets you define Terraform modules as constructs
Mozilla Public License 2.0
20 stars 2 forks source link

cdktf conditional statements and Aliased Provider requirement not synthesized correctly #272

Open ankitatdnv opened 11 months ago

ankitatdnv commented 11 months ago

Description

I have created a cdktf construct where ResourceGroup resource is created with name having conditional statement as follows:

let resGrp = new resourceGroup.ResourceGroup(this, "resGrp", {
                location: input.location,
                name: input.existingRgName == ""? `${input.namePrefix}-${input.appName}-${input.environmentName}-rg` : input.existingRgName,
                tags: input.tags,
                provider: input.provider
            });

But after synthesizing it removes conditional statement and generates following output:

{
    "azurerm_resource_group": {
      "static-app_resGrp_E3D22600": {
        "//": {
          "metadata": {
            "path": "az-static-app/static-app/resGrp",
            "uniqueId": "static-app_resGrp_E3D22600"
          }
        },
        "location": "${var.location}",
        "name": "${var.existingRgName}",
        "provider": "azurerm",
        "tags": "${var.tags}"
      }
    }

Also I have passed an Alias azurerm provider requirement, but after synthesis, it's not taking the alias name, instead just taking the name of the provider.

let azurermProvider = new ProviderRequirement(this, "azurerm", "~> 3.70.0", "hashicorp/azurerm");
let providerAlias = new TFModuleVariable(this, "providerAlias", {
      type: "string",
      default: ""    
    });
azurermProvider.alias = providerAlias.value;

Synthesized output:

"azurerm_resource_group": {
      "static-app_resGrp_E3D22600": {
        "//": {
          "metadata": {
            "path": "az-static-app/static-app/resGrp",
            "uniqueId": "static-app_resGrp_E3D22600"
          }
        },
        "location": "${var.location}",
        "name": "${var.existingRgName}",
        "provider": "azurerm",
        "tags": "${var.tags}"
      }
    }

Versions

language: null cdktf-cli: 0.18.0 node: v18.17.1 terraform: 1.5.2 arch: x64 os: win32 10.0.19045

Providers

No response

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

Community Note