Skip to content

Commit 4759f46

Browse files
fix: dynamodb terraform lock table (#101)
2 parents 518e11b + 5829014 commit 4759f46

File tree

9 files changed

+27
-23
lines changed

9 files changed

+27
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ jobs:
6565
if: steps.list.outputs.stdout
6666
id: init
6767
run: |
68-
terramate run --changed -- terraform init
68+
terramate run -C stacks --changed -- terraform init
6969
7070
- name: Create Terraform plan on changed stacks
7171
if: steps.list.outputs.stdout
7272
id: plan
73-
run: terramate run --changed -- terraform plan -lock-timeout=5m -out out.tfplan
73+
run: terramate run -C stacks --changed -- terraform plan -lock-timeout=5m -out out.tfplan
7474

7575
- name: Apply planned changes on changed stacks
7676
id: apply
7777
if: steps.list.outputs.stdout
78-
run: terramate run --changed --cloud-sync-deployment --cloud-sync-terraform-plan-file=out.tfplan -- terraform apply -input=false -auto-approve -lock-timeout=5m out.tfplan
78+
run: terramate run -C stacks --changed --cloud-sync-deployment --cloud-sync-terraform-plan-file=out.tfplan -- terraform apply -input=false -auto-approve -lock-timeout=5m out.tfplan
7979
env:
8080
GITHUB_TOKEN: ${{ github.token }}
8181

8282
- name: Run drift detection
8383
if: steps.list.outputs.stdout && ! cancelled() && steps.apply.outcome != 'skipped'
84-
run: terramate run --changed --cloud-sync-drift-status --cloud-sync-terraform-plan-file=drift.tfplan -- terraform plan -out drift.tfplan -detailed-exitcode
84+
run: terramate run -C stacks --changed --cloud-sync-drift-status --cloud-sync-terraform-plan-file=drift.tfplan -- terraform plan -out drift.tfplan -detailed-exitcode
8585
env:
8686
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/drift-detection.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ jobs:
5656

5757
- name: Run Terraform init on all stacks
5858
id: init
59-
run: terramate run -- terraform init
59+
run: terramate run -C stacks -- terraform init
6060

6161
- name: Run drift detection
6262
id: drift
63-
run: terramate run --cloud-sync-drift-status --cloud-sync-terraform-plan-file=drift.tfplan --continue-on-error -- terraform plan -out drift.tfplan -detailed-exitcode -lock=false
63+
run: terramate run -C stacks --cloud-sync-drift-status --cloud-sync-terraform-plan-file=drift.tfplan --continue-on-error -- terraform plan -out drift.tfplan -detailed-exitcode -lock=false
6464
env:
6565
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/preview.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ jobs:
8787

8888
- name: Initialize Terraform in changed stacks
8989
if: steps.list.outputs.stdout
90-
run: terramate run --parallel 1 --changed -- terraform init -lock-timeout=5m
90+
run: terramate run -C stacks --parallel 1 --changed -- terraform init -lock-timeout=5m
9191

9292
- name: Validate Terraform configuration in changed stacks
9393
if: steps.list.outputs.stdout
94-
run: terramate run --parallel 5 --changed -- terraform validate
94+
run: terramate run -C stacks --parallel 5 --changed -- terraform validate
9595

9696
- name: Plan Terraform changes in changed stacks
9797
if: steps.list.outputs.stdout
9898
run: |
99-
terramate run --parallel 5 --changed --cloud-sync-preview --cloud-sync-terraform-plan-file=out.tfplan --debug-preview-url preview_url.txt --continue-on-error -- terraform plan -out out.tfplan -detailed-exitcode -lock=false
99+
terramate run -C stacks --parallel 5 --changed --cloud-sync-preview --cloud-sync-terraform-plan-file=out.tfplan --debug-preview-url preview_url.txt --continue-on-error -- terraform plan -out out.tfplan -detailed-exitcode -lock=false
100100
env:
101101
GITHUB_TOKEN: ${{ github.token }}
102102

@@ -119,7 +119,7 @@ jobs:
119119
echo >>pr-comment.txt "#### Terraform Plan"
120120
echo >>pr-comment.txt
121121
echo >>pr-comment.txt '```terraform'
122-
terramate run --changed -- terraform show -no-color out.tfplan |& dd bs=1024 count=248 >>pr-comment.txt
122+
terramate run -C stacks --changed -- terraform show -no-color out.tfplan |& dd bs=1024 count=248 >>pr-comment.txt
123123
[ "${PIPESTATUS[0]}" == "141" ] && sed -i 's/#### Terraform Plan/#### :warning: Terraform Plan truncated: please check console output :warning:/' pr-comment.txt
124124
echo >>pr-comment.txt '```'
125125
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY

_bootstrap/oidc-aws-github/stack.tm.hcl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ stack {
22
name = "oidc-aws-github"
33
description = "Configure GitHub Actions as an IAM OIDC identity provider in AWS."
44
id = "7d22b8e6-0e02-4815-995b-1cd34c826c95"
5-
6-
tags = ["no-backend"]
5+
tags = ["no-backend"]
76
}

_bootstrap/terraform-state-bucket/_main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "state-bucket" {
2828
}
2929
resource "aws_dynamodb_table" "terraform-lock" {
3030
hash_key = "LockID"
31-
name = "terraform_state"
31+
name = "terraform-lock"
3232
read_capacity = 5
3333
tags = {
3434
"Name" = "DynamoDB Terraform State Lock Table"

_bootstrap/terraform-state-bucket/config.tm.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ generate_hcl "_main.tf" {
3535
}
3636

3737
resource "aws_dynamodb_table" "terraform-lock" {
38-
name = "terraform_state"
38+
name = tm_try(global.terraform.backend.dyanmodb_table, "terraform_state")
3939
read_capacity = 5
4040
write_capacity = 5
4141
hash_key = "LockID"

config.tm.hcl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ globals "terraform" {
33
}
44

55
globals "terraform" "backend" {
6-
bucket = "terramate-example-terraform-state-backend"
7-
region = "us-east-1"
6+
bucket = "terramate-example-terraform-state-backend"
7+
dyanmodb_table = "terraform-lock"
8+
region = "us-east-1"
89
}
910

1011
globals "aws" "oidc" {

imports/backend.tm.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ generate_hcl "_backend.tf" {
88
bucket = global.terraform.backend.bucket
99
key = "terraform/stacks/by-id/${terramate.stack.id}/terraform.tfstate"
1010
encrypt = true
11-
dynamodb_table = tm_try(global.terraform.backend.dynamo_table, "terraform-lock")
11+
dynamodb_table = tm_try(global.terraform.backend.dyanmodb_table, "terraform-lock")
1212
}
1313
}
1414
}

terramate.tm.hcl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
terramate {
22
config {
3-
experiments = [
4-
"scripts", # Enable Terramate Scripts
5-
]
63

4+
# Configure the namespace of your Terramate Cloud organization
75
cloud {
86
organization = "terramate-demo"
97
}
@@ -14,18 +12,24 @@ terramate {
1412

1513
# Optionally disable git safe guards
1614
# Learn more: https://terramate.io/docs/cli/orchestration/safeguards
17-
check_remote = false
18-
check_untracked = false
19-
check_uncommitted = false
15+
# check_remote = false
16+
# check_untracked = false
17+
# check_uncommitted = false
2018
}
2119

2220
run {
2321
env {
2422
TF_PLUGIN_CACHE_DIR = "${terramate.root.path.fs.absolute}/.tf_plugin_cache_dir"
2523
}
24+
2625
# Optionally disable code generation safe guard
2726
# Learn more: https://terramate.io/docs/cli/orchestration/safeguards
2827
# check_gen_code = true
2928
}
29+
30+
# Enable Terramate Scripts
31+
experiments = [
32+
"scripts",
33+
]
3034
}
3135
}

0 commit comments

Comments
 (0)