Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions 03-terraform-outputs-across-stacks/backend.tm.hcl
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
globals {
aws_region = "us-west-2"
name = "terramate-example-data-sharing"
state_bucket = "CHANGE-THIS"
aws_region = "us-west-2"
name = "terramate-example-data-sharing"
state_bucket = {
key_fmt = "state-files/stacks/%s/terraform.state"
name = "CHANGE-THIS"
}
}

# generates the backend.tf in each stack
generate_hcl "_backend.tf" {
generate_hcl "_terramate_generated_backend.tf" {
content {
terraform {
backend "s3" {
bucket = global.state_bucket
key = "state-files/stacks/${terramate.stack.id}/terraform.state"
bucket = global.state_bucket.name
key = tm_format(global.state_bucket.key_fmt, terramate.stack.id)
region = global.aws_region
encrypt = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
generate_hcl "_remote-state.tf" {
generate_hcl "_terramate_generated_remote_state.tf" {
content {
data "terraform_remote_state" "vpc" {
backend = "s3"
config = {
bucket = global.state_bucket
bucket = global.state_bucket.name
region = global.aws_region
encrypt = true
# The key here uses the stack ID of the VPC stack
key = "state-files/stacks/c2c67b6a-5cc5-4129-b684-f471548781d5/terraform.state"
key = tm_format(global.state_bucket.key_fmt, "c2c67b6a-5cc5-4129-b684-f471548781d5")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ stack {
name = "ec2"
description = "ec2"
id = "fd944951-2497-4a75-a93c-f486975c3777"
after = ["tag:vpc"]
after = ["../vpc"]
wanted_by = ["../vpc"]
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"

tags = {
Name = global.name
Name = "terramate-example-data-sharing"
}
}

resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"

tags = {
Name = global.name
Name = "terramate-example-data-sharing"
}
vpc_id = aws_vpc.main.id
}

output "subnet_id" {
value = aws_subnet.main.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
generate_hcl "_terramate_generated_vpc_and_subnet.tf" {
content {
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"

tags = {
Name = global.name
}
}

resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"

tags = {
Name = global.name
}
}

output "subnet_id" {
value = aws_subnet.main.id
}
}
}