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 #170

Merged
merged 8 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions enhanced-monitoring.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module "enhanced_monitoring_label" {
resource "aws_iam_role" "enhanced_monitoring" {
count = module.this.enabled && var.enhanced_monitoring_role_enabled ? 1 : 0
name = module.enhanced_monitoring_label.id
assume_role_policy = join("", data.aws_iam_policy_document.enhanced_monitoring.*.json)
assume_role_policy = join("", data.aws_iam_policy_document.enhanced_monitoring[*].json)
tags = module.enhanced_monitoring_label.tags
}

# Attach Amazon's managed policy for RDS enhanced monitoring
resource "aws_iam_role_policy_attachment" "enhanced_monitoring" {
count = module.this.enabled && var.enhanced_monitoring_role_enabled ? 1 : 0
role = join("", aws_iam_role.enhanced_monitoring.*.name)
role = join("", aws_iam_role.enhanced_monitoring[*].name)
policy_arn = "arn:${local.partition}:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}

Expand Down
4 changes: 2 additions & 2 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ name = "rds-cluster"

instance_type = "db.t3.small"

cluster_family = "aurora5.6"
cluster_family = "aurora-mysql5.7"

cluster_size = 1

deletion_protection = false

autoscaling_enabled = false

engine = "aurora"
engine = "aurora-mysql"

engine_mode = "provisioned"

Expand Down
16 changes: 6 additions & 10 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ provider "aws" {
}

module "vpc" {
source = "cloudposse/vpc/aws"
version = "1.1.0"

source = "cloudposse/vpc/aws"
version = "2.1.0"
ipv4_primary_cidr_block = "172.16.0.0/16"

context = module.this.context
context = module.this.context
}

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

source = "cloudposse/dynamic-subnets/aws"
version = "2.4.1"
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false

context = module.this.context
context = module.this.context
}

module "rds_cluster" {
Expand Down
4 changes: 2 additions & 2 deletions examples/postgres/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "rds-cluster"

instance_type = "db.m5d.large"

cluster_family = "postgres13"
cluster_family = "postgres14"

cluster_size = 1

Expand All @@ -22,7 +22,7 @@ engine = "postgres"

engine_mode = "provisioned"

engine_version = "13.4"
engine_version = "14.7"

db_name = "test_db"

Expand Down
4 changes: 2 additions & 2 deletions examples/postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "aws" {

module "vpc" {
source = "cloudposse/vpc/aws"
version = "1.1.0"
version = "2.1.0"

ipv4_primary_cidr_block = "172.16.0.0/16"

Expand All @@ -13,7 +13,7 @@ module "vpc" {

module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.0.2"
version = "2.4.1"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
Expand Down
4 changes: 2 additions & 2 deletions examples/serverlessv2_postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "aws" {

module "vpc" {
source = "cloudposse/vpc/aws"
version = "1.1.0"
version = "2.1.0"

ipv4_primary_cidr_block = "172.16.0.0/16"

Expand All @@ -13,7 +13,7 @@ module "vpc" {

module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.0.2"
version = "2.4.1"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
Expand Down
46 changes: 23 additions & 23 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
enabled = module.this.enabled

partition = join("", data.aws_partition.current.*.partition)
partition = join("", data.aws_partition.current[*].partition)

cluster_instance_count = local.enabled ? var.cluster_size : 0
is_regional_cluster = var.cluster_type == "regional"
Expand Down Expand Up @@ -30,7 +30,7 @@ resource "aws_security_group_rule" "ingress_security_groups" {
to_port = var.db_port
protocol = "tcp"
source_security_group_id = var.security_groups[count.index]
security_group_id = join("", aws_security_group.default.*.id)
security_group_id = join("", aws_security_group.default[*].id)
}

resource "aws_security_group_rule" "traffic_inside_security_group" {
Expand All @@ -41,7 +41,7 @@ resource "aws_security_group_rule" "traffic_inside_security_group" {
to_port = var.db_port
protocol = "tcp"
self = true
security_group_id = join("", aws_security_group.default.*.id)
security_group_id = join("", aws_security_group.default[*].id)
}

resource "aws_security_group_rule" "ingress_cidr_blocks" {
Expand All @@ -52,7 +52,7 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
to_port = var.db_port
protocol = "tcp"
cidr_blocks = var.allowed_cidr_blocks
security_group_id = join("", aws_security_group.default.*.id)
security_group_id = join("", aws_security_group.default[*].id)
}

resource "aws_security_group_rule" "egress" {
Expand All @@ -63,7 +63,7 @@ resource "aws_security_group_rule" "egress" {
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = join("", aws_security_group.default.*.id)
security_group_id = join("", aws_security_group.default[*].id)
}

# The name "primary" is poorly chosen. We actually mean standalone or regional.
Expand All @@ -88,16 +88,16 @@ resource "aws_rds_cluster" "primary" {
kms_key_id = var.kms_key_arn
source_region = var.source_region
snapshot_identifier = var.snapshot_identifier
vpc_security_group_ids = compact(flatten([join("", aws_security_group.default.*.id), var.vpc_security_group_ids]))
vpc_security_group_ids = compact(flatten([join("", aws_security_group.default[*].id), var.vpc_security_group_ids]))
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
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
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
preferred_maintenance_window = var.maintenance_window
db_subnet_group_name = join("", aws_db_subnet_group.default.*.name)
db_cluster_parameter_group_name = join("", aws_rds_cluster_parameter_group.default.*.name)
db_subnet_group_name = join("", aws_db_subnet_group.default[*].name)
db_cluster_parameter_group_name = join("", aws_rds_cluster_parameter_group.default[*].name)
iam_database_authentication_enabled = var.iam_database_authentication_enabled
tags = module.this.tags
engine = var.engine
engine_version = var.engine_version
allow_major_version_upgrade = var.allow_major_version_upgrade
db_instance_parameter_group_name = var.allow_major_version_upgrade ? join("", aws_db_parameter_group.default.*.name) : null
db_instance_parameter_group_name = var.allow_major_version_upgrade ? join("", aws_db_parameter_group.default[*].name) : null
engine_mode = var.engine_mode
iam_roles = var.iam_roles
backtrack_window = var.backtrack_window
Expand Down Expand Up @@ -179,10 +179,10 @@ resource "aws_rds_cluster" "secondary" {
kms_key_id = var.kms_key_arn
source_region = var.source_region
snapshot_identifier = var.snapshot_identifier
vpc_security_group_ids = compact(flatten([join("", aws_security_group.default.*.id), var.vpc_security_group_ids]))
vpc_security_group_ids = compact(flatten([join("", aws_security_group.default[*].id), var.vpc_security_group_ids]))
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
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
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
max-lobur marked this conversation as resolved.
Show resolved Hide resolved
preferred_maintenance_window = var.maintenance_window
db_subnet_group_name = join("", aws_db_subnet_group.default.*.name)
db_cluster_parameter_group_name = join("", aws_rds_cluster_parameter_group.default.*.name)
db_subnet_group_name = join("", aws_db_subnet_group.default[*].name)
db_cluster_parameter_group_name = join("", aws_rds_cluster_parameter_group.default[*].name)
iam_database_authentication_enabled = var.iam_database_authentication_enabled
tags = module.this.tags
engine = var.engine
Expand Down Expand Up @@ -241,17 +241,17 @@ resource "aws_rds_cluster" "secondary" {
resource "aws_rds_cluster_instance" "default" {
count = local.cluster_instance_count
identifier = var.cluster_identifier == "" ? "${module.this.id}-${count.index + 1}" : "${var.cluster_identifier}-${count.index + 1}"
cluster_identifier = coalesce(join("", aws_rds_cluster.primary.*.id), join("", aws_rds_cluster.secondary.*.id))
cluster_identifier = coalesce(join("", aws_rds_cluster.primary[*].id), join("", aws_rds_cluster.secondary[*].id))
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
instance_class = var.serverlessv2_scaling_configuration != null ? "db.serverless" : var.instance_type
db_subnet_group_name = join("", aws_db_subnet_group.default.*.name)
db_parameter_group_name = join("", aws_db_parameter_group.default.*.name)
db_subnet_group_name = join("", aws_db_subnet_group.default[*].name)
db_parameter_group_name = join("", aws_db_parameter_group.default[*].name)
publicly_accessible = var.publicly_accessible
tags = module.this.tags
engine = var.engine
engine_version = var.engine_version
auto_minor_version_upgrade = var.auto_minor_version_upgrade
monitoring_interval = var.rds_monitoring_interval
monitoring_role_arn = var.enhanced_monitoring_role_enabled ? join("", aws_iam_role.enhanced_monitoring.*.arn) : var.rds_monitoring_role_arn
monitoring_role_arn = var.enhanced_monitoring_role_enabled ? join("", aws_iam_role.enhanced_monitoring[*].arn) : var.rds_monitoring_role_arn
performance_insights_enabled = var.performance_insights_enabled
performance_insights_kms_key_id = var.performance_insights_kms_key_id
performance_insights_retention_period = var.performance_insights_retention_period
Expand Down Expand Up @@ -349,7 +349,7 @@ module "dns_master" {
enabled = local.enabled && length(var.zone_id) > 0
dns_name = local.cluster_dns_name
zone_id = try(var.zone_id[0], tostring(var.zone_id), "")
records = coalescelist(aws_rds_cluster.primary.*.endpoint, aws_rds_cluster.secondary.*.endpoint, [""])
records = coalescelist(aws_rds_cluster.primary[*].endpoint, aws_rds_cluster.secondary[*].endpoint, [""])

context = module.this.context
}
Expand All @@ -361,7 +361,7 @@ module "dns_replicas" {
enabled = local.enabled && length(var.zone_id) > 0 && !local.is_serverless && local.cluster_instance_count > 0
dns_name = local.reader_dns_name
zone_id = try(var.zone_id[0], tostring(var.zone_id), "")
records = coalescelist(aws_rds_cluster.primary.*.reader_endpoint, aws_rds_cluster.secondary.*.reader_endpoint, [""])
records = coalescelist(aws_rds_cluster.primary[*].reader_endpoint, aws_rds_cluster.secondary[*].reader_endpoint, [""])

context = module.this.context
}
Expand All @@ -370,17 +370,17 @@ resource "aws_appautoscaling_target" "replicas" {
count = local.enabled && var.autoscaling_enabled ? 1 : 0
service_namespace = "rds"
scalable_dimension = "rds:cluster:ReadReplicaCount"
resource_id = "cluster:${coalesce(join("", aws_rds_cluster.primary.*.id), join("", aws_rds_cluster.secondary.*.id))}"
resource_id = "cluster:${coalesce(join("", aws_rds_cluster.primary[*].id), join("", aws_rds_cluster.secondary[*].id))}"
min_capacity = var.autoscaling_min_capacity
max_capacity = var.autoscaling_max_capacity
}

resource "aws_appautoscaling_policy" "replicas" {
count = local.enabled && var.autoscaling_enabled ? 1 : 0
name = module.this.id
service_namespace = join("", aws_appautoscaling_target.replicas.*.service_namespace)
scalable_dimension = join("", aws_appautoscaling_target.replicas.*.scalable_dimension)
resource_id = join("", aws_appautoscaling_target.replicas.*.resource_id)
service_namespace = join("", aws_appautoscaling_target.replicas[*].service_namespace)
scalable_dimension = join("", aws_appautoscaling_target.replicas[*].scalable_dimension)
resource_id = join("", aws_appautoscaling_target.replicas[*].resource_id)
policy_type = var.autoscaling_policy_type

target_tracking_scaling_policy_configuration {
Expand All @@ -398,7 +398,7 @@ resource "aws_appautoscaling_policy" "replicas" {
resource "aws_rds_cluster_activity_stream" "primary" {
count = local.enabled && var.activity_stream_enabled ? 1 : 0

resource_arn = join("", aws_rds_cluster.primary.*.arn)
resource_arn = join("", aws_rds_cluster.primary[*].arn)
mode = var.activity_stream_mode
kms_key_id = var.activity_stream_kms_key_id
}
26 changes: 13 additions & 13 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ output "database_name" {
}

output "master_username" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.master_username) : join("", aws_rds_cluster.secondary.*.master_username)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].master_username) : join("", aws_rds_cluster.secondary[*].master_username)
description = "Username for the master DB user"
sensitive = true
}

output "cluster_identifier" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.cluster_identifier) : join("", aws_rds_cluster.secondary.*.cluster_identifier)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].cluster_identifier) : join("", aws_rds_cluster.secondary[*].cluster_identifier)
description = "Cluster Identifier"
}

output "arn" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.arn) : join("", aws_rds_cluster.secondary.*.arn)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].arn) : join("", aws_rds_cluster.secondary[*].arn)
description = "Amazon Resource Name (ARN) of the cluster"
}

output "endpoint" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.endpoint) : join("", aws_rds_cluster.secondary.*.endpoint)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].endpoint) : join("", aws_rds_cluster.secondary[*].endpoint)
description = "The DNS address of the RDS instance"
}

output "reader_endpoint" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.reader_endpoint) : join("", aws_rds_cluster.secondary.*.reader_endpoint)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].reader_endpoint) : join("", aws_rds_cluster.secondary[*].reader_endpoint)
description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas"
}

Expand All @@ -40,41 +40,41 @@ output "replicas_host" {
}

output "dbi_resource_ids" {
value = aws_rds_cluster_instance.default.*.dbi_resource_id
value = aws_rds_cluster_instance.default[*].dbi_resource_id
description = "List of the region-unique, immutable identifiers for the DB instances in the cluster"
}

output "cluster_resource_id" {
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary.*.cluster_resource_id) : join("", aws_rds_cluster.secondary.*.cluster_resource_id)
value = local.is_regional_cluster ? join("", aws_rds_cluster.primary[*].cluster_resource_id) : join("", aws_rds_cluster.secondary[*].cluster_resource_id)
description = "The region-unique, immutable identifie of the cluster"
}

output "cluster_security_groups" {
value = coalescelist(aws_rds_cluster.primary.*.vpc_security_group_ids, aws_rds_cluster.secondary.*.vpc_security_group_ids, [""])
value = coalescelist(aws_rds_cluster.primary[*].vpc_security_group_ids, aws_rds_cluster.secondary[*].vpc_security_group_ids, [""])
description = "Default RDS cluster security groups"
}

output "security_group_id" {
value = join("", aws_security_group.default.*.id)
value = join("", aws_security_group.default[*].id)
description = "Security Group ID"
}

output "security_group_arn" {
value = join("", aws_security_group.default.*.arn)
value = join("", aws_security_group.default[*].arn)
description = "Security Group ARN"
}

output "security_group_name" {
value = join("", aws_security_group.default.*.name)
value = join("", aws_security_group.default[*].name)
description = "Security Group name"
}

output "activity_stream_arn" {
value = join("", aws_rds_cluster_activity_stream.primary.*.id)
value = join("", aws_rds_cluster_activity_stream.primary[*].id)
description = "Activity Stream ARN"
}

output "activity_stream_name" {
value = join("", aws_rds_cluster_activity_stream.primary.*.kinesis_stream_name)
value = join("", aws_rds_cluster_activity_stream.primary[*].kinesis_stream_name)
description = "Activity Stream Name"
}