Help us understand the problem. What is going on with this article?

TerraformをアップグレードしたらVPC周りで怒られた件

More than 1 year has passed since last update.

Terraformのバージョンをv0.10.7からv0.11.2にアップグレードしたら、planで以下のようなエラーが発生しました。

% terraform plan
 ------------------------------------------------------------------------

Warning: output "database_subnet_group": must use splat syntax to access aws_db_subnet_group.database attribute "id", because it has "count" set; use aws_db_subnet_group.database.*.id to obtain a list of the attributes across all instances



Warning: output "elasticache_subnet_group": must use splat syntax to access aws_elasticache_subnet_group.elasticache attribute "id", because it has "count" set; use aws_elasticache_subnet_group.elasticache.*.id to obtain a list of the attributes across all instances



Warning: output "igw_id": must use splat syntax to access aws_internet_gateway.mod attribute "id", because it has "count" set; use aws_internet_gateway.mod.*.id to obtain a list of the attributes across all instances



Warning: output "vpc_endpoint_s3_id": must use splat syntax to access aws_vpc_endpoint.s3 attribute "id", because it has "count" set; use aws_vpc_endpoint.s3.*.id to obtain a list of the attributes across all instances



Warning: output "vpc_endpoint_dynamodb_id": must use splat syntax to access aws_vpc_endpoint.dynamodb attribute "id", because it has "count" set; use aws_vpc_endpoint.dynamodb.*.id to obtain a list of the attributes across all instances



Error: Error running plan: 4 error(s) occurred:

* module.vpc.output.vpc_endpoint_dynamodb_id: Resource 'aws_vpc_endpoint.dynamodb' not found for variable 'aws_vpc_endpoint.dynamodb.id'
* module.vpc.output.vpc_endpoint_s3_id: Resource 'aws_vpc_endpoint.s3' not found for variable 'aws_vpc_endpoint.s3.id'
* module.vpc.output.elasticache_subnet_group: Resource 'aws_elasticache_subnet_group.elasticache' not found for variable 'aws_elasticache_subnet_group.elasticache.id'
* module.vpc.output.database_subnet_group: Resource 'aws_db_subnet_group.database' not found for variable 'aws_db_subnet_group.database.id'

でも今回エラーとなった構文は、 .tfstate の中にのみ存在する記述だったりして、しばらく悩んでしまいました(dynamodbとか使ってないしw。

原因はどうやら利用していたVPCのモジュールが [DEPRECATED] になった事でした。

利用していたvpcモジュール : terraform-community-modules/tf_aws_vpc

[DEPRECATED] Use https://github.com/terraform-aws-modules/terraform-aws-vpc

なのでvpcモジュール利用箇所を

 module "vpc" {
-  source = "github.com/terraform-community-modules/tf_aws_vpc"
+  source = "terraform-aws-modules/vpc/aws"

   name = "vega_vpc_${var.env}"

のように修正し terraform plan し直したら上述のWarningとErrorが全部消えました。

めでたしめでたし。

ただ、VPC系モジュールに関わるモノがほぼ全て ~ update in-place または -/+ destroy and then create replacement になってしまったのでapplyする際は注意が必要です。

私の場合、たまたまv0.10からv0.11にアップグレードしたタイミングで発覚しただけですが同様のエラーでお困りの人向けにまとめてみました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした