我一辈子都无法让它发挥作用。我需要AWS_PROFILE
设置环境变量才能让 terragrunt 正常运行。如果我运行:
export AWS_PROFILE=myprofile; terragrunt plan
这会起作用,但这不是我想要运行的内容:
terragrunt plan
并让该自动选择我应该使用的正确 aws 配置文件。这是我所拥有的:
generate "provider" {
path = "provider.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
provider "aws" {
region = "${local.region}"
profile = "${trimspace(run_cmd("bash", "${get_parent_terragrunt_dir()}/../../set_profile.sh",local.profile))}"
}
EOF
}
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite"
}
config = {
...
...
region = local.region
profile = local.profile
...
...
}
}
它总是向我抛出错误:
Error finding AWS credentials (did you set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables?): NoCredentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors
set_profile.sh
脚本如下:
#!/bin/bash
VALUE=$(echo $1 | sed $'s/\r//')
export AWS_PROFILE=$VALUE
echo "$AWS_PROFILE"
如果我回显我AWS_PROFILE
的,它仍然是空白的。所以这就像运行命令实际上并没有将导出值保存到我的控制台。
我究竟做错了什么?有没有人真的能够成功地AWS_PROFILE
用 terragrunt 动态设置他们的?