Skip to content

Commit

Permalink
Merge pull request #93 from sixfeetup/nvernooy/92-refactor-duplicates
Browse files Browse the repository at this point in the history
Nvernooy/92 refactor duplicates
  • Loading branch information
nvernooy authored Jul 25, 2023
2 parents dea3b07 + 890e3db commit 6d10cef
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_cloudfront_origin_access_identity" "static_storage" {
comment = "${var.application}-${var.environment}"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_iam_policy" "{{cookiecutter.project_slug}}_user_policy" {
name = "task-${module.global_variables.application}-${var.environment}"
name = "task-${var.application}-${var.environment}"
policy = <<EOF
{
"Version": "2012-10-17",
Expand Down Expand Up @@ -44,15 +44,17 @@ resource "aws_iam_policy" "{{cookiecutter.project_slug}}_user_policy" {
EOF
}

resource "aws_iam_user" "{{cookiecutter.project_slug}}_user" {
name = "${module.global_variables.application}-user-${var.environment}"
resource "aws_iam_user" "application_user" {
name = "${var.application}-user-${var.environment}"

tags = local.common_tags
}

resource "aws_iam_access_key" "{{cookiecutter.project_slug}}_user_key" {
user = aws_iam_user.{{cookiecutter.project_slug}}_user.name
resource "aws_iam_access_key" "application_user_key" {
user = aws_iam_user.application_user.name
}

resource "aws_iam_user_policy_attachment" "{{cookiecutter.project_slug}}_user_policy_attachment" {
user = aws_iam_user.{{cookiecutter.project_slug}}_user.name
policy_arn = aws_iam_policy.{{cookiecutter.project_slug}}_user_policy.arn
resource "aws_iam_user_policy_attachment" "application_user_policy_attachment" {
user = aws_iam_user.application_user.name
policy_arn = aws_iam_policy.application_user_policy.arn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
common_tags = merge(var.tags, {
automation = "terraform"
"automation.config" = join(".", [var.application, var.environment])
application = var.application
environment = var.environment
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
output "application_user_access_key" {
value = aws_iam_access_key.application_user_key.id
}

output "application_user_secret_key" {
sensitive = true
value = aws_iam_access_key.application_user_key.secret
}

output "static_storage_bucket" {
value = aws_s3_bucket.static_storage.bucket_domain_name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

data "aws_route53_zone" "route_zone" {
name = var.domain_zone
}

# record for calls to cluster
resource "aws_route53_record" "routes" {
for_each = var.domain_urls
zone_id = data.aws_route53_zone.route_zone.zone_id
name = each.value
type = "A"
records = [var.cluster_public_id]
ttl = 600
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_s3_bucket" "static_storage" {
bucket_prefix = "${module.global_variables.application}-${var.environment}-"
tags = local.common_tags
bucket_prefix = "${var.application}-${var.environment}-"
tags = local.common_tags
}

resource "aws_s3_bucket_server_side_encryption_configuration" "static_storage" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "application" {
default = "{{cookiecutter.project_slug}}"
}

variable "environment" {
default = "sandbox"
}

variable "domain_zone" {
default = "{{ cookiecutter.domain_name }}"
}

variable "domain_urls" {
type = list(string)
default = ["{{ cookiecutter.domain_name }}"]
}

variable "cluster_public_id" {
default = ""
}

variable "tags" {
type = map(string)
default = {}
}
10 changes: 10 additions & 0 deletions {{cookiecutter.project_slug}}/terraform/prod/application.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# the application module sets up Route53 records to the EC2 cluster and S3 static storage
module "application" {
source = "../modules/application"

application = module.global_variables.application
environment = var.environment
domain_zone = var.domain
domain_urls = [var.domain, var.api_domain]
cluster_public_id = data.aws_instance.ec2_cluster.public_ip
}
3 changes: 0 additions & 3 deletions {{cookiecutter.project_slug}}/terraform/prod/cloudfront.tf

This file was deleted.

58 changes: 0 additions & 58 deletions {{cookiecutter.project_slug}}/terraform/prod/iam.tf

This file was deleted.

11 changes: 10 additions & 1 deletion {{cookiecutter.project_slug}}/terraform/prod/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ output "ec2_cluster_public_dns" {
}

output "static_storage_domain" {
value = aws_s3_bucket.static_storage.bucket_domain_name
value = module.application.static_storage_bucket
}

output "application_user_access_key" {
value = module.application.application_user_access_key
}

output "application_user_secret_key" {
sensitive = true
value = module.application.application_user_secret_key
}
22 changes: 0 additions & 22 deletions {{cookiecutter.project_slug}}/terraform/prod/route53.tf

This file was deleted.

81 changes: 0 additions & 81 deletions {{cookiecutter.project_slug}}/terraform/prod/s3.tf

This file was deleted.

10 changes: 10 additions & 0 deletions {{cookiecutter.project_slug}}/terraform/sandbox/application.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# the application module sets up Route53 records to the EC2 cluster and S3 static storage
module "application" {
source = "../modules/application"

application = module.global_variables.application
environment = var.environment
domain_zone = var.domain
domain_urls = [var.domain, var.api_domain]
cluster_public_id = data.aws_instance.ec2_cluster.public_ip
}
3 changes: 0 additions & 3 deletions {{cookiecutter.project_slug}}/terraform/sandbox/cloudfront.tf

This file was deleted.

11 changes: 10 additions & 1 deletion {{cookiecutter.project_slug}}/terraform/sandbox/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ output "ec2_cluster_public_dns" {
}

output "static_storage_domain" {
value = aws_s3_bucket.static_storage.bucket_domain_name
value = module.application.static_storage_bucket
}

output "application_user_access_key" {
value = module.application.application_user_access_key
}

output "application_user_secret_key" {
sensitive = true
value = module.application.application_user_secret_key
}
22 changes: 0 additions & 22 deletions {{cookiecutter.project_slug}}/terraform/sandbox/route53.tf

This file was deleted.

0 comments on commit 6d10cef

Please sign in to comment.