Skip to content

Commit

Permalink
fix: Clean up resource names
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Nov 23, 2023
1 parent e4d4315 commit 12119ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
24 changes: 12 additions & 12 deletions terraform/modules/kitten-science-website/cloudfront.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Certificate
resource "aws_acm_certificate" "kitten_science_website" {
resource "aws_acm_certificate" "this" {
domain_name = var.domain_name
key_algorithm = "EC_prime256v1"
validation_method = "DNS"
Expand All @@ -10,9 +10,9 @@ resource "aws_acm_certificate" "kitten_science_website" {

provider = aws.global
}
resource "aws_route53_record" "kitten_science_website_validation" {
resource "aws_route53_record" "this_validation" {
for_each = {
for dvo in aws_acm_certificate.kitten_science_website.domain_validation_options : dvo.domain_name => {
for dvo in aws_acm_certificate.this.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
Expand All @@ -28,25 +28,25 @@ resource "aws_route53_record" "kitten_science_website_validation" {

provider = aws.global
}
resource "aws_acm_certificate_validation" "kitten_science_website" {
certificate_arn = aws_acm_certificate.kitten_science_website.arn
validation_record_fqdns = [for record in aws_route53_record.kitten_science_website_validation : record.fqdn]
resource "aws_acm_certificate_validation" "this" {
certificate_arn = aws_acm_certificate.this.arn
validation_record_fqdns = [for record in aws_route53_record.this_validation : record.fqdn]

provider = aws.global
}

# Distribution
resource "aws_cloudfront_distribution" "kitten_science_website" {
depends_on = [aws_acm_certificate_validation.kitten_science_website]
resource "aws_cloudfront_distribution" "this" {
depends_on = [aws_acm_certificate_validation.this]

aliases = [var.domain_name]

enabled = true
is_ipv6_enabled = true

origin {
domain_name = aws_s3_bucket_website_configuration.kitten_science_website.website_endpoint
origin_id = aws_s3_bucket.kitten_science_website.bucket
domain_name = aws_s3_bucket_website_configuration.this.website_endpoint
origin_id = aws_s3_bucket.this.bucket
custom_origin_config {
http_port = 80
https_port = 443
Expand All @@ -58,7 +58,7 @@ resource "aws_cloudfront_distribution" "kitten_science_website" {
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = aws_s3_bucket.kitten_science_website.bucket
target_origin_id = aws_s3_bucket.this.bucket

forwarded_values {
query_string = false
Expand All @@ -81,7 +81,7 @@ resource "aws_cloudfront_distribution" "kitten_science_website" {
}

viewer_certificate {
acm_certificate_arn = aws_acm_certificate.kitten_science_website.arn
acm_certificate_arn = aws_acm_certificate.this.arn
minimum_protocol_version = "TLSv1.2_2021"
ssl_support_method = "sni-only"
}
Expand Down
22 changes: 11 additions & 11 deletions terraform/modules/kitten-science-website/iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Maintainer Access
data "aws_iam_policy_document" "kitten_science_maintainer_assume_role" {
data "aws_iam_policy_document" "maintainer_assume_role" {
statement {
actions = ["sts:AssumeRole"]

Expand Down Expand Up @@ -29,27 +29,27 @@ data "aws_iam_policy_document" "kitten_science_maintainer_assume_role" {
}
}
}
resource "aws_iam_role" "kitten_science_maintainer" {
resource "aws_iam_role" "maintainer" {
name = "${var.bucket_name}-maintainer"
assume_role_policy = data.aws_iam_policy_document.kitten_science_maintainer_assume_role.json
assume_role_policy = data.aws_iam_policy_document.maintainer_assume_role.json
}

data "aws_iam_policy_document" "kitten_science_website_maintainer" {
data "aws_iam_policy_document" "maintainer" {
statement {
effect = "Allow"
actions = ["s3:*"]
resources = [
aws_s3_bucket.kitten_science_website.arn,
"${aws_s3_bucket.kitten_science_website.arn}/*"
aws_s3_bucket.this.arn,
"${aws_s3_bucket.this.arn}/*"
]
}
}
resource "aws_iam_policy" "kitten_science_website_maintainer" {
resource "aws_iam_policy" "maintainer" {
name = "${var.bucket_name}-maintainer"
description = "Allows changing the Kitten Science website."
policy = data.aws_iam_policy_document.kitten_science_website_maintainer.json
policy = data.aws_iam_policy_document.maintainer.json
}
resource "aws_iam_role_policy_attachment" "kitten_science_website_maintainer" {
role = aws_iam_role.kitten_science_maintainer.name
policy_arn = aws_iam_policy.kitten_science_website_maintainer.arn
resource "aws_iam_role_policy_attachment" "maintainer" {
role = aws_iam_role.maintainer.name
policy_arn = aws_iam_policy.maintainer.arn
}
6 changes: 3 additions & 3 deletions terraform/modules/kitten-science-website/route53.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
resource "aws_route53_record" "kitten_science_website" {
resource "aws_route53_record" "this" {
for_each = toset([ "A", "AAAA" ])

alias {
evaluate_target_health = true
name = aws_cloudfront_distribution.kitten_science_website.domain_name
zone_id = aws_cloudfront_distribution.kitten_science_website.hosted_zone_id
name = aws_cloudfront_distribution.this.domain_name
zone_id = aws_cloudfront_distribution.this.hosted_zone_id
}

name = var.domain_name
Expand Down
22 changes: 11 additions & 11 deletions terraform/modules/kitten-science-website/s3.tf
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
resource "aws_s3_bucket" "kitten_science_website" {
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
force_destroy = true
}

resource "aws_s3_bucket_ownership_controls" "kitten_science_website" {
bucket = aws_s3_bucket.kitten_science_website.id
resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.this.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}

resource "aws_s3_bucket_public_access_block" "kitten_science_website" {
bucket = aws_s3_bucket.kitten_science_website.id
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_acl" "kitten_science_website" {
resource "aws_s3_bucket_acl" "this" {
depends_on = [
aws_s3_bucket_ownership_controls.kitten_science_website,
aws_s3_bucket_public_access_block.kitten_science_website,
aws_s3_bucket_ownership_controls.this,
aws_s3_bucket_public_access_block.this,
]

bucket = aws_s3_bucket.kitten_science_website.id
bucket = aws_s3_bucket.this.id
acl = "public-read"
}

resource "aws_s3_bucket_website_configuration" "kitten_science_website" {
bucket = aws_s3_bucket.kitten_science_website.id
resource "aws_s3_bucket_website_configuration" "this" {
bucket = aws_s3_bucket.this.id

index_document {
suffix = "index.html"
Expand Down

0 comments on commit 12119ea

Please sign in to comment.