Integrate with actions (#1)
Co-authored-by: Ben Martin <ben.martin@sky.uk> Reviewed-on: #1
This commit is contained in:
parent
d4335ca10e
commit
cba0f1cfd4
6 changed files with 109 additions and 18 deletions
|
@ -1,21 +1,23 @@
|
||||||
name: Deploy
|
name: Terraform Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_run:
|
||||||
|
workflows: ["Terraform Plan"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
TF_IN_AUTOMATION: true
|
||||||
|
TF_CLI_ARGS: "-no-color"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
plan:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: hashicorp/setup-terraform@v3
|
||||||
- name: Terraform Init
|
- name: Terraform apply
|
||||||
run: |
|
id: apply
|
||||||
terraform init -input=false
|
run: terraform apply -auto-approve tfplan
|
||||||
- name: Terraform Plan
|
|
||||||
run: |
|
|
||||||
terraform plan -out=tfplan -input=false
|
|
||||||
- name: Terraform Apply
|
|
||||||
run: |
|
|
||||||
terraform apply -input=false tfplan
|
|
||||||
|
|
89
.gitea/workflows/plan.yaml
Normal file
89
.gitea/workflows/plan.yaml
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
name: Terraform Plan
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
TF_IN_AUTOMATION: true
|
||||||
|
TF_CLI_ARGS: "-no-color"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
plan:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: hashicorp/setup-terraform@v3
|
||||||
|
- name: Terraform fmt
|
||||||
|
id: fmt
|
||||||
|
run: terraform fmt -check
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Terraform Init
|
||||||
|
id: init
|
||||||
|
run: terraform init -input=false
|
||||||
|
- name: Terraform Validate
|
||||||
|
id: validate
|
||||||
|
run: terraform validate
|
||||||
|
- name: Terraform Plan
|
||||||
|
id: plan
|
||||||
|
run: terraform plan -out=tfplan
|
||||||
|
continue-on-error: true
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
env:
|
||||||
|
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
const { data: comments } = await github.rest.issues.listComments({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
})
|
||||||
|
const botComment = comments.find(comment => {
|
||||||
|
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
|
||||||
|
})
|
||||||
|
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
||||||
|
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
|
||||||
|
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
|
||||||
|
<details><summary>Validation Output</summary>
|
||||||
|
|
||||||
|
\`\`\`\n
|
||||||
|
${{ steps.validate.outputs.stdout }}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
|
||||||
|
|
||||||
|
<details><summary>Show Plan</summary>
|
||||||
|
|
||||||
|
\`\`\`\n
|
||||||
|
${process.env.PLAN}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
||||||
|
if (botComment) {
|
||||||
|
github.rest.issues.updateComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
comment_id: botComment.id,
|
||||||
|
body: output
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
github.rest.issues.createComment({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: output
|
||||||
|
})
|
||||||
|
}
|
0
prod/.terraform.lock.hcl → .terraform.lock.hcl
generated
0
prod/.terraform.lock.hcl → .terraform.lock.hcl
generated
3
main.tf
Normal file
3
main.tf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module "dummy" {
|
||||||
|
source = "./modules/dummy"
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
module "dummy" {
|
|
||||||
source = "../modules/dummy"
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
nomad = {
|
nomad = {
|
||||||
source = "hashicorp/nomad"
|
source = "hashicorp/nomad"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue