-
Notifications
You must be signed in to change notification settings - Fork 3
85 lines (82 loc) · 2.91 KB
/
_workspace-manager.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: "Terraform workspace manager"
description: "Tool for terraform workspace manager. "
inputs:
aws_access_key_id:
description: "AWS Access Key ID."
required: true
aws_secret_access_key:
description: "AWS Secret Access Key."
required: true
aws_region:
description: "AWS Region"
default: "eu-west-1"
aws_account_id:
description: "Account ID for IAM Role"
required: true
aws_iam_role:
description: "AWS IAM Role Name"
required: true
register_workspace:
description: "Workspace name"
default: ""
time_to_protect:
description: "Time in hours to protect workspace for"
default: "24"
outputs:
protected_workspaces:
description: "Output from protected-workspaces call"
value: ${{ steps.list.outputs.list }}
workspace_name:
description: "registered workspace name"
value: ${{ steps.list.outputs.workspace }}
runs:
using: "composite"
steps:
- id: setup
name: Setup workspace manager
shell: bash
env:
TWM_SOURCE: https://github.com/TomTucka/terraform-workspace-manager/releases/download/v0.3.1/terraform-workspace-manager_Linux_x86_64.tar.gz
run: |
wget ${TWM_SOURCE} -O ${HOME}/terraform-workspace-manager.tar.gz
sudo tar -xvf ${HOME}/terraform-workspace-manager.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/terraform-workspace-manager
- id: aws_creds
name: Configure AWS Credentials For Terraform
uses: aws-actions/configure-aws-credentials@v4.0.1
with:
aws-access-key-id: ${{ inputs.aws_access_key_id }}
aws-secret-access-key: ${{ inputs.aws_secret_access_key }}
aws-region: ${{ inputs.aws_region }}
role-duration-seconds: 600
role-session-name: "${{github.repository}}-TWM"
- id: register
if: ${{ inputs.register_workspace != '' }}
name: Register workspace name [${{inputs.register_workspace}}]
shell: bash
env:
TWM_ACCOUNT_ID: ${{inputs.aws_account_id}}
TWM_IAM_ROLE: ${{inputs.aws_iam_role}}
TWM_TTL: ${{inputs.time_to_protect}}
TWM_REGISTER_WORKSPACE: ${{inputs.register_workspace}}
run: |
echo "Registering workspace"
terraform-workspace-manager \
-aws-account-id=${TWM_ACCOUNT_ID} \
-aws-iam-role=${TWM_IAM_ROLE} \
-time-to-protect=${TWM_TTL} \
-register-workspace=${TWM_REGISTER_WORKSPACE}
- id: list
name: List workspaces
shell: bash
env:
TWM_ACCOUNT_ID: ${{inputs.aws_account_id}}
TWM_IAM_ROLE: ${{inputs.aws_iam_role}}
run: |
echo "List protected workspace"
workspaces=$(terraform-workspace-manager \
-aws-account-id=${TWM_ACCOUNT_ID} \
-aws-iam-role=${TWM_IAM_ROLE} \
-protected-workspaces=true)
echo "list=${workspaces}" >> $GITHUB_OUTPUT
echo "workspace=${{inputs.register_workspace}}" >> $GITHUB_OUTPUT