我正在GitHub工作流中自动化我的Terraform脚本
在我的terraform脚本中,我有一个敏感的输出变量,如下所示:
output "db_password" {
value = aws_db_instance.db.password
description = "The password for logging in to the database."
sensitive = true
}
我正在GitHub动作工作流中部署(地形应用)脚本。成功部署后,我需要将密码存储在安全的存储区(Azure KeyVault)中。我有一个bash命令可以做到这一点。
我需要在环境变量中具有db_password的值。
如何将敏感输出变量的值分配给环境变量?
有更好的方法吗?
我建议在terraform output
之后使用terraform apply
。然后,您可以将输出存储到Bash / shell变量或文件中,而无需打印输出。
例如
terraform apply # as before
MY_SECRET=$(terraform output db_password)
azureInterface keyvault store $MYSECRET # a totally made-up line, no clue about Azure
缺点是它可能:
ps
命令行参数中可见因此,修改后的解决方案是将其存储在临时文件中
CREDENTIALS=$(mktemp -t tmp.XXXXXXXXXX)
terraform output db_password >$CREDENTIALS
# and now use the $CREDENTIALS file as input to Azure
rm -rf $CREDENTIALS
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句