Skip to content

Commit

Permalink
Github action for terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkcuys committed Sep 9, 2020
1 parent c97634d commit f5284a5
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Terraform"

on:
push:
branches:
- master
pull_request:

jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build the site in the jekyll/builder container
run: |
docker run \
-v ${{ github.workspace }}:/srv/jekyll -v ${{ github.workspace }}/_site:/srv/jekyll/_site \
jekyll/builder:latest /bin/bash -c "chmod 777 /srv/jekyll && jekyll build --future"
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

- name: Terraform Format
id: fmt
run: terraform fmt -check

- name: Terraform Init
id: init
run: terraform init --backend-config="key=tfstate/p2pu-website/${{github.branch}}"

- name: Terraform apply
id: apply
if: github.event_name == 'pull_request'
run: terraform apply -auto-approve
# continue-on-error: true

- uses: actions/[email protected]
if: github.event_name == 'pull_request'
env:
APPLY: "terraform\n${{ steps.apply.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Apply 📖\`${{ steps.apply.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`${process.env.APPLY}\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
# - name: Terraform Plan Status
# if: steps.apply.outcome == 'failure'
# run: exit 1
29 changes: 29 additions & 0 deletions terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "branch_name" {
type = string
}

terraform {
backend "s3" {
bucket = "sysadmin"
region = "us-east-1"
}
}

provider "aws" {
region = "us-east-1"
}

resource "random_pet" "bucket" {}

resource "aws_s3_bucket" "website" {
bucket = "p2pu-website-${random_pet.bucket.id}"
acl = "public-read"

website {
index_document = "index.html"
}
}

output "site_url" {
value = aws_s3_bucket.website.bucket_domain_name
}

0 comments on commit f5284a5

Please sign in to comment.