-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebd2c68
commit 328df3e
Showing
16 changed files
with
241 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
resource "tls_private_key" "this" { | ||
algorithm = "RSA" | ||
rsa_bits = 2048 | ||
} | ||
|
||
resource "tls_self_signed_cert" "this" { | ||
private_key_pem = tls_private_key.this.private_key_pem | ||
|
||
subject { | ||
common_name = "${module.naming.resource_prefix.acm}1.com" | ||
organization = "ACME Examples, Inc" | ||
} | ||
|
||
validity_period_hours = 800 | ||
|
||
allowed_uses = [ | ||
"key_encipherment", | ||
"digital_signature", | ||
"server_auth", | ||
] | ||
} | ||
|
||
resource "aws_acm_certificate" "this1" { | ||
private_key = tls_private_key.this.private_key_pem | ||
certificate_body = tls_self_signed_cert.this.cert_pem | ||
} | ||
|
||
resource "aws_acm_certificate" "this2" { | ||
domain_name = "${module.naming.resource_prefix.acm}2.com" | ||
validation_method = "DNS" | ||
|
||
options { | ||
certificate_transparency_logging_preference = "ENABLED" | ||
} | ||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resource "aws_lb" "this" { | ||
name = module.naming.resource_prefix.lb | ||
internal = true | ||
load_balancer_type = "application" | ||
subnets = [ | ||
data.terraform_remote_state.common.outputs.vpc_subnet_1_id, | ||
data.terraform_remote_state.common.outputs.vpc_subnet_3_id | ||
] | ||
} | ||
|
||
resource "aws_lb_target_group" "this" { | ||
name = module.naming.resource_prefix.lb | ||
port = 80 | ||
protocol = "HTTP" | ||
vpc_id = data.terraform_remote_state.common.outputs.vpc_id | ||
} | ||
|
||
resource "aws_lb_listener" "this" { | ||
load_balancer_arn = aws_lb.this.arn | ||
port = "443" | ||
protocol = "HTTPS" | ||
ssl_policy = "ELBSecurityPolicy-2016-08" | ||
certificate_arn = aws_acm_certificate.this1.arn | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.this.arn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module "naming" { | ||
source = "../../shared_tf_modules/naming" | ||
resource_type = basename(abspath(path.module)) | ||
status = title(basename(dirname(abspath(path.module)))) | ||
} | ||
|
||
data "terraform_remote_state" "common" { | ||
backend = "local" | ||
|
||
config = { | ||
path = "../common_resources/terraform.tfstate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
output "acm" { | ||
value = { | ||
acm-certificate = aws_acm_certificate.this1.arn | ||
ecc-aws-528-acm_certificate_transparency_logging_enabled = aws_acm_certificate.this2.arn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
default_tags { | ||
tags = module.naming.default_tags | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "region" { | ||
type = string | ||
description = "Region where resources will be created" | ||
default = "us-east-1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
resource "tls_private_key" "this" { | ||
algorithm = "RSA" | ||
rsa_bits = 1024 | ||
} | ||
|
||
resource "tls_self_signed_cert" "this" { | ||
private_key_pem = tls_private_key.this.private_key_pem | ||
|
||
subject { | ||
common_name = "*.${module.naming.resource_prefix.acm}.com" | ||
} | ||
|
||
allowed_uses = [ | ||
"key_encipherment", | ||
"digital_signature", | ||
"server_auth", | ||
] | ||
validity_period_hours = 12 | ||
} | ||
|
||
resource "aws_acm_certificate" "this" { | ||
private_key = tls_private_key.this.private_key_pem | ||
certificate_body = tls_self_signed_cert.this.cert_pem | ||
} | ||
|
||
data "external" "this" { | ||
program = ["bash", "-c", "aws acm request-certificate --domain-name ${module.naming.resource_prefix.acm}.c1 --validation-method DNS | jq -r -c '{arn: .CertificateArn}'"] | ||
} | ||
|
||
resource "null_resource" "this" { | ||
triggers = { | ||
cert_arn = data.external.this.result["arn"] | ||
} | ||
provisioner "local-exec" { | ||
when = destroy | ||
command = "aws acm delete-certificate --certificate-arn ${self.triggers.cert_arn}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module "naming" { | ||
source = "../../shared_tf_modules/naming" | ||
resource_type = basename(abspath(path.module)) | ||
status = title(basename(dirname(abspath(path.module)))) | ||
} | ||
|
||
data "terraform_remote_state" "common" { | ||
backend = "local" | ||
|
||
config = { | ||
path = "../common_resources/terraform.tfstate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "acm" { | ||
value = { | ||
acm-certificate = aws_acm_certificate.this.arn | ||
ecc-aws-109-invalid_or_failed_certificates_are_removed_from_acm = data.external.this.result["arn"] | ||
ecc-aws-393-acm_without_tag_information = data.external.this.result["arn"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
default_tags { | ||
tags = module.naming.default_tags | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
alias = "provider2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "region" { | ||
type = string | ||
description = "Region where resources will be created" | ||
default = "us-east-1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters