Skip to content

adding aws_ebs_volume to instance #2

@TinajaLabs

Description

@TinajaLabs

Two of my instance require an ebs volume and I'm trying to get it set up.

I tried using a block in the calling module, but it complains that should be type list, got map (see commented section below).

Is it best practice to create an aws_ebs_volume and then reference it in the calling module?

Thanks for any tips,
Chris.

# create the required volume
resource "aws_ebs_volume" "example1" {
    availability_zone = "us-west-2a"
    size = 40
    tags {
        Name = "HelloWorld"
    }
}

module "ec2_myinstance" {
  source = "terraform-aws-modules/ec2-instance/aws"

  name  = "my-instance"
  count = 5
  
  ami                    = "ami-ebd02392"
  instance_type          = "t2.micro"
  key_name               = "user1"
  monitoring             = true
  vpc_security_group_ids = ["sg-12345678"]

  # <==== set the ebs_block_device
  ebs_block_device = "${aws_ebs_volume.example1.id}"

  # tried this, did not work:
  # ebs_block_device = {
  #   volume_size = 40
  #   volume_type = "gp2"
  #   # delete_on_termination = false
  # }

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions