Skip to content
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

feat: Add availability_zone output #347

Merged
merged 2 commits into from
Aug 30, 2023
Merged

feat: Add availability_zone output #347

merged 2 commits into from
Aug 30, 2023

Conversation

deny-7
Copy link
Contributor

@deny-7 deny-7 commented Jul 22, 2023

Description

Added availability_zone output. The availability_zone of the created instance is useful information to use outside of the module.

Motivation and Context

When creating multiple EC2 instances in multiple AZs, in most cases, we would like to have the EBS volume in the same AZ as the created EC2. As a trick we can use data.aws_instance with loop or a map of AZs and random_suffle,
but it does not look nice. In my opinion having availability_zone output would get out of tricks and make the code cleaner and easier to read.

This PR resolves #341 and #264

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
    Deployed volume-attachment example:
terraform plan --target module.ec2 --target aws_volume_attachment.this --target aws_ebs_volume.this

  # aws_ebs_volume.this will be created
  + resource "aws_ebs_volume" "this" {
      + arn               = (known after apply)
      + availability_zone = "eu-west-1c"
      + encrypted         = (known after apply)
      + final_snapshot    = false
      + id                = (known after apply)
      + iops              = (known after apply)
      + kms_key_id        = (known after apply)
      + size              = 1
      + snapshot_id       = (known after apply)
      + tags              = {
          + "Example"    = "ex-volume-attachment"
          + "Name"       = "ex-volume-attachment"
          + "Repository" = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
        }
      + tags_all          = {
          + "Example"    = "ex-volume-attachment"
          + "Name"       = "ex-volume-attachment"
          + "Repository" = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
        }
      + throughput        = (known after apply)
      + type              = (known after apply)
    }

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

  # module.ec2.aws_instance.this[0] will be created
  + resource "aws_instance" "this" {
      + ami                                  = "ami-0c43c11b9446e99da"
      + arn                                  = (known after apply)
      + associate_public_ip_address          = true
      + availability_zone                    = "eu-west-1c"
      + cpu_core_count                       = (known after apply)
      + cpu_threads_per_core                 = (known after apply)
      + disable_api_stop                     = (known after apply)
      + disable_api_termination              = (known after apply)
      + ebs_optimized                        = (known after apply)
      + get_password_data                    = false
      + host_id                              = (known after apply)
      + host_resource_group_arn              = (known after apply)
      + iam_instance_profile                 = (known after apply)
      + id                                   = (known after apply)
      + instance_initiated_shutdown_behavior = (known after apply)
      + instance_lifecycle                   = (known after apply)
      + instance_state                       = (known after apply)
      + instance_type                        = "c5.large"
      + ipv6_address_count                   = (known after apply)
      + ipv6_addresses                       = (known after apply)
      + key_name                             = (known after apply)
      + monitoring                           = (known after apply)
      + outpost_arn                          = (known after apply)
      + password_data                        = (known after apply)
      + placement_group                      = (known after apply)
      + placement_partition_number           = (known after apply)
      + primary_network_interface_id         = (known after apply)
      + private_dns                          = (known after apply)
      + private_ip                           = (known after apply)
      + public_dns                           = (known after apply)
      + public_ip                            = (known after apply)
      + secondary_private_ips                = (known after apply)
      + security_groups                      = (known after apply)
      + source_dest_check                    = true
      + spot_instance_request_id             = (known after apply)
      + subnet_id                            = "subnet-****"
      + tags                                 = {
          + "Example"    = "ex-volume-attachment"
          + "Name"       = "ex-volume-attachment"
          + "Repository" = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
        }
      + tags_all                             = {
          + "Example"    = "ex-volume-attachment"
          + "Name"       = "ex-volume-attachment"
          + "Repository" = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
        }
      + tenancy                              = (known after apply)
      + user_data                            = (known after apply)
      + user_data_base64                     = (known after apply)
      + user_data_replace_on_change          = false
      + volume_tags                          = {
          + "Name" = "ex-volume-attachment"
        }
      + vpc_security_group_ids               = (known after apply)

      + credit_specification {}

      + enclave_options {
          + enabled = (known after apply)
        }

      + metadata_options {
          + http_endpoint               = "enabled"
          + http_put_response_hop_limit = 1
          + http_tokens                 = "optional"
          + instance_metadata_tags      = (known after apply)
        }

      + timeouts {}
    }

Plan: 3 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + ec2_arn                                = (known after apply)
  + ec2_availability_zone                  = "eu-west-1c"
  + ec2_capacity_reservation_specification = (known after apply)
  + ec2_id                                 = (known after apply)
  + ec2_instance_state                     = (known after apply)
  + ec2_primary_network_interface_id       = (known after apply)
  + ec2_private_dns                        = (known after apply)
  + ec2_public_dns                         = (known after apply)
  + ec2_public_ip                          = (known after apply)
  + ec2_tags_all                           = {
      + Example    = "ex-volume-attachment"
      + Name       = "ex-volume-attachment"
      + Repository = "https://github.com/terraform-aws-modules/terraform-aws-ec2-instance"
    }
  • I have executed pre-commit run -a on my pull request

@deny-7 deny-7 changed the title feat: add availability_zone output feat: Add availability_zone output Jul 22, 2023
@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 Aug 22, 2023
Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable, thank you!

@bryantbiggs bryantbiggs merged commit 1b2cdeb into terraform-aws-modules:master Aug 30, 2023
7 checks passed
antonbabenko pushed a commit that referenced this pull request Aug 30, 2023
## [5.4.0](v5.3.1...v5.4.0) (2023-08-30)

### Features

* Add `availability_zone` output ([#347](#347)) ([1b2cdeb](1b2cdeb))
@antonbabenko
Copy link
Member

This PR is included in version 5.4.0 🎉

@github-actions
Copy link

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 Sep 30, 2023
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
3 participants