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

Support AWS Provider V5 #57

Merged
merged 6 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,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 +278,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 +332,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)
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
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