terraform-aws-modules / terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws
Apache License 2.0
758 stars 1.88k forks source link

feat: Adding `availability_zone` to the outputs of the module #265

Closed kennedy closed 2 years ago

kennedy commented 2 years ago

Description

The availability_zone of the instance is very useful information to use outside of the module. This PR provides that information.

Motivation and Context

When creating an external or auxiliary aws_ebs_volume for the EC2 instance, it requires an availability zone argument. Often times, we would like to have the EBS volume in the same AZ as the EC2. Having that information would make that design much easier.

Resolves #264

Breaking Changes

None

How Has This Been Tested?

module "kennedy" {
  source               = "github.com/kennedy/terraform-aws-ec2-instance?ref=kennedy-adding-availability-zone"
  ...
  # AMI image has one EBS volume mapping, no additional ebs block is declared

  root_block_device = [
    {
      volume_type = "gp2"
      volume_size = 100
    },
  ]
}

resource "aws_volume_attachment" "kennedy" {
  device_name = "/dev/sdh"
  volume_id   = aws_ebs_volume.kennedy.id
  instance_id = module.kennedy.id
}

resource "aws_ebs_volume" "kennedy" {
  availability_zone = module.kennedy.availability_zone
  size              = 500
}

Environment:

macOS 12.2
Terraform v0.13.7
+ provider registry.terraform.io/hashicorp/aws v3.74.3
+ provider registry.terraform.io/hashicorp/local v2.1.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
terraform plan --target aws_volume_attachment.kennedy --target aws_ebs_volume.kennedy --target module.kennedy
...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_ebs_volume.kennedy will be created
  + resource "aws_ebs_volume" "kennedy" {
      + arn               = (known after apply)
      + availability_zone = (known after apply)
      + encrypted         = (known after apply)
      + id                = (known after apply)
      + iops              = (known after apply)
      + kms_key_id        = (known after apply)
      + size              = 500
      + snapshot_id       = (known after apply)
      + tags_all          = {
            ...
        }
      + throughput        = (known after apply)
      + type              = (known after apply)
    }

  # aws_volume_attachment.kennedy will be created
  + resource "aws_volume_attachment" "kennedy" {
      + device_name = "/dev/sdh"
      + id          = (known after apply)
      + instance_id = (known after apply)
      + volume_id   = (known after apply)
    }

  # module.kennedy.aws_instance.this[0] will be created
  + resource "aws_instance" "this" {
      + ami                                  = "ami-redacted"
      # AMI image has one pre-exisiting EBS volume mapping

...
      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + tags                  = (known after apply)
          + throughput            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

...

      + root_block_device {
          + delete_on_termination = true
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + throughput            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = 100
          + volume_type           = "gp2"
        }

      + timeouts {}
    }

Plan: 3 to add, 0 to change, 0 to destroy.
github-actions[bot] commented 2 years ago

This PR has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 10 days

github-actions[bot] commented 2 years ago

This PR was automatically closed because of stale in 10 days

github-actions[bot] commented 2 years ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.