From 3142c055357d1e85a897a612096c4cbbb6153f95 Mon Sep 17 00:00:00 2001 From: ongeziwe17 Date: Sun, 7 Dec 2025 00:08:25 +0200 Subject: [PATCH 1/2] Separate provider to its own config file and add lifecycle rule for bootstrap --- bootstrap/main.tf | 28 ++++++++++++++-------------- bootstrap/providers.tf | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 bootstrap/providers.tf diff --git a/bootstrap/main.tf b/bootstrap/main.tf index 3a15d5d..c4644a5 100644 --- a/bootstrap/main.tf +++ b/bootstrap/main.tf @@ -1,17 +1,3 @@ -terraform { - required_version = ">= 1.6.0" - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 5.0" - } - } -} - -provider "aws" { - region = var.aws_region -} - resource "aws_s3_bucket" "tf_state" { bucket = var.state_bucket_name } @@ -21,8 +7,22 @@ resource "aws_s3_bucket_versioning" "tf_state" { versioning_configuration { status = "Enabled" } } +resource "aws_s3_bucket_lifecycle_configuration" "lifecycle" { + bucket = aws_s3_bucket.tf_state.id + + rule { + id = "cleanup-old-versions" + status = "Enabled" + + noncurrent_version_expiration { + noncurrent_days = 90 + } + } +} + resource "aws_s3_bucket_server_side_encryption_configuration" "tf_state" { bucket = aws_s3_bucket.tf_state.id + rule { apply_server_side_encryption_by_default { sse_algorithm = "AES256" diff --git a/bootstrap/providers.tf b/bootstrap/providers.tf new file mode 100644 index 0000000..cc0273a --- /dev/null +++ b/bootstrap/providers.tf @@ -0,0 +1,19 @@ +terraform { + required_version = ">= 1.6.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } +} + +provider "aws" { + region = var.aws_region + default_tags { + tags = { + Project = "flagging-infra" + ManagedBy = "Terraform" + } + } +} From b317a1f43e67a4a6c47d1fcfebceecc14446c1fe Mon Sep 17 00:00:00 2001 From: ongeziwe17 Date: Sun, 7 Dec 2025 00:12:20 +0200 Subject: [PATCH 2/2] terraform fmt --- bootstrap/main.tf | 2 +- bootstrap/providers.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap/main.tf b/bootstrap/main.tf index c4644a5..4b2b718 100644 --- a/bootstrap/main.tf +++ b/bootstrap/main.tf @@ -13,7 +13,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "lifecycle" { rule { id = "cleanup-old-versions" status = "Enabled" - + noncurrent_version_expiration { noncurrent_days = 90 } diff --git a/bootstrap/providers.tf b/bootstrap/providers.tf index cc0273a..f942f42 100644 --- a/bootstrap/providers.tf +++ b/bootstrap/providers.tf @@ -12,8 +12,8 @@ provider "aws" { region = var.aws_region default_tags { tags = { - Project = "flagging-infra" - ManagedBy = "Terraform" + Project = "flagging-infra" + ManagedBy = "Terraform" } } }