无法跨地域更新安全组规则

Unable to update security group rule across regions

Terraform 版本:v0.11.8

我正在尝试在部署当前安全组(俄亥俄州)后更新另一个区域(爱尔兰)的安全组规则。

下面是我的代码片段:

variable "aws_account_id" {}

terraform {
  backend "s3" {}
}

provider "aws" {
  region              = "us-east-2"
  allowed_account_ids = ["${var.aws_account_id}"]
}

provider "aws" {
  alias               = "TestApp"
  region              = "eu-west-1"
}


data "aws_security_group" "test_sg" {
  provider        = "aws.TestApp"
  name = "test-sg"
}

resource "aws_security_group" "test1_sg" {
  name        = "Test 1"
  vpc_id      = "VPC ID"
}

resource "aws_security_group_rule" "allow_test1_access_test_sg" {
  provider        = "aws.TestApp"

  type            = "ingress"
  from_port       = "80"
  to_port         = "80"
  protocol        = "tcp"
  security_group_id = "${data.aws_security_group.test_sg.id}"

  source_security_group_id = "${aws_security_group.test1_sg.id}"
}

我得到如下循环依赖。

案例 1:运行 上面的代码,得到 test1_sg 安全组不存在的错误。

案例 2:运行 上面的代码在 aws_security_group_rule 中没有 provider = "aws.TestApp",得到的错误是 test_sg 安全组没有存在。

案例 3: 运行 以上代码在 data "aws_security_group" "test_sg" 中没有 provider = "aws.TestApp" ,得到 test_sg 安全组没有的错误存在。

我不确定这是不是 100% 的区域间通信问题,但似乎是这样。

注意:上述错误是在 运行 terraform 应用时出现的。计划显示正确的更改,没有任何错误。

任何帮助将不胜感激。

谢谢!

就你的情况 1 而言,你的源安全组应该是 "test1_sg"。没有名为 "test1_access_test2" 的安全组。使用这个。

source_security_group_id = "${aws_security_group.test1_sg.id}"

否则,去你的控制台看看这个安全组是否存在。

好的,所以我终于找到了答案。

根据亚马逊文档...

You cannot reference the security group of a peer VPC that's in a different region. Instead, use the CIDR block of the peer VPC.

AWS 文档:更新您的安全组以引用对等 VPC 组

我需要在跨区域引用时使用cidr块而不是安全组。