简体   繁体   English

您可以将 AWS 参数存储数据源的值分配给 Terraform 中的变量吗?

[英]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.

相关问题 有没有办法将 CORS 规则添加到 Terraform aws_s3_bucket 数据源? - Is there a way to add CORS rule to Terraform aws_s3_bucket data source? 无法将 AWS API 网关使用计划引用为 Terraform 中的数据源 - Unable to reference an AWS API Gateway Usage Plan as a data source in Terraform 需要在 terraform 中包含值或者使用多个循环来存储变量 - need to include value in terraform or use multiple loops to store variable Azure 数据工厂管道 - 将单值源查询 output 存储为变量,然后在复制数据活动中使用 - Azure Data Factory Pipeline - Store single-value source query output as a variable to then use in Copy Data activity 寻找示例代码以从 aws 参数存储中读取参数值 - looking for a sample code to read parameter value from aws parameter store Terraform 无法评估使用资源组数据源的模块 - Terraform modules that use a resource group data source can't be evaluated 无法获取 Terraform 模块中定义的变量值 - Not able to fetch the variable's value defined in a module in Terraform 在 aws amplify react js 应用程序中访问 SSM 参数存储值 - Access SSM Parameter store value in an aws amplify react js application 轮询 AWS 参数存储 - Polling AWS parameter store 从 AWS Systems Manager Parameter Store 获取最新的参数值及其之前版本的参数值 - Getting the latest parameter value from the AWS Systems Manager Parameter Store and the parameter value of the version preceding it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM