1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[AWS] Terraform AWS Provider 3.0.0以降のACM書式変更について

Posted at

概要

Terraform でACM(AWS Certificate Manager) を使用しSSL証明書を作成する際に、AWS Providerのversionによって書き方が異なっていたため変更点をまとめます。

環境

  • Mac
$ terraform version
Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.17.0

Version3.0.0以前

無料証明書の検証用レコードは以下の様に[0]としてリスト形式で記載する必要があります。

resource "aws_route53_record" "example_certificate" {
  name = aws_acm_certificate.example.domain_validation_options[0].resource_record_name
  type = aws_acm_certificate.example.domain_validation_options[0].resource_record_type
  records = [aws_acm_certificate.example.domain_validation_options[0].resource_record_value]
}

3.0.0以降、上記内容でterraform planを実行すると、Error: Invalid indexとしてエラーが返却されます。

Error: Invalid index

  on route53.tf line 36, in resource "aws_route53_record" "example_certificate":
  36:   type = aws_acm_certificate.example.domain_validation_options[0].resource_record_type

This value does not have any indices.

Version 3.0.0以降

公式ドキュメントに記載がある通り、for eachを使用し値を展開する必要があります。

resource "aws_route53_record" "example_certificate" {
  for_each = {
    for dvo in aws_acm_certificate.example.domain_validation_options : dvo.domain_name => {
      name   = dvo.resource_record_name
      record = dvo.resource_record_value
      type   = dvo.resource_record_type
    }
  }
  allow_overwrite = true
  name = each.value.name
  records = [each.value.record]
  type = each.value.type
  zone_id = data.aws_route53_zone.example.zone_id
  ttl = 60
}

まとめ

少し古めの書籍は基本的に3.0.0より前のversionが多いため、注意が必要です。
困ったら公式ドキュメントを読むことをおすすめします。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?