サーバ構築

root_block_deviceの書き方が変わってた

投稿日:

terraform v0.12 で色々試してたら、root_block_device でエラーでたので、記録残しておく。
  • v0.11で動いてたコード
resource "aws_instance" "sample" {
  ami = "ami-0c3fd0f5d33134a76"
  instance_type = "t3.micro"
  subnet_id = "subnet-xxxxxxx"

  root_block_device = {
    volume_type = "gp2"
    volume_size = 8
  }
}
下記のエラーで terraform plan 失敗する
Error: Unsupported argument

  on hoge.tf line 5, in resource "aws_instance" "sample":
   5:   root_block_device = {

An argument named "root_block_device" is not expected here. Did you mean to
define a block of type "root_block_device"?
  • root_block_deviceの = をなくすとエラー出なくなった(v0.11でもplanのエラーはでない)
resource "aws_instance" "sample" {
  ami = "ami-0c3fd0f5d33134a76"
  instance_type = "t3.micro"
  subnet_id = "subnet-xxxxxxx"

  root_block_device {
    volume_type = "gp2"
    volume_size = 8
  }
}
逆に remote_state= ないとエラーでる。
謎??
data "terraform_remote_state" "vpc" {
  backend = "s3"
  config {
    bucket = "bucket-name"
    key    = "hogehoge"
    region = "ap-northeast-1"
  }
}

-サーバ構築
-

Copyright© 明日から頑張ります。 , 2025 All Rights Reserved Powered by STINGER.