Skip to content

new input on tf plan and new select branch workspace action #87

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion .github/workflows/tf_validate_plan_env_roots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
description: Terraform version to use
type: string
required: true
build-artifact-directory:
description: Optional directory to create before running terraform plan. Path should be relative to the terraform envirionment root directories
type: string
required: false
secrets:
ORG_READ_ONLY_SSH_KEY:
required: true
Expand All @@ -24,7 +28,7 @@ on:
jobs:
TF-Validate-Plan-Roots:
name: TF Validate/Plan ENV Roots
uses: ./.github/workflows/tf_validate_plan_single_root.yml
uses: opensesame/core-github-actions/.github/workflows/tf_validate_plan_single_root.yml@beta
strategy:
fail-fast: false # continues to run jobs even if one fails
matrix:
Expand All @@ -42,6 +46,7 @@ jobs:
terraform-workspace: ${{ inputs.terraform-workspace || matrix.environment }}
terraform-root: terraform/${{ matrix.environment }}
terraform-version: ${{ inputs.terraform-version }}
build-artifact-directory: ${{ inputs.build-artifact-directory }}
secrets:
ORG_READ_ONLY_SSH_KEY: ${{ secrets.ORG_READ_ONLY_SSH_KEY }}
ORG_GITHUB_PACKAGES_READ_ONLY_TOKEN: ${{ secrets.ORG_GITHUB_PACKAGES_READ_ONLY_TOKEN }}
11 changes: 10 additions & 1 deletion .github/workflows/tf_validate_plan_single_root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ on:
description: Terraform version to use
type: string
required: true
build-artifact-directory:
description: Optional directory to create before running terraform plan. Path should be relative to the terraform-root supplied
type: string
required: false
secrets:
ORG_READ_ONLY_SSH_KEY:
required: true
Expand Down Expand Up @@ -98,6 +102,11 @@ jobs:
terraform_version: ${{ inputs.terraform-version }}
terraform_wrapper: false # required to access terraform outputs after apply

# Step to create the directory if the build-artifact-directory input is provided
- name: Ensure Build Artifact Directory Exists
if: ${{ inputs.build-artifact-directory != '' }}
run: mkdir -p ${{ inputs.build-artifact-directory }}

- name: Terraform Init
run: terraform init -upgrade

Expand All @@ -107,7 +116,7 @@ jobs:
- name: Select Workplace
run: terraform workspace select -or-create ${{ inputs.terraform-workspace }}

- name: Terrafrom Re-Init
- name: Terraform Re-Init
run: terraform init -upgrade

- name: Terraform Plan
Expand Down
5 changes: 5 additions & 0 deletions select-branch-workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Overview

Takes in a string input meant to be the name of a branch.
The branch name is sanitized to be used as a workspace name.
The resulting workspace name is then used to select the workspace, creating it if it does not exist.
33 changes: 33 additions & 0 deletions select-branch-workspace/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Sanitize Branch Name for Terraform Workspace
description: Removes everything before the final "/" from the branch name and limits the characters.
inputs:
branch-name:
description: The name of the branch to be sanitized
required: true
working-directory:
description: the directory the step should be run from
required: true
outputs:
workspace-name:
description: "Branch name after the final forward slash"
value: ${{ steps.sanitize_branch.outputs.sanitized_branch_name }}

runs:
using: "composite"
steps:
- name: Sanitize input branch
id: sanitize_branch
shell: bash
run: |
pwd
cd ${{ inputs.working-directory }}
pwd
terraform workspace list
SANITIZED_BRANCH_NAME=$(echo ${{ inputs.branch-name }} | sed 's/.*\///' | sed 's/\(^.\{1,50\}\).*/\1/')
echo "Sanitized branch name: $SANITIZED_BRANCH_NAME"
terraform workspace select -or-create $SANITIZED_BRANCH_NAME
echo "sanitized_branch_name=$SANITIZED_BRANCH_NAME" >> $GITHUB_OUTPUT

# sed 's/.*\///' removes everything before the final slash
# sed 's/\(^.\{1,50\}\).*/\1/' #Character limit is 50. Terraform workspace allows up to 90 characters
# TODO: Remove special characters. Eg sed 's/[#$%*@]//g'