diff --git a/README.md b/README.md
index c66eef7a..c93c2634 100644
--- a/README.md
+++ b/README.md
@@ -265,6 +265,7 @@ No modules.
|------|-------------|
| [ami](#output\_ami) | AMI ID that was used to create the instance |
| [arn](#output\_arn) | The ARN of the instance |
+| [availability\_zone](#output\_availability\_zone) | The availability zone of the created instance |
| [capacity\_reservation\_specification](#output\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| [ebs\_block\_device](#output\_ebs\_block\_device) | EBS block device information |
| [ephemeral\_block\_device](#output\_ephemeral\_block\_device) | Ephemeral block device information |
diff --git a/examples/complete/README.md b/examples/complete/README.md
index 9fa60b35..5c0f17c7 100644
--- a/examples/complete/README.md
+++ b/examples/complete/README.md
@@ -69,6 +69,7 @@ No inputs.
| Name | Description |
|------|-------------|
| [ec2\_complete\_arn](#output\_ec2\_complete\_arn) | The ARN of the instance |
+| [ec2\_complete\_availability\_zone](#output\_ec2\_complete\_availability\_zone) | The availability zone of the created instance |
| [ec2\_complete\_capacity\_reservation\_specification](#output\_ec2\_complete\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| [ec2\_complete\_ebs\_block\_device](#output\_ec2\_complete\_ebs\_block\_device) | EBS block device information |
| [ec2\_complete\_ephemeral\_block\_device](#output\_ec2\_complete\_ephemeral\_block\_device) | Ephemeral block device information |
@@ -98,6 +99,7 @@ No inputs.
| [ec2\_spot\_instance\_public\_ip](#output\_ec2\_spot\_instance\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
| [ec2\_spot\_instance\_tags\_all](#output\_ec2\_spot\_instance\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
| [ec2\_t2\_unlimited\_arn](#output\_ec2\_t2\_unlimited\_arn) | The ARN of the instance |
+| [ec2\_t2\_unlimited\_availability\_zone](#output\_ec2\_t2\_unlimited\_availability\_zone) | The availability zone of the created instance |
| [ec2\_t2\_unlimited\_capacity\_reservation\_specification](#output\_ec2\_t2\_unlimited\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| [ec2\_t2\_unlimited\_id](#output\_ec2\_t2\_unlimited\_id) | The ID of the instance |
| [ec2\_t2\_unlimited\_instance\_state](#output\_ec2\_t2\_unlimited\_instance\_state) | The state of the instance. One of: `pending`, `running`, `shutting-down`, `terminated`, `stopping`, `stopped` |
@@ -107,6 +109,7 @@ No inputs.
| [ec2\_t2\_unlimited\_public\_ip](#output\_ec2\_t2\_unlimited\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
| [ec2\_t2\_unlimited\_tags\_all](#output\_ec2\_t2\_unlimited\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
| [ec2\_t3\_unlimited\_arn](#output\_ec2\_t3\_unlimited\_arn) | The ARN of the instance |
+| [ec2\_t3\_unlimited\_availability\_zone](#output\_ec2\_t3\_unlimited\_availability\_zone) | The availability zone of the created instance |
| [ec2\_t3\_unlimited\_capacity\_reservation\_specification](#output\_ec2\_t3\_unlimited\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| [ec2\_t3\_unlimited\_id](#output\_ec2\_t3\_unlimited\_id) | The ID of the instance |
| [ec2\_t3\_unlimited\_instance\_state](#output\_ec2\_t3\_unlimited\_instance\_state) | The state of the instance. One of: `pending`, `running`, `shutting-down`, `terminated`, `stopping`, `stopped` |
@@ -116,6 +119,7 @@ No inputs.
| [ec2\_t3\_unlimited\_public\_ip](#output\_ec2\_t3\_unlimited\_public\_ip) | The public IP address assigned to the instance, if applicable. NOTE: If you are using an aws\_eip with your instance, you should refer to the EIP's address directly and not use `public_ip` as this field will change after the EIP is attached |
| [ec2\_t3\_unlimited\_tags\_all](#output\_ec2\_t3\_unlimited\_tags\_all) | A map of tags assigned to the resource, including those inherited from the provider default\_tags configuration block |
| [spot\_bid\_status](#output\_spot\_bid\_status) | The current bid status of the Spot Instance Request |
+| [spot\_instance\_availability\_zone](#output\_spot\_instance\_availability\_zone) | The availability zone of the created spot instance |
| [spot\_instance\_id](#output\_spot\_instance\_id) | The Instance ID (if any) that is currently fulfilling the Spot Instance request |
| [spot\_request\_state](#output\_spot\_request\_state) | The current request state of the Spot Instance Request |
diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf
index 1ce36b82..cb32c4f3 100644
--- a/examples/complete/outputs.tf
+++ b/examples/complete/outputs.tf
@@ -89,6 +89,11 @@ output "ec2_complete_ephemeral_block_device" {
value = module.ec2_complete.ephemeral_block_device
}
+output "ec2_complete_availability_zone" {
+ description = "The availability zone of the created instance"
+ value = module.ec2_complete.availability_zone
+}
+
# EC2 T2 Unlimited
output "ec2_t2_unlimited_id" {
description = "The ID of the instance"
@@ -135,6 +140,11 @@ output "ec2_t2_unlimited_tags_all" {
value = module.ec2_t2_unlimited.tags_all
}
+output "ec2_t2_unlimited_availability_zone" {
+ description = "The availability zone of the created instance"
+ value = module.ec2_t2_unlimited.availability_zone
+}
+
# EC2 T3 Unlimited
output "ec2_t3_unlimited_id" {
description = "The ID of the instance"
@@ -181,6 +191,11 @@ output "ec2_t3_unlimited_tags_all" {
value = module.ec2_t3_unlimited.tags_all
}
+output "ec2_t3_unlimited_availability_zone" {
+ description = "The availability zone of the created instance"
+ value = module.ec2_t3_unlimited.availability_zone
+}
+
# EC2 with ignore AMI changes
output "ec2_ignore_ami_changes_ami" {
description = "The AMI of the instance (ignore_ami_changes = true)"
@@ -253,3 +268,8 @@ output "spot_instance_id" {
description = "The Instance ID (if any) that is currently fulfilling the Spot Instance request"
value = module.ec2_spot_instance.spot_instance_id
}
+
+output "spot_instance_availability_zone" {
+ description = "The availability zone of the created spot instance"
+ value = module.ec2_spot_instance.availability_zone
+}
diff --git a/examples/volume-attachment/README.md b/examples/volume-attachment/README.md
index adede89a..3de72392 100644
--- a/examples/volume-attachment/README.md
+++ b/examples/volume-attachment/README.md
@@ -56,6 +56,7 @@ No inputs.
| Name | Description |
|------|-------------|
| [ec2\_arn](#output\_ec2\_arn) | The ARN of the instance |
+| [ec2\_availability\_zone](#output\_ec2\_availability\_zone) | The availability zone of the created spot instance |
| [ec2\_capacity\_reservation\_specification](#output\_ec2\_capacity\_reservation\_specification) | Capacity reservation specification of the instance |
| [ec2\_id](#output\_ec2\_id) | The ID of the instance |
| [ec2\_instance\_state](#output\_ec2\_instance\_state) | The state of the instance. One of: `pending`, `running`, `shutting-down`, `terminated`, `stopping`, `stopped` |
diff --git a/examples/volume-attachment/main.tf b/examples/volume-attachment/main.tf
index f201cad2..877f2140 100644
--- a/examples/volume-attachment/main.tf
+++ b/examples/volume-attachment/main.tf
@@ -44,7 +44,7 @@ resource "aws_volume_attachment" "this" {
}
resource "aws_ebs_volume" "this" {
- availability_zone = element(local.azs, 0)
+ availability_zone = module.ec2.availability_zone
size = 1
tags = local.tags
diff --git a/examples/volume-attachment/outputs.tf b/examples/volume-attachment/outputs.tf
index d9304a30..a927767b 100644
--- a/examples/volume-attachment/outputs.tf
+++ b/examples/volume-attachment/outputs.tf
@@ -43,3 +43,8 @@ output "ec2_tags_all" {
description = "A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block"
value = module.ec2.tags_all
}
+
+output "ec2_availability_zone" {
+ description = "The availability zone of the created spot instance"
+ value = module.ec2.availability_zone
+}
diff --git a/outputs.tf b/outputs.tf
index d79484cd..b10773d4 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -153,6 +153,16 @@ output "ami" {
)
}
+output "availability_zone" {
+ description = "The availability zone of the created instance"
+ value = try(
+ aws_instance.this[0].availability_zone,
+ aws_instance.ignore_ami[0].availability_zone,
+ aws_spot_instance_request.this[0].availability_zone,
+ null,
+ )
+}
+
################################################################################
# IAM Role / Instance Profile
################################################################################