diff --git a/.gitignore b/.gitignore index 00d8475..355b81e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,9 +12,9 @@ override.tfvars.json *.tfvars !vcs.auto.tfvars !terraform.tfvars -_stacks_generated -stacks_migration_infra -stacks-config +# _stacks_generated +# stacks_migration_infra +# stacks-config # Terraform plan outputs *.tfplan diff --git a/_stacks_generated/.terraform-version b/_stacks_generated/.terraform-version new file mode 100755 index 0000000..d0e60d6 --- /dev/null +++ b/_stacks_generated/.terraform-version @@ -0,0 +1 @@ +1.13.5 \ No newline at end of file diff --git a/_stacks_generated/.terraform.lock.hcl b/_stacks_generated/.terraform.lock.hcl new file mode 100755 index 0000000..c46c967 --- /dev/null +++ b/_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 = "6.26.0" + hashes = [ + "h1:79RHpchB+IjuZLMNkbCSjkguoAOUsSWnr0N6Bei+PxI=", + "h1:B7X8EU6aZ9KzIvP0VBDhhgadgjXIrUgMXt/pJ6EUXvo=", + "h1:bq6gvZehoO4jBx/MsjIyMFHU56DX+TP7ndl34o3Fncs=", + "zh:038fd943de79acd9f9f73106fa0eba588c6a0d4e0993e146f51f3aa043728c5f", + "zh:06fa0177d33d3d3f9cb7e205fbeb1c4c3095ba637e2b4d292429401ec5612e81", + "zh:212714fc8b6ee57e26d11d0fdf2ecfe23b37a6eac1008b399c1d790528c3f072", + "zh:3197725d772f360e9e466b68a5ba67363e9f6786809c9adefc50f7f7e525bf42", + "zh:33385539f3e3fafb96c6036421fd72b05c76505eeefaaff8a089c3eeba25db65", + "zh:4ce065e0d3c384d11c1b59fe92582d331aae27ff6e019ace07b8cedef5653aae", + "zh:67863d6ff5517db2c0b8097443708dca548f1922d2e08ad76a98d493ff480cb1", + "zh:771ccf61fc107013b437b0a05cdb342823a99200653bfe9b892702b9fd8997fe", + "zh:80adcf83bef9d683606c48bbe53cbb2b5a04878641674e957939b5e8f124ada0", + "zh:9675c7f209db8e64ba2d5197acc8ba0073bd73b48c3dd61a1961a44844bc8a81", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b47d0f5eff91c94c5d5677815b9361e64dfbe2ee2d59ba2867e2d0f5fa7181e4", + "zh:b4933663b8d6cc1cfb51aa47bd8f26c06012ee2e278e57663faffdc722dd5baa", + "zh:d53a94ecdb6b68a8dc19ec6e16ba2d4c2acde575af254d1b8b80143e57c76abf", + "zh:e7cb8c1770c6f87c5ce1d3e28b838380bb8e5296dd03034b796168de8be1c7ec", + ] +} diff --git a/_stacks_generated/components.tfcomponent.hcl b/_stacks_generated/components.tfcomponent.hcl new file mode 100755 index 0000000..6f95134 --- /dev/null +++ b/_stacks_generated/components.tfcomponent.hcl @@ -0,0 +1,28 @@ +# Generated by tf-migrate 2.0.0-beta1 + + +component "ec2_instance" { + source = "terraform-aws-modules/ec2-instance/aws" + + inputs = { + "ami" = var.ami_id + "instance_type" = var.instance_type + "monitoring" = true + "name" = var.instance_name + "subnet_id" = "subnet-04ac8df91e75657c9" + "tags" = { + Terraform = "true" + Environment = "dev" + } + "vpc_security_group_ids" = [] + } + + version = "~> 6.0" + + + providers = { + aws = provider.aws.this + } +} + + diff --git a/_stacks_generated/deployment.tfdeploy.hcl b/_stacks_generated/deployment.tfdeploy.hcl new file mode 100755 index 0000000..68f5375 --- /dev/null +++ b/_stacks_generated/deployment.tfdeploy.hcl @@ -0,0 +1,39 @@ +# Generated by tf-migrate 2.0.0-beta1 + + + +# 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 "dev-workspace" { + 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 + instance_name = "stack-v3-test-prod-instance" + instance_type = "t3.micro" + ami_id = "ami-0dee22c13ea7a9a67" + } + import = true +} + + + +# deployment "prod-workspace" { +# inputs = { +# instance_name = "stack-v3-test-prod-instance" +# instance_type = "t3.micro" +# ami_id = "ami-0dee22c13ea7a9a67" +# } +# import = true +# } + + + diff --git a/_stacks_generated/outputs.tfcomponent.hcl b/_stacks_generated/outputs.tfcomponent.hcl new file mode 100755 index 0000000..07f7503 --- /dev/null +++ b/_stacks_generated/outputs.tfcomponent.hcl @@ -0,0 +1,15 @@ +# Generated by tf-migrate 2.0.0-beta1 + + +output "instance_id" { + description = "The ID of the EC2 instance" + value = component.ec2_instance.id + type = string +} + +output "instance_public_ip" { + description = "The public IP address of the EC2 instance" + value = component.ec2_instance.public_ip + type = string +} + diff --git a/_stacks_generated/providers.tfcomponent.hcl b/_stacks_generated/providers.tfcomponent.hcl new file mode 100755 index 0000000..0a12a47 --- /dev/null +++ b/_stacks_generated/providers.tfcomponent.hcl @@ -0,0 +1,18 @@ +# Generated by tf-migrate 2.0.0-beta1 + + +provider "aws" "this" { + config { + region = "ap-south-1" + access_key = var.access_key + secret_key = var.secret_key + token = var.session_token + } +} + +required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.66.0, >= 5.0.0" + } +} diff --git a/_stacks_generated/variables.tfcomponent.hcl b/_stacks_generated/variables.tfcomponent.hcl new file mode 100755 index 0000000..0a3f4f2 --- /dev/null +++ b/_stacks_generated/variables.tfcomponent.hcl @@ -0,0 +1,41 @@ +# Generated by tf-migrate 2.0.0-beta1 + + +variable "instance_name" { + description = "Name to be used on all resources as prefix" + type = string + default = "example-instance" +} + +variable "instance_type" { + description = "The type of instance to start" + type = string + default = "t3.micro" +} + +variable "ami_id" { + description = "ID of AMI to use for the instance" + type = string + default = "ami-0dee22c13ea7a9a67" # Amazon Linux 2023 AMI in ap-south-1 (verify this if needed, but using a placeholder/common one is usually okay for templates) +} + +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 +} + diff --git a/stacks_migration_infra/.terraform.lock.hcl b/stacks_migration_infra/.terraform.lock.hcl new file mode 100644 index 0000000..2795e4f --- /dev/null +++ b/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.72.0" + constraints = ">= 0.67.0" + hashes = [ + "h1:DSx+rdyWBkDyBcollXYzGehREnCvwe5dyNT+gK0S0YQ=", + "zh:0c5a72feab8b911d8ecd618aa875e59693f7ba18d01cac2938693d15d9a3de88", + "zh:2e902f3f26d76f856767c7033de01de94f2128779602eec530ff7b03775ff379", + "zh:4489a949eb07bc606947ae8fedc2e681d12db1ea63915f88698cb2e594fca478", + "zh:541d4532c875b2ee7ecb98da9a1461e76788893b623b0adf7c634d9fff7770e3", + "zh:78db652be0568fafc326e995e3eff153381a0d3abf1ecf96347f1bdf65a2e881", + "zh:89f71cbc5ee52afd5e98bf4603d3f2528bb6272cfb77f0215d9c5ffab3c06d6a", + "zh:a6bd22d4425b425a97cffbb85eddafb9c958ed15d4b95146a0c6da15d97bf098", + "zh:a72507ca718c3040845f14e7f3e72a8fe3fc8b581edcdfc301305e0087b19991", + "zh:a8eb3261495366e739e155d9b65864d88387c409552ccf82e50b9553a3a4ab89", + "zh:aab6de3906be0f112b3ed04179624cd34200b258517f9fad1830af97ac4ef708", + "zh:e194e5d053bd95bbf57dc6ab326850c36ad3938573ba4281b5e465a7ffafb7ab", + "zh:f603f1e884c8a194ea762526f2e462d22599d02fe12cb83ab0c030369be4bd4e", + ] +} + +provider "registry.terraform.io/hashicorp/tfmigrate" { + version = "2.0.0-beta1" + constraints = "2.0.0-beta1" + hashes = [ + "h1:mKHG4z8k+qLDkP+MpPdXu8THvgs2l4/NzxWHBBOR+Zs=", + "zh:1c2433b959b06ed4d1ee77bd41e15c43af6c3eb06a1117b061b152faeb189c0c", + "zh:3ddd5866281772c7c6ed1afbbedbe19646aff7630155b783dc7e553788a5fad0", + "zh:46ee906b17321ba58bcba267acdacf141cec6173d9da16fbe12e4e6299586ea5", + "zh:864d0b62faec50e435e0b410bde3d60e8bede42929ea34f9156ba5545c6f8ebe", + "zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f", + "zh:8ab21f0c9014493c3d3676e87b90558aee1a50b48235820a5eb5f537b73bb0e0", + "zh:925cacc6649881255a64faef44a30a525762592de8de321cea24d0374e972ac9", + "zh:9e6b69a03b46881c290965187b471f463467e74101c0caa0b2a26c243fa728a7", + "zh:9fee5bf7e51705a4dc5631d38d1642582845673d61285195358ee2349dd194d1", + "zh:c27ae5372c7b96d0eb42ef63c3377be92b89239553a611ea94a3d3656dc65a8c", + "zh:d26605feea4eb31ef7fec832095d449b0249b8e0bf556fab275e5edf6ed38568", + "zh:e28ab6f7754a0ae63844ed336ccffd6390a722a196260bf595b66c931a5a4549", + ] +} diff --git a/stacks_migration_infra/main.tf b/stacks_migration_infra/main.tf new file mode 100644 index 0000000..576b11d --- /dev/null +++ b/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 = "2.0.0-beta1" + } + } +} + +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/stacks_migration_infra/output.tf b/stacks_migration_infra/output.tf new file mode 100644 index 0000000..e0f6f15 --- /dev/null +++ b/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/stacks_migration_infra/variables.tf b/stacks_migration_infra/variables.tf new file mode 100644 index 0000000..68afb03 --- /dev/null +++ b/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 = "stack-retry-v2" +} + +variable "stack_name" { + default = "stack-retry-test-v2" +} + +variable "stacks_config_file_dir" { + default = "/Users/sujaysamanta/Workspace/Cursor-AI/terraform-stacks-migration-test/stack-terraform-test-v3/_stacks_generated" +} + +variable "terraform_config_dir" { + default = "/Users/sujaysamanta/Workspace/Cursor-AI/terraform-stacks-migration-test/stack-terraform-test-v3" +} + +variable "workspace_deployment_mapping" { + default = { + dev-workspace = "dev-workspace" + } +}