Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint
on: [push, pull_request]
on: [pull_request]
jobs:
tflint:
runs-on: ubuntu-latest
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/terraform_cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: terraform-cloud
on:
push:
branches: main
pull_request:
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_wrapper: false
- name: Terraform init
id: init
run: terraform init

- name: Terraform Validate
id: validate
run: terraform validate -no-color

- name: Terraform plan
id: plan
env:
GITHUB_APP_ID: ${{ secrets.TF_GITHUB_APP_ID }}
GITHUB_APP_INSTALLATION_ID: ${{ secrets.TF_GITHUB_APP_INSTALLATION_ID }}
GITHUB_APP_PEM_FILE: ${{ secrets.TF_GITHUB_APP_PEM_FILE }}
run: terraform plan -no-color
continue-on-error: true

- name: Terraform apply
id: apply
if: github.branch == 'main'
env:
GITHUB_APP_ID: ${{ secrets.TF_GITHUB_APP_ID }}
GITHUB_APP_INSTALLATION_ID: ${{ secrets.TF_GITHUB_APP_INSTALLATION_ID }}
GITHUB_APP_PEM_FILE: ${{ secrets.TF_GITHUB_APP_PEM_FILE }}
run: terraform apply -no-color -auto-approve

- name: Output results as a comment to PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
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')
})

// 2. Prepare format of the comment
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 }}\`*`;

// 3. If we have a comment, update it, otherwise create a new one
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
})
}
64 changes: 33 additions & 31 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions github.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ terraform {
required_providers {
github = {
source = "integrations/github"
version = "4.22.0"
version = ">= 4.22.0"
}
}
}

variable "token" {
default = null
}

provider "github" {
owner = "makiton"
token = var.token # or `GITHUB_TOKEN`
token = ""
app_auth {
# id = var.app_id # or `GITHUB_APP_ID`
# installation_id = var.app_installation_id # or `GITHUB_APP_INSTALLATION_ID`
# pem_file = var.app_pem_file # or `GITHUB_APP_PEM_FILE`
}
}
2 changes: 2 additions & 0 deletions modules/repository/repository.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ resource "github_repository" "repository" {
gitignore_template = var.gitignore_template

vulnerability_alerts = true

archived = var.archived
}
5 changes: 5 additions & 0 deletions modules/repository/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ variable "protected_branches" {
type = map(object({}))
default = { main = {} }
}

variable "archived" {
type = bool
default = false
}
6 changes: 6 additions & 0 deletions repositories.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ locals {
makiton = {
description = "github profile page"
}
"slack-arigato-usagi" = {
description = ""
archived = true
}
}
}

Expand All @@ -57,4 +61,6 @@ module "repository" {
protected_branches = lookup(each.value, "private", false) ? {} : { main = {} }

status_checks = lookup(each.value, "status_checks", [])

archived = lookup(each.value, "archived", false)
}