terraformalibaba-cloudterraform0.12+alibaba-cloud-ecs

Terraform / alicloud : create an ECS instance with multiple data disks


I'm trying to create multiple ecs instances using terraform. In fact I want for each ecs instance to have multiple data disks. So one disk for OS and 2 other data disks.

The code snippet should look like :

resource "alicloud_instance" "node" {
  image_id                      = data.alicloud_images.nodes.id
  instance_type                 = var.instance_type_controller
  internet_max_bandwidth_out    = 100
  security_groups               = alicloud_security_group.cluster.id

  key_name = var.key_pair
  count    = 1

  system_disk_size              = 80

  data_disks                    = [
    {
      name                  = "/dev/xvdb"
      size                  = 200
      delete_with_instance  = true
    },
    {
      name                  = "/dev/xvdc"
      size                  = 100
      delete_with_instance  = true
    }
  ]
}

Only problem is that I have an message error telling me that

An argument named "data_disks" is not expected here. Did you mean to define a
block of type "data_disks"?

I went through the documentation and I am pretty sure that data_disks is of type list(map(string)) so what I wrote should work but it only work when I set it as

data_disks {
      name                  = "/dev/xvdb"
      size                  = 200
      delete_with_instance  = true
}

But I need multiple data disks attached to my ECS instance... Am I missing something ?

I'm using the following terraform/provider versions :

Terraform v0.13.0
+ provider registry.terraform.io/hashicorp/alicloud v1.94.0
+ provider registry.terraform.io/hashicorp/random v2.3.0
+ provider registry.terraform.io/hashicorp/template v2.1.2

Solution

  • As @ydaetskcoR commented. The solution is to have multiple data_disks blocks. So something like this:

    resource "alicloud_instance" "node" {
      image_id                      = data.alicloud_images.nodes.id
      instance_type                 = var.instance_type_controller
      internet_max_bandwidth_out    = 100
      security_groups               = alicloud_security_group.cluster.id
    
      key_name = var.key_pair
      count    = 1
    
      system_disk_size              = 80
       
      data_disks {
          name                  = "/dev/xvdb"
          size                  = 200
          delete_with_instance  = true
      }
    
      data_disks {
          name                  = "/dev/xvdc"
          size                  = 100
          delete_with_instance  = true
      }
     
    }