From da379f20cb07d5aa32e13336064294a9a2c1e01a Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 5 Oct 2023 22:43:35 -0700 Subject: [PATCH] Moving remaining s3 configuration to its own folder --- infra/Makefile | 24 ------------------------ infra/data.tf | 12 ------------ infra/local.tf | 13 ------------- infra/s3/Makefile | 24 ++++++++++++++++++++++++ infra/{ => s3}/backend.tf | 2 +- infra/{ => s3}/input-vars.tf | 0 infra/s3/local.tf | 7 +++++++ infra/s3/s3.tf | 17 +++++++++++++++++ infra/{s3.tf => s3/website-config.tf} | 17 +---------------- 9 files changed, 50 insertions(+), 66 deletions(-) delete mode 100644 infra/Makefile delete mode 100644 infra/data.tf delete mode 100644 infra/local.tf create mode 100644 infra/s3/Makefile rename infra/{ => s3}/backend.tf (89%) rename infra/{ => s3}/input-vars.tf (100%) create mode 100644 infra/s3/local.tf create mode 100644 infra/s3/s3.tf rename infra/{s3.tf => s3/website-config.tf} (85%) diff --git a/infra/Makefile b/infra/Makefile deleted file mode 100644 index 507406e..0000000 --- a/infra/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -plan=out.plan - -SHELL := /bin/bash - -$(plan): *.tf - source secrets/set-env.sh && terraform plan -input=false -out $(plan) - -push: build - source secrets/set-env.sh && terraform apply $(plan) - -refresh: - source secrets/set-env.sh && terraform apply -refresh-only - -test: - terraform validate - - -rip: - source secrets/set-env.sh && terraform destroy - -clean: - rm -f $(plan) - -.PHONY: test build clean push rip diff --git a/infra/data.tf b/infra/data.tf deleted file mode 100644 index f655ae9..0000000 --- a/infra/data.tf +++ /dev/null @@ -1,12 +0,0 @@ -data "aws_vpc" "athens" { - id = var.vpc_id -} - -data "aws_subnet" "delphi" { - id = "subnet-0a1943f26e4338cf6" -} - -data "aws_subnet" "crete" { - id = "subnet-09302319a6678643f" -} - diff --git a/infra/local.tf b/infra/local.tf deleted file mode 100644 index 2eb5d6c..0000000 --- a/infra/local.tf +++ /dev/null @@ -1,13 +0,0 @@ -locals { - # ECR - repos = [ - "reverse-proxy", - ] - buckets = [ - "shockrah.xyz", - "resume.shockrah.xyz" - ] - nginx_name = "${var.athens_prefix}-nginx-static-content" - nginx_hp_check_interval = 300 -} - diff --git a/infra/s3/Makefile b/infra/s3/Makefile new file mode 100644 index 0000000..cb42529 --- /dev/null +++ b/infra/s3/Makefile @@ -0,0 +1,24 @@ +plan=out.plan + +SHELL := /bin/bash + +$(plan): *.tf + source ../secrets/set-env.sh && terraform plan -input=false -out $(plan) + +push: build + source ../secrets/set-env.sh && terraform apply $(plan) + +refresh: + source ../secrets/set-env.sh && terraform apply -refresh-only + +test: + terraform validate + + +rip: + source ../secrets/set-env.sh && terraform destroy + +clean: + rm -f $(plan) + +.PHONY: test build clean push rip diff --git a/infra/backend.tf b/infra/s3/backend.tf similarity index 89% rename from infra/backend.tf rename to infra/s3/backend.tf index 3564cd9..8aeadec 100644 --- a/infra/backend.tf +++ b/infra/s3/backend.tf @@ -2,7 +2,7 @@ terraform { required_version = ">= 0.13" backend "s3" { bucket = "project-athens" - key = "infra/state/build.tfstate" + key = "infra/s3/state/build.tfstate" region = "us-west-1" encrypt = true } diff --git a/infra/input-vars.tf b/infra/s3/input-vars.tf similarity index 100% rename from infra/input-vars.tf rename to infra/s3/input-vars.tf diff --git a/infra/s3/local.tf b/infra/s3/local.tf new file mode 100644 index 0000000..3c59afd --- /dev/null +++ b/infra/s3/local.tf @@ -0,0 +1,7 @@ +locals { + buckets = [ + "shockrah.xyz", + "resume.shockrah.xyz" + ] +} + diff --git a/infra/s3/s3.tf b/infra/s3/s3.tf new file mode 100644 index 0000000..e27eeb1 --- /dev/null +++ b/infra/s3/s3.tf @@ -0,0 +1,17 @@ +resource "aws_s3_bucket" "static-content" { + for_each = { + for idx, record in local.buckets: + idx => record + } + + bucket = each.value + + tags = { + Name = each.value + Description = "Static content" + } +} + + + + diff --git a/infra/s3.tf b/infra/s3/website-config.tf similarity index 85% rename from infra/s3.tf rename to infra/s3/website-config.tf index bed30f2..cb632a8 100644 --- a/infra/s3.tf +++ b/infra/s3/website-config.tf @@ -1,17 +1,3 @@ -resource "aws_s3_bucket" "static-content" { - for_each = { - for idx, record in local.buckets: - idx => record - } - - bucket = each.value - - tags = { - Name = each.value - Description = "Static content" - } -} - ################################################################## # Below are the acl components for each bucket to make them public ################################################################## @@ -42,8 +28,6 @@ resource "aws_s3_bucket_public_access_block" "site" { ignore_public_acls = false restrict_public_buckets = false } - - # Set a policy on the bucket to allow reads from anywhere resource "aws_s3_bucket_policy" "site" { for_each = toset(local.buckets) @@ -66,3 +50,4 @@ resource "aws_s3_bucket_policy" "site" { } +