无法理解如何从参数 store 获取 value 并将其传递给 terraform 变量。我有一个名为“github_token”和“string”类型的参数。 terraform 代码中有一个变量
variable "github_oauth_token" {
default=""
}
我试图用下一个代码块接收 value 参数,但它不正确。
data "aws_ssm_parameter" "github_token" {
name = "github_token"
type = "string"
value = var.github_oauth_token
}
回答1
当使用 data
源时,您不是在创建新的 value,您只是在读取现有的 value。因此,指定“value”和“type”在这种情况下没有意义,因为 value 和参数的类型已经存在。如果您查看https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter,您会发现唯一需要的是 name
value。
假如说:
- 运行 Terraform 的用户有权访问 SSM(参数 store)
- 在路径
github_token
的参数 store 中存储了一个 value - value 未加密
这应该适合你:
variable "github_oauth_token" {
default = "github_token"
}
data "aws_ssm_parameter" "github_token" {
name = var.github_oauth_token
}
然后使用参数store项的value:
data.aws_ssm_parameter.github_token.value