-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |