terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

KUBE_CONFIG_PATH(S) environment variable should be able to overwrite config_path in code

Open NiklasWagner opened this issue 3 years ago • 6 comments

Description

I'm currently implementing an Terraform deployment within our CI pipeline. Our code sets the config_path to the home directory, since this is where the .kube/config usually is. The config_path or config_paths (or either environment variables) is required to use this provider.

While integrating Terraform in the CI pipeline we no longer have the .kube/config in our home directory (because of how the CI runner infrastructure is managed). I've configured the KUBE_CONFIG_PATH environment variable to point to the correct path globally, so it'll be applied to all CI jobs.

Now, I expect Terraform to use the KUBE_CONFIG_PATH variable value instead of the in code reference value, but this doesn't work. After removing the config_path from the code, the environment variable works as expected but removing the stuff from the code is a big no-no in case we want to test something manually on the dev-stage.

I tried switching to config_paths which is a list of strings as well as KUBE_CONFIG_PATHS. This time I excepted that the value of the environment variable will be appended to the existing config_paths code but this doesn't work either. Once something is configured in the code, environment variables will be ignored.

I'd like to have a solution to continue using config_path (or config_paths) within our code while being able to overwrite this by an Environment variable in the CI environment.

A few possible solutions I came up with:

  • Setting KUBE_CONFIG_PATH will overwrite the code. (Breaking Change)
  • Setting KUBE_CONFIG_PATHS will append the environments to the existing config_paths (Probably not that breaking change since it will be appended only)
  • Creating a new Environment Variable that will overwrite these (probably overkill IMO)

Currently I use this workaround in our CI pipeline but it doesn't feel great:

# deletes any lines matching the regex pattern, e.g.: config_path = "~/.kube/config"
find . -type f -exec sed -i -E '\,^\s+config_path\s+=\s+"~\/\.kube\/config"$,d' {} ';'

Potential Terraform Configuration

provider "kubernetes" {
  config_path    = "~/.kube/config"
  config_context = data.terraform_remote_state.infrastructure.outputs.eks_cluster_arn
}

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

NiklasWagner avatar Jan 17 '22 16:01 NiklasWagner

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Jan 18 '23 00:01 github-actions[bot]

Not stale.

Skaronator avatar Feb 15 '23 12:02 Skaronator

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Feb 16 '24 00:02 github-actions[bot]

No

Skaronator avatar Feb 16 '24 05:02 Skaronator