如何解决Terraform-从提供程序获取区域并在资源名称中使用它
provider "aws" {
alias = "sin"
region = "ap-southeast-1"
}
provider "aws" {
alias = "mum"
region = "ap-south-1"
}
resource "aws_sns_topic" "alarms_sin" {
provider = aws.sin
name = "${local.name_prefix}-alarms-${GET_CURRENT_REGION}"
}
resource "aws_sns_topic" "alarms_mum" {
provider = aws.mum
name = "${local.name_prefix}-alarms-${GET_CURRENT_REGION}"
}
通常,您可以使用data "aws_region" "current" {}
之类的数据块,但在这种情况下不起作用。
解决方法
我能够通过在数据块中添加提供程序来解决它-
provider "aws" {
alias = "sin"
region = "ap-southeast-1"
}
provider "aws" {
alias = "mum"
region = "ap-south-1"
}
// Change
data "aws_region" "sin" {
provider = "aws.sin"
}
data "aws_region" "mum" {
provider = "aws.mum"
}
resource "aws_sns_topic" "alarms_sin" {
provider = aws.sin
name = "${local.name_prefix}-alarms-${data.aws_region.sin.name}"
}
resource "aws_sns_topic" "alarms_mum" {
provider = aws.mum
name = "${local.name_prefix}-alarms-${data.aws_region.mum.name}"
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。