Skip to content

Commit

Permalink
Support AWS Provider V5 (#57)
Browse files Browse the repository at this point in the history
* Support AWS Provider V5

* upd

* Support AWS Provider V5

* upd

* updates

* updates
  • Loading branch information
max-lobur authored Jul 5, 2023
1 parent 0a276cf commit 8f1d9a7
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 55 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'examples/**'
- 'test/**'
- 'README.*'

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ permissions:

jobs:
terraform-module:
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ We highly recommend that in your code you pin the version to the exact version y
using so that your infrastructure remains stable, and update versions in a
systematic way so that they do not catch you by surprise.

Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)),
the registry shows many of our inputs as required when in fact they are optional.
The table below correctly indicates which inputs are required.


Note: add `${var.ssh_key_pair}` private key to the `ssh agent`.

Expand Down Expand Up @@ -226,7 +222,7 @@ Available targets:

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |

## Providers
Expand Down Expand Up @@ -278,7 +274,6 @@ Available targets:
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
| <a name="input_comparison_operator"></a> [comparison\_operator](#input\_comparison\_operator) | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold | `string` | `"GreaterThanOrEqualToThreshold"` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| <a name="input_create_default_security_group"></a> [create\_default\_security\_group](#input\_create\_default\_security\_group) | Create default Security Group with only Egress traffic allowed | `bool` | `true` | no |
| <a name="input_default_alarm_action"></a> [default\_alarm\_action](#input\_default\_alarm\_action) | Default alarm action | `string` | `"action/actions/AWS_EC2.InstanceId.Reboot/1.0"` | no |
| <a name="input_delete_on_termination"></a> [delete\_on\_termination](#input\_delete\_on\_termination) | Whether the volume should be destroyed on instance termination | `bool` | `true` | no |
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
Expand Down Expand Up @@ -333,7 +328,6 @@ Available targets:
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no |
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | Instance user data. Do not pass gzip-compressed data via this argument | `string` | `""` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC that the instance security group belongs to | `string` | n/a | yes |
| <a name="input_welcome_message"></a> [welcome\_message](#input\_welcome\_message) | Welcome message | `string` | `""` | no |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion cloud_watch_alarm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "aws_cloudwatch_metric_alarm" "default" {
threshold = var.metric_threshold

dimensions = {
InstanceId = sort(aws_instance.default.*.id)[count.index]
InstanceId = sort(aws_instance.default[*].id)[count.index]
}

alarm_actions = [
Expand Down
4 changes: 1 addition & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |

## Providers
Expand Down Expand Up @@ -55,7 +55,6 @@
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
| <a name="input_comparison_operator"></a> [comparison\_operator](#input\_comparison\_operator) | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold | `string` | `"GreaterThanOrEqualToThreshold"` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| <a name="input_create_default_security_group"></a> [create\_default\_security\_group](#input\_create\_default\_security\_group) | Create default Security Group with only Egress traffic allowed | `bool` | `true` | no |
| <a name="input_default_alarm_action"></a> [default\_alarm\_action](#input\_default\_alarm\_action) | Default alarm action | `string` | `"action/actions/AWS_EC2.InstanceId.Reboot/1.0"` | no |
| <a name="input_delete_on_termination"></a> [delete\_on\_termination](#input\_delete\_on\_termination) | Whether the volume should be destroyed on instance termination | `bool` | `true` | no |
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
Expand Down Expand Up @@ -110,7 +109,6 @@
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no |
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | Instance user data. Do not pass gzip-compressed data via this argument | `string` | `""` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC that the instance security group belongs to | `string` | n/a | yes |
| <a name="input_welcome_message"></a> [welcome\_message](#input\_welcome\_message) | Welcome message | `string` | `""` | no |

## Outputs

Expand Down
8 changes: 4 additions & 4 deletions eni.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ locals {
resource "aws_network_interface" "additional" {
count = local.additional_ips_count * var.instance_count
subnet_id = var.subnet
security_groups = compact(concat(module.security_group.*.id, var.security_groups))
security_groups = compact(concat(module.security_group[*].id, var.security_groups))

tags = module.label.tags
depends_on = [aws_instance.default]
}

resource "aws_network_interface_attachment" "additional" {
count = local.additional_ips_count * var.instance_count
instance_id = aws_instance.default.*.id[count.index % var.instance_count]
network_interface_id = aws_network_interface.additional.*.id[count.index]
instance_id = aws_instance.default[*].id[count.index % var.instance_count]
network_interface_id = aws_network_interface.additional[*].id[count.index]
device_index = 1 + count.index
depends_on = [aws_instance.default]
}

resource "aws_eip" "additional" {
count = local.additional_ips_count * var.instance_count
vpc = true
network_interface = aws_network_interface.additional.*.id[count.index]
network_interface = aws_network_interface.additional[*].id[count.index]
depends_on = [aws_instance.default]
}
10 changes: 10 additions & 0 deletions examples/basic/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}
16 changes: 9 additions & 7 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ provider "aws" {
}

module "vpc" {
source = "cloudposse/vpc/aws"
version = "0.18.1"
cidr_block = "172.16.0.0/16"
source = "cloudposse/vpc/aws"
version = "2.1.0"

ipv4_primary_cidr_block = "172.16.0.0/16"

context = module.this.context
}

module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "0.33.0"
source = "cloudposse/dynamic-subnets/aws"
version = "2.3.0"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = module.vpc.igw_id
cidr_block = module.vpc.vpc_cidr_block
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false

Expand Down
10 changes: 10 additions & 0 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}
18 changes: 9 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ locals {
locals {
public_ips = compact(
concat(
coalescelist(aws_eip.default.*.public_ip, aws_instance.default.*.public_ip),
coalescelist(aws_eip.additional.*.public_ip, [""])
coalescelist(aws_eip.default[*].public_ip, aws_instance.default[*].public_ip),
coalescelist(aws_eip.additional[*].public_ip, [""])
)
)

Expand Down Expand Up @@ -68,7 +68,7 @@ module "label" {
resource "aws_iam_instance_profile" "default" {
count = signum(local.instance_count)
name = module.label.id
role = join("", aws_iam_role.default.*.name)
role = join("", aws_iam_role.default[*].name)
}

resource "aws_iam_role" "default" {
Expand All @@ -89,16 +89,16 @@ resource "aws_instance" "default" {
ebs_optimized = var.ebs_optimized
disable_api_termination = var.disable_api_termination
user_data = var.user_data
iam_instance_profile = join("", aws_iam_instance_profile.default.*.name)
iam_instance_profile = join("", aws_iam_instance_profile.default[*].name)
associate_public_ip_address = var.associate_public_ip_address
key_name = signum(length(var.ssh_key_pair)) == 1 ? var.ssh_key_pair : module.ssh_key_pair.key_name
subnet_id = var.subnet
monitoring = var.monitoring
private_ip = concat(var.private_ips, [""])[min(length(var.private_ips), count.index)]
private_ip = concat(var.private_ips, [null])[min(length(var.private_ips), count.index)]
source_dest_check = var.source_dest_check
ipv6_address_count = var.ipv6_address_count < 0 ? null : var.ipv6_address_count
ipv6_addresses = length(var.ipv6_addresses) > 0 ? var.ipv6_addresses : null
vpc_security_group_ids = compact(concat(module.security_group.*.id, var.security_groups))
vpc_security_group_ids = compact(concat(module.security_group[*].id, var.security_groups))

root_block_device {
volume_type = local.root_volume_type
Expand Down Expand Up @@ -138,7 +138,7 @@ module "ssh_key_pair" {

resource "aws_eip" "default" {
count = local.count_default_ips
network_interface = aws_instance.default.*.primary_network_interface_id[count.index]
network_interface = aws_instance.default[*].primary_network_interface_id[count.index]
vpc = true
depends_on = [aws_instance.default]
tags = module.this.tags
Expand All @@ -158,6 +158,6 @@ resource "aws_ebs_volume" "default" {
resource "aws_volume_attachment" "default" {
count = signum(local.instance_count) == 1 ? var.ebs_volume_count * local.instance_count : 0
device_name = element(slice(var.ebs_device_names, 0, floor(var.ebs_volume_count * local.instance_count / max(local.instance_count, 1))), count.index)
volume_id = aws_ebs_volume.default.*.id[count.index]
instance_id = aws_instance.default.*.id[count.index]
volume_id = aws_ebs_volume.default[*].id[count.index]
instance_id = aws_instance.default[*].id[count.index]
}
20 changes: 10 additions & 10 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ output "public_ips" {

output "private_ips" {
description = "Private IPs of instances"
value = aws_instance.default.*.private_ip
value = aws_instance.default[*].private_ip
}

output "private_dns" {
description = "Private DNS records of instances"
value = aws_instance.default.*.private_dns
value = aws_instance.default[*].private_dns
}

output "public_dns" {
Expand All @@ -20,7 +20,7 @@ output "public_dns" {

output "ids" {
description = "Disambiguated IDs list"
value = aws_instance.default.*.id
value = aws_instance.default[*].id
}

output "name" {
Expand All @@ -45,7 +45,7 @@ output "ssh_key_pem_path" {

output "security_group_ids" {
description = "ID on the new AWS Security Group associated with creating instance"
value = compact(concat(module.security_group.*.id, var.security_groups))
value = compact(concat(module.security_group[*].id, var.security_groups))
}

output "security_group_id" {
Expand All @@ -65,30 +65,30 @@ output "security_group_name" {

output "role_names" {
description = "Names of AWS IAM Roles associated with creating instance"
value = compact(aws_iam_role.default.*.name)
value = compact(aws_iam_role.default[*].name)
}

output "alarm_ids" {
description = "CloudWatch Alarm IDs"
value = aws_cloudwatch_metric_alarm.default.*.id
value = aws_cloudwatch_metric_alarm.default[*].id
}

output "eni_to_eip_map" {
description = "Map of ENI with EIP"
value = zipmap(
aws_network_interface.additional.*.id,
aws_eip.additional.*.public_ip
aws_network_interface.additional[*].id,
aws_eip.additional[*].public_ip
)
}

output "ebs_ids" {
description = "IDs of EBSs"
value = aws_ebs_volume.default.*.id
value = aws_ebs_volume.default[*].id
}

output "primary_network_interface_ids" {
description = "IDs of the instance's primary network interface"
value = aws_instance.default.*.primary_network_interface_id
value = aws_instance.default[*].primary_network_interface_id
}

output "eip_per_instance_count" {
Expand Down
12 changes: 0 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ variable "delete_on_termination" {
default = true
}

variable "welcome_message" {
type = string
description = "Welcome message"
default = ""
}

variable "comparison_operator" {
type = string
description = "The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold"
Expand Down Expand Up @@ -264,12 +258,6 @@ variable "default_alarm_action" {
default = "action/actions/AWS_EC2.InstanceId.Reboot/1.0"
}

variable "create_default_security_group" {
type = bool
description = "Create default Security Group with only Egress traffic allowed"
default = true
}

variable "additional_ips_count" {
type = number
description = "Count of additional EIPs"
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.13"
required_version = ">= 1.0"

required_providers {
aws = {
Expand Down

0 comments on commit 8f1d9a7

Please sign in to comment.