Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

kennedy
Copy link

@kennedy kennedy commented Feb 24, 2022

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?

  • I have tested and validated these changes using one or more of the provided examples/* projects

In terraform, I declared a ec2 module with my revisions and used the outputs for aws_volume_attachment and aws_ebs_volume arguements:

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.

`aws_ebs_volume.this` to use `module.ec2.availability_zone` in `availability_zone` argument
@kennedy kennedy changed the title Adding availability_zone to the outputs of the module feat: Adding availability_zone to the outputs of the module Feb 24, 2022
@github-actions
Copy link

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 github-actions bot added the stale label Mar 27, 2022
@github-actions
Copy link

github-actions bot commented Apr 7, 2022

This PR was automatically closed because of stale in 10 days

@github-actions github-actions bot closed this Apr 7, 2022
@github-actions
Copy link

github-actions bot commented Nov 8, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add availability_zone output
1 participant