Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Darrell Bolger committed Apr 10, 2024
1 parent 7d39fb2 commit e567c6d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 86 deletions.
2 changes: 1 addition & 1 deletion modules/app-autoscaling-policy/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ provider "aws" {
region = "eu-west-2"
}

module "db_instance" {
module "app_autoscaling_policy" {
source = "../src"

environment = "bar"
Expand Down
2 changes: 1 addition & 1 deletion modules/app-autoscaling-target/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ provider "aws" {
region = "eu-west-2"
}

module "db_instance" {
module "app_autoscaling_target" {
source = "../src"

environment = "bar"
Expand Down
2 changes: 1 addition & 1 deletion modules/db-instance/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DB Instance

This module creates a [DB Instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance) and an associated [IAM Role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) for monitoring.
This module creates a [DB Instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance).

## Usage

Expand Down
35 changes: 3 additions & 32 deletions modules/db-instance/src/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_db_instance" "main" {
identifier = "${var.zone}-${var.environment}-${lookup(local.short_regions, var.region)}-${local.identifier}-${lookup(local.db_engines, var.engine)}"
identifier = "${var.zone}-${var.environment}-${local.identifier}-${lookup(local.db_engines, var.engine)}"
db_name = var.db_name
engine = var.engine
engine_version = var.engine_version
Expand All @@ -24,42 +24,13 @@ resource "aws_db_instance" "main" {
password = var.manage_master_user_password ? null : var.password
apply_immediately = var.apply_immediately
monitoring_interval = var.monitoring_interval
monitoring_role_arn = aws_iam_role.main.arn
monitoring_role_arn = var.monitoring_role_arn
performance_insights_enabled = var.performance_insights_enabled

tags = merge(
{
Name = "${var.zone}-${var.environment}-${lookup(local.short_regions, var.region)}-${local.identifier}-${lookup(local.db_engines, var.engine)}"
Name = "${var.zone}-${var.environment}-${local.identifier}-${lookup(local.db_engines, var.engine)}-rds"
},
var.tags
)
}

resource "aws_iam_role" "main" {
name = "${var.zone}-${var.environment}-${lookup(local.short_regions, var.region)}-${local.identifier}-role"

assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "sts:AssumeRole",
Effect = "Allow",
Principal = {
Service = "monitoring.rds.amazonaws.com"
}
}
]
})

tags = merge(
{
Name = "${var.zone}-${var.environment}-${lookup(local.short_regions, var.region)}-${local.identifier}-role"
},
var.tags)
}

resource "aws_iam_policy_attachment" "main" {
name = "rds-monitoring"
roles = [aws_iam_role.main.name]
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}
6 changes: 5 additions & 1 deletion modules/db-instance/src/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variable "backup_retention_period" {

variable "backup_window" {
type = string
default = "02:00-03:00"
default = "01:00-02:00"
}

variable "copy_tags_to_snapshot" {
Expand Down Expand Up @@ -102,6 +102,10 @@ variable "monitoring_interval" {
default = 60
}

variable "monitoring_role_arn" {
type = string
}

variable "multi_az" {
type = string
default = false
Expand Down
1 change: 1 addition & 0 deletions modules/db-instance/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module "db_instance" {
kms_key_id = "foo"
backup_retention_period = 10
db_subnet_group_name = "foogrp"
monitoring_role_arn = "arn"
vpc_security_group_ids = ["foobar"]
username = "barbat"

Expand Down
4 changes: 1 addition & 3 deletions modules/ecr-repository/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ECR Repository

This module creates an [ECR Repository](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository) and an associated [ECR Repository Policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository_policy).
This module creates an [ECR Repository](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository).

## Usage

Expand All @@ -13,8 +13,6 @@ module "ecr_repository" {
region = var.region
zone = var.zone
identifiers = ["123456789012"]
tags = {
WorkloadType = "MortgagesLZ/ai-services"
}
Expand Down
19 changes: 0 additions & 19 deletions modules/ecr-repository/src/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,3 @@ resource "aws_ecr_repository" "main" {
},
var.tags)
}

data "aws_iam_policy_document" "main" {
statement {
sid = "ECR Policy"
effect = "Allow"

principals {
type = "AWS"
identifiers = var.identifiers
}

actions = var.actions
}
}

resource "aws_ecr_repository_policy" "main" {
repository = aws_ecr_repository.main.name
policy = data.aws_iam_policy_document.main.json
}
19 changes: 0 additions & 19 deletions modules/ecr-repository/src/variables.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
variable "actions" {
type = list(string)
default = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:DescribeRepositories",
"ecr:ListImages",
]
}

variable "encryption_type" {
type = string
default = "AES256"
Expand All @@ -31,10 +16,6 @@ variable "identifier" {
type = string
}

variable "identifiers" {
type = list(string)
}

variable "image_tag_mutability" {
type = string
default = "MUTABLE"
Expand Down
2 changes: 0 additions & 2 deletions modules/ecr-repository/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module "ecr_repository" {
region = "eu-west-2"
zone = "bat"

identifiers = ["foo"]

tags = {
Foo = "Bar"
}
Expand Down
19 changes: 17 additions & 2 deletions modules/ecs-service/src/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "aws_ecs_service" "main" {
for_each = var.load_balancers

content {
target_group_arn = load_balancer.value.arn
target_group_arn = load_balancer.value.target_group_arn
container_name = load_balancer.value.container_name
container_port = load_balancer.value.container_port
}
Expand All @@ -36,9 +36,24 @@ resource "aws_ecs_service" "main" {
}
}

dynamic "service_registries" {
for_each = var.service_registry

content {
registry_arn = service_registries.value.registry_arn
port = lookup(service_registries.value, "port", null)
}
}

lifecycle {
ignore_changes = [
desired_count
]
}

tags = merge(
{
Name = "${var.zone}-${var.environment}-${local.identifier}-${lookup(local.short_regions, var.region)}-ecs"
Name = "${var.zone}-${var.environment}-${local.identifier}-${lookup(local.short_regions, var.region)}-ngw"
},
var.tags
)
Expand Down
11 changes: 8 additions & 3 deletions modules/ecs-service/src/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ variable "launch_type" {

variable "load_balancers" {
type = list(object({
arn = string
container_name = string
container_port = number
target_group_arn = string
container_name = string
container_port = number
}))
default = []
}
Expand Down Expand Up @@ -67,6 +67,11 @@ variable "security_groups" {
default = []
}

variable "service_registry" {
type = list(map(string))
default = []
}

variable "subnets" {
type = list(string)
default = []
Expand Down
2 changes: 1 addition & 1 deletion modules/ecs-service/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ provider "aws" {
region = "eu-west-2"
}

module "nat_gateway" {
module "ecs_service" {
source = "../src"

environment = "bar"
Expand Down
2 changes: 1 addition & 1 deletion modules/ecs-task-definition/test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ provider "aws" {
region = "eu-west-2"
}

module "aws_ecs_task_definition" {
module "ecs_task_definition" {
source = "../src"

environment = "bar"
Expand Down

0 comments on commit e567c6d

Please sign in to comment.