简体   繁体   中英

Terraform CDKTF Typescript How to set environment variables?

I have the following code:

class MyStack extends TerraformStack {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const awsSecrectKey = new TerraformVariable(this, "aws", {
      type: "string",
      sensitive: true,
    });

    new AwsProvider(this, "AWS", {
      secretKey: awsSecrectKey.value
    });
  }
}

I want to read the variable aws from any configuration file. I tried the following:

  1. export aws="test"
  2. export aws="TF_VAR_aws"
  3. Created .terraformrc file in ~ with values
  4. Used dotenv to add TF_VAR_aws to process.env

How can I add env variables to my configuration?

You would need to check what the logical id of the variable is, it should be aws, but if you dont have the EXCLUDE_STACK_ID_FROM_LOGICAL_IDS flag in your cdktf.json it might be suffixed. Then setting the value to this id should be sufficient. You can check for this id by inspecting the generated JSON after cdktf synth ran

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM