LoginSignup
5
3

More than 3 years have passed since last update.

TerraformでvpcをDataSourceで取得するとき

Posted at

VPCをDataSourceで取得する

  • filterでタグ名を指定している
  • 複数のリソースが取得されないように、フィルター条件は多い方が良いかも
data "aws_vpc" "vpc" {

  filter {
    name   = "tag:Name"
    values = ["vamdemic-vpc"]
  }
}

DataSourceを利用する場合

  • リスト型で取得されるので、1つ目の要素を取り出します
data "aws_route_table" "route" {
  vpc_id = data.aws_vpc.vpc.*.id[0]

  filter {
    name   = "tag:Name"
    values = ["vamdemic-route"]
  }
}
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3