From cc298b81ddb1b0d26e1873c0da92a900fdafd862 Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Tue, 30 Sep 2025 02:38:02 +0000 Subject: [PATCH 1/8] Update AWS region in main.tf and enhance comments in terraform.tfvars.example --- main.tf | 11 +++++++++-- terraform.tfvars.example | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 4e161f7..e0df539 100644 --- a/main.tf +++ b/main.tf @@ -6,11 +6,18 @@ terraform { version = "~> 5.0" } } + + # cloud { + # organization = "sujay-test-01" + # workspaces { + # name = "cli-driven-test-workspace-1" + # } + # } } # Configure the AWS Provider provider "aws" { - region = "us-east-1" + region = "ap-south-1" } # Create S3 bucket @@ -53,4 +60,4 @@ resource "aws_s3_bucket_public_access_block" "main" { block_public_policy = true ignore_public_acls = true restrict_public_buckets = true -} \ No newline at end of file +} diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 2c2c197..66ae8fc 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -1,10 +1,10 @@ # Example Terraform variables file # Copy this file to terraform.tfvars and customize the values -bucket_name = "my-unique-bucket-name-12345" -environment = "dev" +bucket_name = "my-unique-bucket-name-12345" # must be unique across AWS +environment = "dev" # must be either dev, int or prod -tags = { +tags = { # optional "Project" = "cli-driven-test-workspace-1" "Owner" = "terraform-test-lab" } \ No newline at end of file From aa1c54d7d8e30049608229dc6b2f11c88346594a Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Tue, 30 Sep 2025 02:53:47 +0000 Subject: [PATCH 2/8] Remove commented-out cloud configuration from main.tf --- main.tf | 7 ------- 1 file changed, 7 deletions(-) diff --git a/main.tf b/main.tf index e0df539..6b11520 100644 --- a/main.tf +++ b/main.tf @@ -6,13 +6,6 @@ terraform { version = "~> 5.0" } } - - # cloud { - # organization = "sujay-test-01" - # workspaces { - # name = "cli-driven-test-workspace-1" - # } - # } } # Configure the AWS Provider From 5a39460120d06168b92af92fb37a8fe981364dfc Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Tue, 30 Sep 2025 02:57:05 +0000 Subject: [PATCH 3/8] added vcs.auto.tfvars to track the file in git --- .gitignore | 1 + vcs.auto.tfvars | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 vcs.auto.tfvars diff --git a/.gitignore b/.gitignore index 6349e36..9ae65a1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ override.tf.json # Ignore CLI configuration files .terraformrc terraform.rc +!vcs.auto.tfvars \ No newline at end of file diff --git a/vcs.auto.tfvars b/vcs.auto.tfvars new file mode 100644 index 0000000..8cb92be --- /dev/null +++ b/vcs.auto.tfvars @@ -0,0 +1,7 @@ +bucket_name = "my-unique-bucket-name-12345-sujay-test-vcs" # must be unique across AWS +environment = "dev" # must be either dev, int or prod + +tags = { # optional + "Project" = "vcs-driven-test-workspace-1" + "Owner" = "terraform-test-lab" +} \ No newline at end of file From 6142dfb8e3a13daf93377eafefc8362c147788e0 Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Fri, 3 Oct 2025 03:54:34 +0000 Subject: [PATCH 4/8] Add terraform.tfvars file and update .gitignore to include it --- .gitignore | 3 ++- vcs.auto.tfvars => terraform.tfvars | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename vcs.auto.tfvars => terraform.tfvars (55%) diff --git a/.gitignore b/.gitignore index 9ae65a1..6b83448 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ override.tf.json # Ignore CLI configuration files .terraformrc terraform.rc -!vcs.auto.tfvars \ No newline at end of file +!vcs.auto.tfvars +!terraform.tfvars \ No newline at end of file diff --git a/vcs.auto.tfvars b/terraform.tfvars similarity index 55% rename from vcs.auto.tfvars rename to terraform.tfvars index 8cb92be..6167d04 100644 --- a/vcs.auto.tfvars +++ b/terraform.tfvars @@ -1,7 +1,7 @@ -bucket_name = "my-unique-bucket-name-12345-sujay-test-vcs" # must be unique across AWS +bucket_name = "my-unique-bucket-name-12345-sujay-test-cli" # must be unique across AWS environment = "dev" # must be either dev, int or prod tags = { # optional - "Project" = "vcs-driven-test-workspace-1" + "Project" = "cli-driven-test-workspace-1" "Owner" = "terraform-test-lab" } \ No newline at end of file From b4cb2cdd09c9ea61d13d81e22484fd2ff1a417a0 Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Fri, 3 Oct 2025 03:59:02 +0000 Subject: [PATCH 5/8] Add cloud configuration to main.tf for workspace management --- main.tf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.tf b/main.tf index 6b11520..6f0a10d 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,4 @@ + terraform { required_version = ">= 1.0" required_providers { @@ -6,13 +7,22 @@ terraform { version = "~> 5.0" } } + + cloud { + organization = "sujay-test-01" + workspaces { + name = "cli-driven-test-workspace-1" + } + } } + # Configure the AWS Provider provider "aws" { region = "ap-south-1" } + # Create S3 bucket resource "aws_s3_bucket" "main" { bucket = var.bucket_name @@ -26,6 +36,7 @@ resource "aws_s3_bucket" "main" { ) } + # Configure S3 bucket versioning resource "aws_s3_bucket_versioning" "main" { bucket = aws_s3_bucket.main.id @@ -34,6 +45,7 @@ resource "aws_s3_bucket_versioning" "main" { } } + # Configure S3 bucket server-side encryption resource "aws_s3_bucket_server_side_encryption_configuration" "main" { bucket = aws_s3_bucket.main.id @@ -45,6 +57,7 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "main" { } } + # Block public access to the S3 bucket resource "aws_s3_bucket_public_access_block" "main" { bucket = aws_s3_bucket.main.id From 3545fd0fa9ae4eebdc86d479ad2e3287dc7e3632 Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Fri, 3 Oct 2025 04:54:19 +0000 Subject: [PATCH 6/8] Remove validation rules from bucket_name and environment variables in variables.tf --- variables.tf | 8 -------- 1 file changed, 8 deletions(-) diff --git a/variables.tf b/variables.tf index 51c3913..379974b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,20 +1,12 @@ variable "bucket_name" { description = "Name of the S3 bucket" type = string - validation { - condition = can(regex("^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$", var.bucket_name)) - error_message = "Bucket name must be between 3 and 63 characters, start and end with lowercase letter or number, and contain only lowercase letters, numbers, and hyphens." - } } variable "environment" { description = "Environment name (e.g., dev, staging, prod)" type = string default = "dev" - validation { - condition = contains(["dev", "staging", "prod"], var.environment) - error_message = "Environment must be one of: dev, staging, prod." - } } variable "tags" { From c945b5f54311ce86994ffbb6cab4744c0c3c8a4d Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Fri, 3 Oct 2025 07:16:59 +0000 Subject: [PATCH 7/8] Add missing hash for AWS provider in .terraform.lock.hcl --- .terraform.lock.hcl | 1 + 1 file changed, 1 insertion(+) diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 39a6fbd..db1d5f3 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -5,6 +5,7 @@ provider "registry.terraform.io/hashicorp/aws" { version = "5.100.0" constraints = "~> 5.0" hashes = [ + "h1:Ijt7pOlB7Tr7maGQIqtsLFbl7pSMIj06TVdkoSBcYOw=", "h1:edXOJWE4ORX8Fm+dpVpICzMZJat4AX0VRCAy/xkcOc0=", "zh:054b8dd49f0549c9a7cc27d159e45327b7b65cf404da5e5a20da154b90b8a644", "zh:0b97bf8d5e03d15d83cc40b0530a1f84b459354939ba6f135a0086c20ebbe6b2", From b8ced7e278d7aa38fcca048f5d7f61572ee0403c Mon Sep 17 00:00:00 2001 From: Terrform Migrate Service Account Date: Fri, 3 Oct 2025 07:30:19 +0000 Subject: [PATCH 8/8] Add Terraform configuration for AWS S3 bucket and TFE stack migration --- .gitignore | 6 +- modularized_config/.terraform.lock.hcl | 25 +++++ .../_stacks_generated/.terraform-version | 1 + .../_stacks_generated/.terraform.lock.hcl | 26 +++++ .../components.tfcomponent.hcl | 18 ++++ .../_stacks_generated/deployment.tfdeploy.hcl | 30 ++++++ .../_stacks_generated/outputs.tfcomponent.hcl | 14 +++ .../providers.tfcomponent.hcl | 18 ++++ .../terraform_modules/main.tf | 71 +++++++++++++ .../terraform_modules/outputs.tf | 9 ++ .../terraform_modules/variables.tf | 16 +++ .../variables.tfcomponent.hcl | 38 +++++++ modularized_config/main.tf | 28 ++++++ modularized_config/outputs.tf | 10 ++ .../.terraform.lock.hcl | 42 ++++++++ .../stacks_migration_infra/main.tf | 36 +++++++ .../stacks_migration_infra/output.tf | 7 ++ .../stacks_migration_infra/terraform.tfstate | 99 +++++++++++++++++++ .../stacks_migration_infra/variables.tf | 29 ++++++ modularized_config/terraform.tfvars | 7 ++ modularized_config/terraform_modules/main.tf | 69 +++++++++++++ .../terraform_modules/outputs.tf | 9 ++ .../terraform_modules/variables.tf | 16 +++ modularized_config/variables.tf | 16 +++ 24 files changed, 639 insertions(+), 1 deletion(-) create mode 100644 modularized_config/.terraform.lock.hcl create mode 100644 modularized_config/_stacks_generated/.terraform-version create mode 100644 modularized_config/_stacks_generated/.terraform.lock.hcl create mode 100644 modularized_config/_stacks_generated/components.tfcomponent.hcl create mode 100644 modularized_config/_stacks_generated/deployment.tfdeploy.hcl create mode 100644 modularized_config/_stacks_generated/outputs.tfcomponent.hcl create mode 100644 modularized_config/_stacks_generated/providers.tfcomponent.hcl create mode 100644 modularized_config/_stacks_generated/terraform_modules/main.tf create mode 100644 modularized_config/_stacks_generated/terraform_modules/outputs.tf create mode 100644 modularized_config/_stacks_generated/terraform_modules/variables.tf create mode 100644 modularized_config/_stacks_generated/variables.tfcomponent.hcl create mode 100644 modularized_config/main.tf create mode 100644 modularized_config/outputs.tf create mode 100644 modularized_config/stacks_migration_infra/.terraform.lock.hcl create mode 100644 modularized_config/stacks_migration_infra/main.tf create mode 100644 modularized_config/stacks_migration_infra/output.tf create mode 100644 modularized_config/stacks_migration_infra/terraform.tfstate create mode 100644 modularized_config/stacks_migration_infra/variables.tf create mode 100644 modularized_config/terraform.tfvars create mode 100644 modularized_config/terraform_modules/main.tf create mode 100644 modularized_config/terraform_modules/outputs.tf create mode 100644 modularized_config/terraform_modules/variables.tf create mode 100644 modularized_config/variables.tf diff --git a/.gitignore b/.gitignore index 6b83448..855fab4 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,8 @@ override.tf.json .terraformrc terraform.rc !vcs.auto.tfvars -!terraform.tfvars \ No newline at end of file +!terraform.tfvars +!modularized_config/_stacks_generated/.terraform.lock.hcl +!modularized_config/stacks_migration_infra/.terraform.lock.hcl +!modularized_config/stacks_migration_infra/terraform.tfstate +!modularized_config/.terraform.lock.hcl \ No newline at end of file diff --git a/modularized_config/.terraform.lock.hcl b/modularized_config/.terraform.lock.hcl new file mode 100644 index 0000000..cdc1668 --- /dev/null +++ b/modularized_config/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.100.0" + constraints = "~> 5.0" + hashes = [ + "h1:Ijt7pOlB7Tr7maGQIqtsLFbl7pSMIj06TVdkoSBcYOw=", + "zh:054b8dd49f0549c9a7cc27d159e45327b7b65cf404da5e5a20da154b90b8a644", + "zh:0b97bf8d5e03d15d83cc40b0530a1f84b459354939ba6f135a0086c20ebbe6b2", + "zh:1589a2266af699cbd5d80737a0fe02e54ec9cf2ca54e7e00ac51c7359056f274", + "zh:6330766f1d85f01ae6ea90d1b214b8b74cc8c1badc4696b165b36ddd4cc15f7b", + "zh:7c8c2e30d8e55291b86fcb64bdf6c25489d538688545eb48fd74ad622e5d3862", + "zh:99b1003bd9bd32ee323544da897148f46a527f622dc3971af63ea3e251596342", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f8b909d3ec50ade83c8062290378b1ec553edef6a447c56dadc01a99f4eaa93", + "zh:aaef921ff9aabaf8b1869a86d692ebd24fbd4e12c21205034bb679b9caf883a2", + "zh:ac882313207aba00dd5a76dbd572a0ddc818bb9cbf5c9d61b28fe30efaec951e", + "zh:bb64e8aff37becab373a1a0cc1080990785304141af42ed6aa3dd4913b000421", + "zh:dfe495f6621df5540d9c92ad40b8067376350b005c637ea6efac5dc15028add4", + "zh:f0ddf0eaf052766cfe09dea8200a946519f653c384ab4336e2a4a64fdd6310e9", + "zh:f1b7e684f4c7ae1eed272b6de7d2049bb87a0275cb04dbb7cda6636f600699c9", + "zh:ff461571e3f233699bf690db319dfe46aec75e58726636a0d97dd9ac6e32fb70", + ] +} diff --git a/modularized_config/_stacks_generated/.terraform-version b/modularized_config/_stacks_generated/.terraform-version new file mode 100644 index 0000000..f0df1f7 --- /dev/null +++ b/modularized_config/_stacks_generated/.terraform-version @@ -0,0 +1 @@ +1.13.2 \ No newline at end of file diff --git a/modularized_config/_stacks_generated/.terraform.lock.hcl b/modularized_config/_stacks_generated/.terraform.lock.hcl new file mode 100644 index 0000000..f9278ab --- /dev/null +++ b/modularized_config/_stacks_generated/.terraform.lock.hcl @@ -0,0 +1,26 @@ +# This file is maintained automatically by "terraform stacks providers lock". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.100.0" + hashes = [ + "h1:Ijt7pOlB7Tr7maGQIqtsLFbl7pSMIj06TVdkoSBcYOw=", + "h1:edXOJWE4ORX8Fm+dpVpICzMZJat4AX0VRCAy/xkcOc0=", + "h1:wOhTPz6apLBuF7/FYZuCoXRK/MLgrNprZ3vXmq83g5k=", + "zh:054b8dd49f0549c9a7cc27d159e45327b7b65cf404da5e5a20da154b90b8a644", + "zh:0b97bf8d5e03d15d83cc40b0530a1f84b459354939ba6f135a0086c20ebbe6b2", + "zh:1589a2266af699cbd5d80737a0fe02e54ec9cf2ca54e7e00ac51c7359056f274", + "zh:6330766f1d85f01ae6ea90d1b214b8b74cc8c1badc4696b165b36ddd4cc15f7b", + "zh:7c8c2e30d8e55291b86fcb64bdf6c25489d538688545eb48fd74ad622e5d3862", + "zh:99b1003bd9bd32ee323544da897148f46a527f622dc3971af63ea3e251596342", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f8b909d3ec50ade83c8062290378b1ec553edef6a447c56dadc01a99f4eaa93", + "zh:aaef921ff9aabaf8b1869a86d692ebd24fbd4e12c21205034bb679b9caf883a2", + "zh:ac882313207aba00dd5a76dbd572a0ddc818bb9cbf5c9d61b28fe30efaec951e", + "zh:bb64e8aff37becab373a1a0cc1080990785304141af42ed6aa3dd4913b000421", + "zh:dfe495f6621df5540d9c92ad40b8067376350b005c637ea6efac5dc15028add4", + "zh:f0ddf0eaf052766cfe09dea8200a946519f653c384ab4336e2a4a64fdd6310e9", + "zh:f1b7e684f4c7ae1eed272b6de7d2049bb87a0275cb04dbb7cda6636f600699c9", + "zh:ff461571e3f233699bf690db319dfe46aec75e58726636a0d97dd9ac6e32fb70", + ] +} diff --git a/modularized_config/_stacks_generated/components.tfcomponent.hcl b/modularized_config/_stacks_generated/components.tfcomponent.hcl new file mode 100644 index 0000000..5796255 --- /dev/null +++ b/modularized_config/_stacks_generated/components.tfcomponent.hcl @@ -0,0 +1,18 @@ +# Generated by tf-migrate 1.3.0 + +component "terraform_module" { + source = "./terraform_modules" + + inputs = { + "bucket_name" = var.bucket_name + "environment" = var.environment + "tags" = var.tags + } + + + providers = { + aws = provider.aws.this + } +} + + diff --git a/modularized_config/_stacks_generated/deployment.tfdeploy.hcl b/modularized_config/_stacks_generated/deployment.tfdeploy.hcl new file mode 100644 index 0000000..78df35c --- /dev/null +++ b/modularized_config/_stacks_generated/deployment.tfdeploy.hcl @@ -0,0 +1,30 @@ +# Generated by tf-migrate 1.3.0 + + +# Note on stacks authentication: +# tf-migrate cannot generate stack authentication, this needs to be manually added before execute +# More on authentication - https://developer.hashicorp.com/terraform/language/stacks/deploy/authenticate + +store "varset" "tokens" { + id = "varset-xvfRyT1qNahGfpWm" + category = "env" +} + + +deployment "cli-driven-test-workspace-1" { + inputs = { + access_key = store.varset.tokens.AWS_ACCESS_KEY_ID + secret_key = store.varset.tokens.AWS_SECRET_ACCESS_KEY + session_token = store.varset.tokens.AWS_SESSION_TOKEN + tags = { + Owner = "terraform-test-lab" + Project = "cli-driven-test-workspace-1" + } + bucket_name = "my-unique-bucket-name-12345-sujay-test-cli" + environment = "dev" + } + import = true +} + + + diff --git a/modularized_config/_stacks_generated/outputs.tfcomponent.hcl b/modularized_config/_stacks_generated/outputs.tfcomponent.hcl new file mode 100644 index 0000000..7c2d534 --- /dev/null +++ b/modularized_config/_stacks_generated/outputs.tfcomponent.hcl @@ -0,0 +1,14 @@ +# Generated by tf-migrate 1.3.0 + +output "bucket_name" { + description = "Name of the created S3 bucket" + value = component.terraform_module.bucket_name + type = string +} + +output "bucket_arn" { + description = "ARN of the created S3 bucket" + value = component.terraform_module.bucket_arn + type = string +} + diff --git a/modularized_config/_stacks_generated/providers.tfcomponent.hcl b/modularized_config/_stacks_generated/providers.tfcomponent.hcl new file mode 100644 index 0000000..c31489f --- /dev/null +++ b/modularized_config/_stacks_generated/providers.tfcomponent.hcl @@ -0,0 +1,18 @@ +# Generated by tf-migrate 1.3.0 + +required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.7.0" + } +} + +provider "aws" "this" { + config { + region = "ap-south-1" + access_key = var.access_key + secret_key = var.secret_key + token = var.session_token + } +} + diff --git a/modularized_config/_stacks_generated/terraform_modules/main.tf b/modularized_config/_stacks_generated/terraform_modules/main.tf new file mode 100644 index 0000000..8ff322b --- /dev/null +++ b/modularized_config/_stacks_generated/terraform_modules/main.tf @@ -0,0 +1,71 @@ + +terraform { + required_version = ">= 1.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } + + cloud { + organization = "sujay-test-01" + workspaces { + name = "cli-driven-test-workspace-1" + } + } +} + + +# Configure the AWS Provider +/* commented by tf-migrate, ref - https://developer.hashicorp.com/terraform/language/stacks/create/declare-providers +provider "aws" { + region = "ap-south-1" +} +*/ + + +# Create S3 bucket +resource "aws_s3_bucket" "main" { + bucket = var.bucket_name + + tags = merge( + var.tags, + { + Environment = var.environment + ManagedBy = "Terraform" + } + ) +} + + +# Configure S3 bucket versioning +resource "aws_s3_bucket_versioning" "main" { + bucket = aws_s3_bucket.main.id + versioning_configuration { + status = "Enabled" + } +} + + +# Configure S3 bucket server-side encryption +resource "aws_s3_bucket_server_side_encryption_configuration" "main" { + bucket = aws_s3_bucket.main.id + + rule { + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } +} + + +# Block public access to the S3 bucket +resource "aws_s3_bucket_public_access_block" "main" { + bucket = aws_s3_bucket.main.id + + block_public_acls = true + block_public_policy = true + ignore_public_acls = true + restrict_public_buckets = true +} diff --git a/modularized_config/_stacks_generated/terraform_modules/outputs.tf b/modularized_config/_stacks_generated/terraform_modules/outputs.tf new file mode 100644 index 0000000..5f428ea --- /dev/null +++ b/modularized_config/_stacks_generated/terraform_modules/outputs.tf @@ -0,0 +1,9 @@ +output "bucket_name" { + description = "Name of the created S3 bucket" + value = aws_s3_bucket.main.bucket +} + +output "bucket_arn" { + description = "ARN of the created S3 bucket" + value = aws_s3_bucket.main.arn +} \ No newline at end of file diff --git a/modularized_config/_stacks_generated/terraform_modules/variables.tf b/modularized_config/_stacks_generated/terraform_modules/variables.tf new file mode 100644 index 0000000..379974b --- /dev/null +++ b/modularized_config/_stacks_generated/terraform_modules/variables.tf @@ -0,0 +1,16 @@ +variable "bucket_name" { + description = "Name of the S3 bucket" + type = string +} + +variable "environment" { + description = "Environment name (e.g., dev, staging, prod)" + type = string + default = "dev" +} + +variable "tags" { + description = "Additional tags to apply to the S3 bucket" + type = map(string) + default = {} +} \ No newline at end of file diff --git a/modularized_config/_stacks_generated/variables.tfcomponent.hcl b/modularized_config/_stacks_generated/variables.tfcomponent.hcl new file mode 100644 index 0000000..8101770 --- /dev/null +++ b/modularized_config/_stacks_generated/variables.tfcomponent.hcl @@ -0,0 +1,38 @@ +# Generated by tf-migrate 1.3.0 + +variable "environment" { + description = "Environment name (e.g., dev, staging, prod)" + type = string + default = "dev" +} + +variable "tags" { + description = "Additional tags to apply to the S3 bucket" + type = map(string) + default = {} +} + +variable "bucket_name" { + description = "Name of the S3 bucket" + type = string +} + +variable "access_key" { + description = "AWS access key" + type = string + ephemeral = true +} + +variable "secret_key" { + description = "AWS sensitive secret key." + type = string + sensitive = true + ephemeral = true +} + +variable "session_token" { + description = "AWS session token." + type = string + sensitive = true + ephemeral = true +} \ No newline at end of file diff --git a/modularized_config/main.tf b/modularized_config/main.tf new file mode 100644 index 0000000..c62403a --- /dev/null +++ b/modularized_config/main.tf @@ -0,0 +1,28 @@ +terraform { + required_version = ">= 1.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } + + cloud { + organization = "sujay-test-01" + workspaces { + name = "cli-driven-test-workspace-1" + } + } +} + +# Configure the AWS Provider +provider "aws" { + region = "ap-south-1" +} + +module "terraform_module" { + source = "./terraform_modules" + environment = var.environment + tags = var.tags + bucket_name = var.bucket_name +} diff --git a/modularized_config/outputs.tf b/modularized_config/outputs.tf new file mode 100644 index 0000000..cf5861a --- /dev/null +++ b/modularized_config/outputs.tf @@ -0,0 +1,10 @@ +output "bucket_name" { + description = "Name of the created S3 bucket" + value = module.terraform_module.bucket_name +} + +output "bucket_arn" { + description = "ARN of the created S3 bucket" + value = module.terraform_module.bucket_arn +} + diff --git a/modularized_config/stacks_migration_infra/.terraform.lock.hcl b/modularized_config/stacks_migration_infra/.terraform.lock.hcl new file mode 100644 index 0000000..341a2fa --- /dev/null +++ b/modularized_config/stacks_migration_infra/.terraform.lock.hcl @@ -0,0 +1,42 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/tfe" { + version = "0.70.0" + constraints = ">= 0.67.0" + hashes = [ + "h1:Ec0oVc+y+v0D3X/xw36RgPqNJHF7gTTllgoAJFUY73Y=", + "zh:15da83e255cb314c3a6dc4dee116bde408a19f91fed09ca9b57421ff18e825f2", + "zh:1893ea8d8af605cf89c23b16df2a91c0e1b35de97fcd2a5f3f4ffec01f78bbae", + "zh:22b998a850219a3e27205771b9827ed093c904a422dcba37301c1b42a73b17fa", + "zh:23654e8da805856609198a711510e398a185c9fc6ecd538ed21fbf18f38dab55", + "zh:4f40c6376359ea09fb359a935bab22e44d2cdade81abba0935117f429736bbd5", + "zh:53baf684acaf80d16fa8a34a2a6d12ec3449e12c593e95f34df451b52475a0a3", + "zh:541d4532c875b2ee7ecb98da9a1461e76788893b623b0adf7c634d9fff7770e3", + "zh:625a4dea24f33700b5c11a27447c3227401490f0ad005c3e28825c4aa0013f44", + "zh:876a21f4691a8bd29ad579e880efeecd916d40e29f3cc5ce5099ecf6540d0c07", + "zh:8bd3cdf321db5d8cfa03ba2afbb1a31c2073a06e0d5258fd863974e8ac6918c0", + "zh:b063c4d4e5a681411f88afa5c4fe32d9de380c67c3d6cdd5f21ce9de0d4f9f31", + "zh:f360c24951e3c102a1106e9912e5ef255a5efa74b44ef37d2251db58d50f2e76", + ] +} + +provider "registry.terraform.io/hashicorp/tfmigrate" { + version = "1.3.0-alpha20250930" + constraints = "1.3.0-alpha20250930" + hashes = [ + "h1:keaq0Ob4DVmFsAoFZQQeZX98FjxV9Xr9TWSLUarNZLE=", + "zh:31e34d42f31d69634b768a94d5d1f2750547d31a73019ce78195a75bf5bd83ca", + "zh:43a9a836520061099161314107ceb9939b1a671a49f45f998da770901700c69b", + "zh:56106b038b1a5cc8853be9d98151c6ff1e824385c1766e41041c31e9b78ce2c3", + "zh:58fd912b6f7f09e3126a1a4509070db4cd167eb984b1027bcc490173d6b63a38", + "zh:6ecca752e28c3ea315fd41e46f746a720a110f48a788d1584f89af9ed00301e5", + "zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f", + "zh:a36545b1f996899cf9af30871e3bcbd8041335861fccf92cee3609afa93a41e5", + "zh:ab3e475361aaa3c218f8fc0eeaee6001718fc82e3f148458049bb8ccc48b9f51", + "zh:b58e5eaff1d497589027c561372920b607d0c0fd20ce2404ad2801bfb431ad46", + "zh:c2ebeef25a93d45f9092a612e92b4fc0307fde561e712287b51269f4bf7ef43e", + "zh:ecc4608335319e255c96c366e95c09dcede7e18c8094720c9fd3f61cbcdc2bea", + "zh:f19a79da67f3ed2a768a39bfc099aec371c34439d5befd0cca40e8ee3cad5e87", + ] +} diff --git a/modularized_config/stacks_migration_infra/main.tf b/modularized_config/stacks_migration_infra/main.tf new file mode 100644 index 0000000..d7a8412 --- /dev/null +++ b/modularized_config/stacks_migration_infra/main.tf @@ -0,0 +1,36 @@ +terraform { + required_providers { + tfe = { + source = "hashicorp/tfe" + version = ">= 0.67.0" + } + tfmigrate = { + source = "hashicorp/tfmigrate" + version = "1.3.0-alpha20250930" + } + } +} + +provider "tfe" { + hostname = var.tfe_hostname + organization = var.organization_name +} + +resource "tfe_project" "stack_project" { + name = var.project_name + organization = var.organization_name +} + +resource "tfe_stack" "stack" { + name = var.stack_name + project_id = tfe_project.stack_project.id +} + +resource "tfmigrate_stack_migration" "stack_migration" { + config_file_dir = var.stacks_config_file_dir + organization = var.organization_name + name = tfe_stack.stack.name + project = tfe_project.stack_project.name + terraform_config_dir = var.terraform_config_dir + workspace_deployment_mapping = var.workspace_deployment_mapping +} \ No newline at end of file diff --git a/modularized_config/stacks_migration_infra/output.tf b/modularized_config/stacks_migration_infra/output.tf new file mode 100644 index 0000000..e0f6f15 --- /dev/null +++ b/modularized_config/stacks_migration_infra/output.tf @@ -0,0 +1,7 @@ +output "project_url" { + value = "https://app.terraform.io/app/${var.organization_name}/projects/${tfe_project.stack_project.id}" +} + +output "stack_url" { + value = "https://app.terraform.io/app/${var.organization_name}/projects/${tfe_project.stack_project.id}/stacks/${tfe_stack.stack.id}" +} \ No newline at end of file diff --git a/modularized_config/stacks_migration_infra/terraform.tfstate b/modularized_config/stacks_migration_infra/terraform.tfstate new file mode 100644 index 0000000..d942822 --- /dev/null +++ b/modularized_config/stacks_migration_infra/terraform.tfstate @@ -0,0 +1,99 @@ +{ + "version": 4, + "terraform_version": "1.13.2", + "serial": 4, + "lineage": "c498134f-dffe-06fc-d811-017756ca5022", + "outputs": { + "project_url": { + "value": "https://app.terraform.io/app/sujay-test-01/projects/prj-fFUMuaZmwfVoycRG", + "type": "string" + }, + "stack_url": { + "value": "https://app.terraform.io/app/sujay-test-01/projects/prj-fFUMuaZmwfVoycRG/stacks/st-GXsTx1G5mR95tEjD", + "type": "string" + } + }, + "resources": [ + { + "mode": "managed", + "type": "tfe_project", + "name": "stack_project", + "provider": "provider[\"registry.terraform.io/hashicorp/tfe\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "auto_destroy_activity_duration": null, + "description": "", + "id": "prj-fFUMuaZmwfVoycRG", + "ignore_additional_tags": null, + "name": "cli-migrated-stacks-project-01", + "organization": "sujay-test-01", + "tags": {} + }, + "sensitive_attributes": [], + "identity_schema_version": 0 + } + ] + }, + { + "mode": "managed", + "type": "tfe_stack", + "name": "stack", + "provider": "provider[\"registry.terraform.io/hashicorp/tfe\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "agent_pool_id": null, + "created_at": "2025-10-03T07:01:55Z", + "description": null, + "id": "st-GXsTx1G5mR95tEjD", + "name": "cli-migrated-stacks-01", + "project_id": "prj-fFUMuaZmwfVoycRG", + "updated_at": "2025-10-03T07:01:55Z", + "vcs_repo": null + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "tfe_project.stack_project" + ] + } + ] + }, + { + "mode": "managed", + "type": "tfmigrate_stack_migration", + "name": "stack_migration", + "provider": "provider[\"registry.terraform.io/hashicorp/tfmigrate\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "config_file_dir": "/Users/sujaysamanta/test-stack-temp/cli-driven-test-workspace-1/modularized_config/_stacks_generated", + "current_configuration_id": "stc-hUC579oz3Cme9U3E", + "current_configuration_status": "completed", + "migration_hash": "gbtjbGktZHJpdmVuLXRlc3Qtd29ya3NwYWNlLTGFq1dvcmtzcGFjZUlks3dzLURvc0tjaDVTc2JpYXZNWnGuRGVwbG95bWVudE5hbWW7Y2xpLWRyaXZlbi10ZXN0LXdvcmtzcGFjZS0xs0RlcGxveW1lbnRHcm91cERhdGGCoklktHNkZy1zcXJRcGZRaXAxS01vekxSplN0YXR1c6lzdWNjZWVkZWStRmFpbHVyZVJlYXNvbqCoV2FybmluZ3PA", + "name": "cli-migrated-stacks-01", + "organization": "sujay-test-01", + "project": "cli-migrated-stacks-project-01", + "source_bundle_hash": "f614b8c1e9b732c900671741ac6b24f4ad9834bfe2ae2a3819ed93fc0626673c", + "terraform_config_dir": "/Users/sujaysamanta/test-stack-temp/cli-driven-test-workspace-1/modularized_config", + "terraform_config_hash": "f614b8c1e9b732c900671741ac6b24f4ad9834bfe2ae2a3819ed93fc0626673c", + "workspace_deployment_mapping": { + "cli-driven-test-workspace-1": "cli-driven-test-workspace-1" + } + }, + "sensitive_attributes": [], + "identity_schema_version": 0, + "dependencies": [ + "tfe_project.stack_project", + "tfe_stack.stack" + ] + } + ] + } + ], + "check_results": null +} diff --git a/modularized_config/stacks_migration_infra/variables.tf b/modularized_config/stacks_migration_infra/variables.tf new file mode 100644 index 0000000..cc9b2a4 --- /dev/null +++ b/modularized_config/stacks_migration_infra/variables.tf @@ -0,0 +1,29 @@ +variable "organization_name" { + default = "sujay-test-01" +} + +variable "tfe_hostname" { + default = "app.terraform.io" +} + +variable "project_name" { + default = "cli-migrated-stacks-project-01" +} + +variable "stack_name" { + default = "cli-migrated-stacks-01" +} + +variable "stacks_config_file_dir" { + default = "/Users/sujaysamanta/test-stack-temp/cli-driven-test-workspace-1/modularized_config/_stacks_generated" +} + +variable "terraform_config_dir" { + default = "/Users/sujaysamanta/test-stack-temp/cli-driven-test-workspace-1/modularized_config" +} + +variable "workspace_deployment_mapping" { + default = { + cli-driven-test-workspace-1 = "cli-driven-test-workspace-1" + } +} diff --git a/modularized_config/terraform.tfvars b/modularized_config/terraform.tfvars new file mode 100644 index 0000000..6167d04 --- /dev/null +++ b/modularized_config/terraform.tfvars @@ -0,0 +1,7 @@ +bucket_name = "my-unique-bucket-name-12345-sujay-test-cli" # must be unique across AWS +environment = "dev" # must be either dev, int or prod + +tags = { # optional + "Project" = "cli-driven-test-workspace-1" + "Owner" = "terraform-test-lab" +} \ No newline at end of file diff --git a/modularized_config/terraform_modules/main.tf b/modularized_config/terraform_modules/main.tf new file mode 100644 index 0000000..6f0a10d --- /dev/null +++ b/modularized_config/terraform_modules/main.tf @@ -0,0 +1,69 @@ + +terraform { + required_version = ">= 1.0" + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } + + cloud { + organization = "sujay-test-01" + workspaces { + name = "cli-driven-test-workspace-1" + } + } +} + + +# Configure the AWS Provider +provider "aws" { + region = "ap-south-1" +} + + +# Create S3 bucket +resource "aws_s3_bucket" "main" { + bucket = var.bucket_name + + tags = merge( + var.tags, + { + Environment = var.environment + ManagedBy = "Terraform" + } + ) +} + + +# Configure S3 bucket versioning +resource "aws_s3_bucket_versioning" "main" { + bucket = aws_s3_bucket.main.id + versioning_configuration { + status = "Enabled" + } +} + + +# Configure S3 bucket server-side encryption +resource "aws_s3_bucket_server_side_encryption_configuration" "main" { + bucket = aws_s3_bucket.main.id + + rule { + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } +} + + +# Block public access to the S3 bucket +resource "aws_s3_bucket_public_access_block" "main" { + bucket = aws_s3_bucket.main.id + + block_public_acls = true + block_public_policy = true + ignore_public_acls = true + restrict_public_buckets = true +} diff --git a/modularized_config/terraform_modules/outputs.tf b/modularized_config/terraform_modules/outputs.tf new file mode 100644 index 0000000..5f428ea --- /dev/null +++ b/modularized_config/terraform_modules/outputs.tf @@ -0,0 +1,9 @@ +output "bucket_name" { + description = "Name of the created S3 bucket" + value = aws_s3_bucket.main.bucket +} + +output "bucket_arn" { + description = "ARN of the created S3 bucket" + value = aws_s3_bucket.main.arn +} \ No newline at end of file diff --git a/modularized_config/terraform_modules/variables.tf b/modularized_config/terraform_modules/variables.tf new file mode 100644 index 0000000..379974b --- /dev/null +++ b/modularized_config/terraform_modules/variables.tf @@ -0,0 +1,16 @@ +variable "bucket_name" { + description = "Name of the S3 bucket" + type = string +} + +variable "environment" { + description = "Environment name (e.g., dev, staging, prod)" + type = string + default = "dev" +} + +variable "tags" { + description = "Additional tags to apply to the S3 bucket" + type = map(string) + default = {} +} \ No newline at end of file diff --git a/modularized_config/variables.tf b/modularized_config/variables.tf new file mode 100644 index 0000000..4a2f93c --- /dev/null +++ b/modularized_config/variables.tf @@ -0,0 +1,16 @@ +variable "environment" { + description = "Environment name (e.g., dev, staging, prod)" + type = string + default = "dev" +} + +variable "tags" { + description = "Additional tags to apply to the S3 bucket" + type = map(string) + default = {} +} +variable "bucket_name" { + description = "Name of the S3 bucket" + type = string +} +