Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAT-16244 DevOps :: Spacelift replacement of Terraform Cloud #211

Merged
merged 7 commits into from
Jan 9, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
runs-on: ubuntu-20.04
env:
TF_VAR_env: "prod"
SPACELIFT_API_KEY_ENDPOINT: ${{ secrets.SPACELIFT_API_KEY_ENDPOINT }}
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
defaults:
run:
working-directory: scripts/redirect_creation
Expand All @@ -45,10 +48,8 @@ jobs:
aws-secret-access-key: ${{ secrets.DOCS_AWS_KEY }}
aws-region: us-east-1

- name: Terraform Init
id: init
run: terraform init -backend-config=$TF_VAR_env.remote.tfbackend

- name: Terraform Apply
run: terraform apply -target=aws_s3_object.enterprise_redirects -auto-approve
- name: Deploy infrastructure
run: |
spacectl stack set-current-commit --id liquibase-docs-prod --sha ${{ github.sha }}
spacectl stack deploy --id liquibase-docs-prod --auto-confirm

21 changes: 11 additions & 10 deletions .github/workflows/promote-staging-to-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ jobs:
runs-on: ubuntu-20.04
env:
TF_VAR_env: "prod"
SPACELIFT_API_KEY_ENDPOINT: ${{ secrets.SPACELIFT_API_KEY_ENDPOINT }}
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
defaults:
run:
working-directory: scripts/redirect_creation
steps:
- uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Install spacectl
uses: spacelift-io/setup-spacectl@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -46,9 +49,7 @@ jobs:
aws-secret-access-key: ${{ secrets.DOCS_AWS_KEY }}
aws-region: us-east-1

- name: Terraform Init
id: init
run: terraform init -backend-config=$TF_VAR_env.remote.tfbackend

- name: Terraform Apply
run: terraform apply -auto-approve
- name: Deploy infrastructure
run: |
spacectl stack set-current-commit --id liquibase-docs-prod --sha ${{ github.sha }}
spacectl stack deploy --id liquibase-docs-prod --auto-confirm
28 changes: 14 additions & 14 deletions .github/workflows/send-docs-redirects-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
runs-on: ubuntu-20.04
env:
TF_VAR_env: "staging"
SPACELIFT_API_KEY_ENDPOINT: ${{ secrets.SPACELIFT_API_KEY_ENDPOINT }}
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
defaults:
run:
working-directory: scripts/redirect_creation
Expand All @@ -26,10 +29,10 @@ jobs:
with:
ref: ${{ github.event.inputs.branch }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Install spacectl
uses: spacelift-io/setup-spacectl@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -45,20 +48,15 @@ jobs:

- name: Terraform Init
id: init
run: terraform init -backend-config=$TF_VAR_env.remote.tfbackend
run: terraform init

- name: Terraform Validate
if: ${{ github.event_name == 'pull_request' }}
id: validate
run: terraform validate -no-color

- name: Terraform Plan
if: ${{ github.event_name == 'pull_request' }}
id: plan
run: |
terraform plan -out=plan.tmp
terraform show -no-color plan.tmp >${GITHUB_WORKSPACE}/plan.out
continue-on-error: false
- name: Preview infrastructure
run: spacectl stack local-preview --id liquibase-docs-staging > ${GITHUB_WORKSPACE}/plan.out

- name: Terraform Show Plan in PR
uses: actions/github-script@v6
Expand Down Expand Up @@ -103,6 +101,8 @@ jobs:
body: output
})

- name: Terraform Apply
- name: Deploy infrastructure
if: ${{ github.event_name == 'push' }}
run: terraform apply -auto-approve
run: |
spacectl stack set-current-commit --id liquibase-docs-staging --sha ${{ github.sha }}
spacectl stack deploy --id liquibase-docs-staging --auto-confirm
28 changes: 14 additions & 14 deletions .github/workflows/send-enterprise-redirects-to-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
runs-on: ubuntu-20.04
env:
TF_VAR_env: "staging"
SPACELIFT_API_KEY_ENDPOINT: ${{ secrets.SPACELIFT_API_KEY_ENDPOINT }}
SPACELIFT_API_KEY_ID: ${{ secrets.SPACELIFT_API_KEY_ID }}
SPACELIFT_API_KEY_SECRET: ${{ secrets.SPACELIFT_API_KEY_SECRET }}
defaults:
run:
working-directory: scripts/redirect_creation
Expand All @@ -23,10 +26,10 @@ jobs:
with:
ref: ${{ github.event.inputs.branch }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Install spacectl
uses: spacelift-io/setup-spacectl@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand All @@ -42,20 +45,15 @@ jobs:

- name: Terraform Init
id: init
run: terraform init -backend-config=$TF_VAR_env.remote.tfbackend
run: terraform init

- name: Terraform Validate
if: ${{ github.event_name == 'pull_request' }}
id: validate
run: terraform validate -no-color

- name: Terraform Plan
if: ${{ github.event_name == 'pull_request' }}
id: plan
run: |
terraform plan -out=plan.tmp
terraform show -no-color plan.tmp >${GITHUB_WORKSPACE}/plan.out
continue-on-error: false
- name: Preview infrastructure
run: spacectl stack local-preview --id liquibase-docs-staging >${GITHUB_WORKSPACE}/plan.out

- name: Terraform Show Plan in PR
uses: actions/github-script@v6
Expand Down Expand Up @@ -100,6 +98,8 @@ jobs:
body: output
})

- name: Terraform Apply
- name: Deploy infrastructure
if: ${{ github.event_name == 'push' }}
run: terraform apply -target=aws_s3_object.enterprise_redirects -auto-approve
run: |
spacectl stack set-current-commit --id liquibase-docs-staging --sha ${{ github.sha }}
spacectl stack deploy --id liquibase-docs-staging --auto-confirm
6 changes: 1 addition & 5 deletions scripts/redirect_creation/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@

terraform {
backend "remote" {}
}

# use Terraform Remote State Data stanza to read state from environment-based workspace
data "terraform_remote_state" "state" {
backend = "remote"
config = {
organization = "liquibase"
hostname = "spacelift.io"
workspaces = {
name = "liquibase-${var.env}"
}
Expand Down
Loading
Loading