【问题标题】:create the vpc flow log from terraform in existing environment在现有环境中从 terraform 创建 vpc 流日志
【发布时间】:2020-08-14 01:52:17
【问题描述】:

我是 terraform 的新手,还在学习。 我知道有办法可以将现有基础设施导入 terraform 并创建状态文件。但是,好像现在我有多个 AWS 账户和这些账户中的多个区域,这些账户有多个 VPC。 我的任务是通过 terraform 创建 vpc 流日志。 可能吗? 如果是,请您帮助我或指导我如何完成这件事。

【问题讨论】:

  • 如果您询问如何跨账户使用 aws 提供程序,请在 provider "aws" 块中输入 profile = var.aws_profile 并将 aws_profile 设置为您在 ~/.aws/ 中的凭证的别名证书。有关更多信息,请参阅文档terraform.io/docs/providers/aws/index.html

标签: amazon-web-services terraform amazon-vpc terraform-provider-aws


【解决方案1】:

这是可能的,尽管有点混乱。您需要为您拥有的每个帐户/区域组合创建一个提供商块(具有唯一别名)(您可以使用配置文件,但我认为角色是最好的),并在您的资源中适当地选择这些提供商。

provider "aws" {
  alias  = "acct1uswest2"
  region = "us-west-2"
  assume_role {
    role_arn     = "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"
  }
}

provider "aws" {
  alias  = "acct2useast1"
  region = "us-east-1"
  assume_role {
    role_arn     = "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"
  }
}

resource "aws_flow_log" "flow1" {
  provider = aws.acct1uswest2
  vpc_id = "vpc id in account 1" # you mentioned the vpc already exists, so you can either import the vpc and reference it's .id attribute here, or just put the id here as a string
...
}

resource "aws_flow_log" "flow2" {
  provider = aws.acct2useast1
  vpc_id = "vpc id in account 2"
...
}

建议您阅读有关导入资源(及其影响)here
更多关于多个提供商here

【讨论】:

  • 如果我错了,请纠正我,我需要为每个账户中每个区域的每个 VPC 执行此操作。
猜你喜欢
  • 2019-04-10
  • 2020-09-08
  • 1970-01-01
  • 2023-01-17
  • 2019-12-06
  • 2021-11-09
  • 2021-12-14
  • 2018-11-12
  • 2018-02-28
相关资源
最近更新 更多