Skip to content

Commit

Permalink
feat: updating workflows (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnuCode authored May 17, 2024
2 parents ec9ea67 + a4bbecd commit 8ee146e
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 84 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
-C stacks \
--parallel 1 \
--changed \
terraform init
init
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -83,7 +83,7 @@ jobs:
-C stacks \
--parallel 5 \
--changed \
terraform deploy
deploy
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -98,7 +98,7 @@ jobs:
-C stacks \
--parallel 5 \
--changed \
terraform drift detect
drift detect
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/drift-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
terramate script run \
-C stacks \
--parallel 1 \
terraform init
init
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -79,7 +79,7 @@ jobs:
--parallel 5 \
--continue-on-error \
-- \
terraform drift detect
drift detect
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -93,11 +93,11 @@ jobs:
terramate script run \
-C stacks \
--tags reconcile \
--cloud-status=drifted \
--status=drifted \
--parallel 5 \
--continue-on-error \
-- \
terraform drift reconcile
drift reconcile
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
-C stacks \
--changed \
--parallel 1 \
terraform init
init
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -106,7 +106,7 @@ jobs:
--parallel 5 \
--continue-on-error \
-- \
terraform preview
preview
env:
GITHUB_TOKEN: ${{ github.token }}
ARM_USE_OIDC: true
Expand All @@ -133,7 +133,7 @@ jobs:
echo >>pr-comment.txt "#### Terraform Plan"
echo >>pr-comment.txt
echo >>pr-comment.txt '```terraform'
terramate run -C stacks --changed -- terraform show -no-color preview.tfplan |& dd bs=1024 count=248 >>pr-comment.txt
terramate script run --changed -- terraform render | dd bs=1024 count=248 >>pr-comment.txt
[ "${PIPESTATUS[0]}" == "141" ] && sed -i 's/#### Terraform Plan/#### :warning: Terraform Plan truncated: please check console output :warning:/' pr-comment.txt
echo >>pr-comment.txt '```'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
Expand Down
4 changes: 0 additions & 4 deletions imports.tm.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
source = "./imports/*.tm.hcl"
}

import {
source = "./workflows/*.tm.hcl"
}
83 changes: 83 additions & 0 deletions workflows.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
script "init" {
name = "Terraform Init"
description = "Download the required provider plugins and modules and set up the backend"

job {
commands = [
["terraform", "init", "-lock-timeout=5m"],
]
}
}

script "preview" {
name = "Terraform Deployment Preview"
description = "Create a preview of Terraform changes and synchronize it to Terramate Cloud"

job {
commands = [
["terraform", "validate"],
["terraform", "plan", "-out", "out.tfplan", "-detailed-exitcode", "-lock=false", {
sync_preview = true
terraform_plan_file = "out.tfplan"
}],
]
}
}

script "terraform" "render" {
name = "Terraform Show Plan"
description = "Render a Terraform plan"

job {
commands = [
["echo", "Stack: `${terramate.stack.path.absolute}`"],
["echo", "```terraform"],
["terraform", "show", "-no-color", "out.tfplan"],
["echo", "```"],
]
}
}

script "deploy" {
name = "Terraform Deployment"
description = "Run a full Terraform deployment cycle and synchronize the result to Terramate Cloud"

job {
commands = [
["terraform", "validate"],
["terraform", "plan", "-out", "out.tfplan", "-lock=false"],
["terraform", "apply", "-input=false", "-auto-approve", "-lock-timeout=5m", "out.tfplan", {
sync_deployment = true
terraform_plan_file = "out.tfplan"
}],
]
}
}

script "drift" "detect" {
name = "Terraform Drift Check"
description = "Detect drifts in Terraform configuration and synchronize it to Terramate Cloud"

job {
commands = [
["terraform", "plan", "-out", "out.tfplan", "-detailed-exitcode", "-lock=false", {
sync_drift_status = true
terraform_plan_file = "out.tfplan"
}],
]
}
}

script "drift" "reconcile" {
name = "Terraform Drift Reconciliation"
description = "Reconcile drifts in all changed stacks"

job {
commands = [
["terraform", "apply", "-input=false", "-auto-approve", "-lock-timeout=5m", "drift.tfplan", {
sync_deployment = true
terraform_plan_file = "drift.tfplan"
}],
]
}
}
10 changes: 0 additions & 10 deletions workflows/script.terraform_init.tm.hcl

This file was deleted.

17 changes: 0 additions & 17 deletions workflows/script_terraform_deploy.tm.hcl

This file was deleted.

27 changes: 0 additions & 27 deletions workflows/script_terraform_detect_drift.tm.hcl

This file was deleted.

16 changes: 0 additions & 16 deletions workflows/script_terraform_preview.tm.hcl

This file was deleted.

0 comments on commit 8ee146e

Please sign in to comment.