diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2326b55..619d2d4 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -43,6 +43,11 @@ jobs: asdf plugin add opentofu asdf install opentofu + - name: Use branch terramate + run: | + GOBIN=/tmp go install github.com/terramate-io/terramate/cmd/terramate@i4k-sharing-orchestrate2 + cp -v /tmp/terramate /usr/local/bin/terramate-bin + ### Linting - name: Check Terramate formatting @@ -89,12 +94,18 @@ jobs: - name: Plan Terraform changes in changed stacks if: steps.list-changed.outputs.stdout run: | - terramate script run \ - -C stacks \ + terramate run \ + -C stacks/terraform \ + --changed \ + bash -c 'terraform init; terraform validate' + + terramate run \ + -C stacks/terraform \ --changed \ --parallel 5 \ - --continue-on-error \ + --cloud-sync-preview \ + --terraform-plan-file=out.tfplan -- \ - preview + terraform plan -out=out.tfplan -detailed-exitcode -lock=false env: GITHUB_TOKEN: ${{ github.token }} diff --git a/stacks/terraform/sharing_backend.tm b/stacks/terraform/sharing_backend.tm new file mode 100644 index 0000000..6ac53ab --- /dev/null +++ b/stacks/terraform/sharing_backend.tm @@ -0,0 +1,5 @@ +sharing_backend "terraform" { + type = terraform + command = ["terraform", "output", "-json"] + filename = "sharing.tf" +} diff --git a/stacks/terraform/use-vpc-output-example/backend.tf b/stacks/terraform/use-vpc-output-example/backend.tf new file mode 100644 index 0000000..b054ee6 --- /dev/null +++ b/stacks/terraform/use-vpc-output-example/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "s3" { + bucket = "terramate-example-terraform-state-backend" + dynamodb_table = "terraform-lock" + encrypt = true + key = "terraform/stacks/by-id/e4e5d4fb-c62a-46f1-8242-89b9ce765c15/terraform.tfstate" + region = "us-east-1" + } +} diff --git a/stacks/terraform/use-vpc-output-example/inputs.tm b/stacks/terraform/use-vpc-output-example/inputs.tm new file mode 100644 index 0000000..443b2ee --- /dev/null +++ b/stacks/terraform/use-vpc-output-example/inputs.tm @@ -0,0 +1,6 @@ +input "vpc_id" { + backend = "terraform" + value = outputs.vpc_id.value + mock = "mocked" + from_stack_id = "1902bc6d-b192-450c-9d96-dfe4ce16192a" +} diff --git a/stacks/terraform/use-vpc-output-example/sharing.tf b/stacks/terraform/use-vpc-output-example/sharing.tf new file mode 100644 index 0000000..3823122 --- /dev/null +++ b/stacks/terraform/use-vpc-output-example/sharing.tf @@ -0,0 +1,3 @@ +variable "vpc_id" { + type = string +} diff --git a/stacks/terraform/use-vpc-output-example/stack.tm.hcl b/stacks/terraform/use-vpc-output-example/stack.tm.hcl new file mode 100644 index 0000000..ff187e6 --- /dev/null +++ b/stacks/terraform/use-vpc-output-example/stack.tm.hcl @@ -0,0 +1,8 @@ +stack { + name = "use-vpc-output-example" + description = "use-vpc-output-example" + id = "e4e5d4fb-c62a-46f1-8242-89b9ce765c15" + after = [ + "/stacks/terraform/vpc" + ] +} diff --git a/stacks/terraform/use-vpc-output-example/terraform.tf b/stacks/terraform/use-vpc-output-example/terraform.tf new file mode 100644 index 0000000..30661b6 --- /dev/null +++ b/stacks/terraform/use-vpc-output-example/terraform.tf @@ -0,0 +1,16 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + required_version = "1.8.5" +} +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.48" + } + } +} +provider "aws" { + region = "us-east-1" +} diff --git a/stacks/terraform/vpc/main.tf b/stacks/terraform/vpc/main.tf index e69de29..9a7d8f0 100644 --- a/stacks/terraform/vpc/main.tf +++ b/stacks/terraform/vpc/main.tf @@ -0,0 +1,19 @@ +module "vpc" { + source = "terraform-aws-modules/vpc/aws" + + name = "demo-vpc" + cidr = "20.0.0.0/16" + + azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"] + private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] + public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] + + enable_nat_gateway = false + enable_vpn_gateway = false + + tags = { + Terraform = "true" + Environment = "dev" + } +} + diff --git a/stacks/terraform/vpc/outputs.tm b/stacks/terraform/vpc/outputs.tm new file mode 100644 index 0000000..d4eb1de --- /dev/null +++ b/stacks/terraform/vpc/outputs.tm @@ -0,0 +1,5 @@ +output "vpc_id" { + backend = "terraform" + value = module.vpc.vpc_id + sensitive = false +} diff --git a/stacks/terraform/vpc/sharing.tf b/stacks/terraform/vpc/sharing.tf new file mode 100644 index 0000000..a2f1bdf --- /dev/null +++ b/stacks/terraform/vpc/sharing.tf @@ -0,0 +1,3 @@ +output "vpc_id" { + value = module.vpc.vpc_id +} diff --git a/terramate.tm.hcl b/terramate.tm.hcl index 1576f3d..39e2947 100644 --- a/terramate.tm.hcl +++ b/terramate.tm.hcl @@ -31,6 +31,7 @@ terramate { # Enable Terramate Scripts experiments = [ "scripts", + "sharing-is-caring", ] } }