Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement corefunc_env_copy_to_var #20

Closed
skyzyx opened this issue Sep 6, 2023 · 1 comment
Closed

Implement corefunc_env_copy_to_var #20

skyzyx opened this issue Sep 6, 2023 · 1 comment

Comments

@skyzyx
Copy link
Member

skyzyx commented Sep 6, 2023

Go: corefunc.EnvCopyToVar(envName, tfVarName)
TF: corefunc_env_copy_to_var

Real-world use-case: When integrating PagerDuty and Datadog, need to read PagerDuty API key from PAGERDUTY_TOKEN, then pass it to a variable, so that the Datadog provider can read it without printing in text (which is insecure).

If a Terraform variable is called var.pagerduty_token, then this would read PAGERDUTY_TOKEN and then write that same value to TF_VARS_pagerduty_token so that Terraform will read it as the variable value.

variable "pagerduty_token" {
  description = "PagerDuty API token. Value is set via .env file."
  type        = string
}

data "corefunc_env_copy_to_var" "pagerduty_token" {
  name     = "PAGERDUTY_TOKEN"
  variable = "pagerduty_token"
}

Yes, you could do export TF_VARS_pagerduty_token=$PAGERDUTY_TOKEN, but:

  1. You'd be surprised how few people know about this.
  2. This (and corefunc_env_ensure) help make it an explicit and unmissable part of running the Terraform.
@skyzyx
Copy link
Member Author

skyzyx commented Oct 15, 2023

Meh. The copy needs to happen before Terraform is run. Boo.

@skyzyx skyzyx closed this as completed Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant