閱讀此https://developer.hashicorp.com/terraform/language/values/variables#assigning-values-to-root-module-variables后,我確信有 3 種方法可以設定變數值。
最近我在我們的一個專案中遇到了在匯入模塊時傳遞變數的代碼。
module "robot_shell" {
source = "./modules/xx_shell"
xx_resource_name_prefix = local.resource_name_prefix
cloudwatch_log_group_retention_days = 30
s3_expiration_days = 30
}
模塊中的檔案./modules/xx_shell
resource "aws_s3_bucket_lifecycle_configuration" "dest" {
bucket = aws_s3_bucket.dest.bucket
rule {
id = "expire"
status = "Enabled"
expiration {
days = var.s3_expiration_days
}
}
}
變數定義變數.tf
variable "s3_expiration_days" {
type = number
description = "S3 bucket objects expiration days https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration#days"
}
為什么 terraform 檔案不談論它?還是這是一種不再使用的舊方法?
uj5u.com熱心網友回復:
如您所述,這是將變數傳遞給模塊的一種正常方式。這在 TF 檔案中有所描述:
- 添加模塊配置
您在問題中提供的鏈接是關于在運行時將變數傳遞給根/父模塊plan/apply。但是當您想將變數傳遞給使用module塊定義的子模塊時,您可以通過module引數傳遞它們。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/521728.html
標籤:亚马逊网络服务亚马逊-s3地形terraform-provider-aws
