[英]Can you assign AWS parameter store data source's value to a variable in Terraform?
I am trying to read a value from AWS Parameter Store and assign its value to a variable.我正在尝试从 AWS Parameter Store 读取一个值并将其值分配给一个变量。
# data source
data "aws_ssm_parameter" "environment" {
name = "environment"
}
# variable
variable "environment" {
type = string
description = "AWS Environment Name"
default = data.aws_ssm_parameter.environment.value
}
Is this possible?这可能吗?
I know you can use data.aws_ssm_parameter.environment.value
wherever I need to use a variable but is it possible to simplify it by assigning it to a variable.我知道您可以在我需要使用变量的任何地方使用data.aws_ssm_parameter.environment.value
但是否可以通过将其分配给变量来简化它。
That is not possible.这是不可能的。 However, you can use local variables [1] for that.但是,您可以为此使用局部变量 [1]。 For example:例如:
locals {
environment = data.aws_ssm_parameter.environment.value
}
You would then reference that value elsewhere in the code with local.environment
.然后,您可以使用local.environment
在代码的其他地方引用该值。
[1] https://developer.hashicorp.com/terraform/language/values/locals [1] https://developer.hashicorp.com/terraform/language/values/locals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.