Skip to content

Commit

Permalink
test: example of Terramate Sharing Outputs.
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <t.nateldemoura@gmail.com>
  • Loading branch information
i4ki committed Aug 7, 2024
1 parent 0183939 commit 1499c57
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 7 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,20 @@ 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 \
--enable-sharing \
--mock-on-fail \
-- \
preview
terraform plan -out=out.tfplan -detailed-exitcode -lock=false
env:
GITHUB_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ pr-comment.txt
.tf_plugin_cache_dir

preview_url.txt
stacks/terraform/use-vpc-output-example/vpc_id.txt
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
terraform 1.8.5
terramate 0.9.0
terramate 0.10.1-rc1
pre-commit 3.6.2
opentofu 1.7.2
5 changes: 5 additions & 0 deletions stacks/terraform/sharing_backend.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sharing_backend "terraform" {
type = terraform
command = ["terraform", "output", "-json"]
filename = "sharing.tf"
}
11 changes: 11 additions & 0 deletions stacks/terraform/use-vpc-output-example/backend.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 6 additions & 0 deletions stacks/terraform/use-vpc-output-example/inputs.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
input "vpc_id" {
backend = "terraform"
value = outputs.vpc_id.value
mock = "mocked"
from_stack_id = "1902bc6d-b192-450c-9d96-dfe4ce16192a"
}
6 changes: 6 additions & 0 deletions stacks/terraform/use-vpc-output-example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "local_file" "vpc_id" {
content = var.vpc_id
filename = "${path.module}/vpc_id.txt"
file_permission = 0777
directory_permission = 0777
}
5 changes: 5 additions & 0 deletions stacks/terraform/use-vpc-output-example/sharing.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

variable "vpc_id" {
type = string
}
8 changes: 8 additions & 0 deletions stacks/terraform/use-vpc-output-example/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -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"
]
}
16 changes: 16 additions & 0 deletions stacks/terraform/use-vpc-output-example/terraform.tf
Original file line number Diff line number Diff line change
@@ -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"
}
19 changes: 19 additions & 0 deletions stacks/terraform/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}

5 changes: 5 additions & 0 deletions stacks/terraform/vpc/outputs.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "vpc_id" {
backend = "terraform"
value = module.vpc.vpc_id
sensitive = false
}
5 changes: 5 additions & 0 deletions stacks/terraform/vpc/sharing.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

output "vpc_id" {
value = module.vpc.vpc_id
}
5 changes: 3 additions & 2 deletions terramate.tm.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
terramate {
required_version = ">= 0.9.0"
# required_version_allow_prereleases = true
required_version = ">= 0.9.0"
required_version_allow_prereleases = true
config {

# Optionally disable safe guards
Expand Down Expand Up @@ -31,6 +31,7 @@ terramate {
# Enable Terramate Scripts
experiments = [
"scripts",
"sharing-is-caring",
]
}
}

0 comments on commit 1499c57

Please sign in to comment.