/
action.yaml
165 lines (156 loc) · 5.18 KB
/
action.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: "spawn-cluster"
description: "Spawn a cluster using Terraform"
inputs:
# Access credentials
GIT_ACCESS_TOKEN:
description: "A Github PAT"
required: true
ARTIFACTS_USER:
description: "Scality Artifacts username"
required: true
ARTIFACTS_PASSWORD:
description: "Scality Artifacts password"
required: true
# Tooling configuration
TERRAFORM_VERSION:
description: "Terraform version to use"
required: false
default: "1.8.2"
TERRAFORM_SNAPSHOT_TAG:
description: "Tag to checkout for the scality/terraform-snapshot repository"
required: false
default: "0.15.0"
# Cloud configuration
CLOUD:
description: "Name of the remote cloud to use (available: ovh)"
required: false
default: "ovh"
# Spawn configuration
NAME:
description: "Name of the deployment (used in artifacts and the VM names prefix)"
required: true
OS:
description: "Name of the OS to spawn"
required: false
default: rocky-8
NODES_COUNT:
description: "Number of nodes to spawn in addition to bootstrap and bastion"
required: false
default: "0"
RESTORE_ENV:
description: "The name of the snapshoted environment that will be use to spawn"
required: false
default: ""
rhsm-username:
description: "The RHSM username to use (only needed on RedHat)"
required: false
default: ""
rhsm-password:
description: "The RHSM password to use (only needed on RedHat)"
required: false
default: ""
AUTHORIZED_CIDRS:
description: "List of CIDRs to allow SSH and ICMP ingress from"
required: false
default: '["0.0.0.0/0"]'
args:
description: Specific arguments to add to the apply command
required: false
default: ""
skip-prepare:
description: Skip the preparation of the worker
required: false
default: "false"
runs:
using: "composite"
steps:
- name: Prepare SSH keypair
if: inputs.skip-prepare == 'false'
shell: bash
run: |
mkdir -p ~/.ssh
rm -rf ~/.ssh/terraform*
ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/terraform
# copy ssh keys now in order to allow us to connect to the machine if needed
mkdir -p "artifacts/terraform-context/${{ inputs.NAME }}/"
cp ~/.ssh/terraform* "artifacts/terraform-context/${{ inputs.NAME }}/"
- name: Upload SSH keypair
if: inputs.skip-prepare == 'false'
uses: scality/action-artifacts@v4
with:
method: upload
url: https://artifacts.scality.net
user: ${{inputs.ARTIFACTS_USER}}
password: ${{inputs.ARTIFACTS_PASSWORD}}
source: artifacts/
- name: Checkout scality/terraform-snapshot
if: inputs.skip-prepare == 'false'
uses: actions/checkout@v3
with:
repository: scality/terraform-snapshot
path: terraform-snapshot
token: ${{ inputs.GIT_ACCESS_TOKEN }}
ref: ${{ inputs.TERRAFORM_SNAPSHOT_TAG }}
- name: Install tools
if: inputs.skip-prepare == 'false'
shell: bash
run: sudo apt-get update && sudo apt-get install -y unzip
- name: Install node
if: inputs.skip-prepare == 'false'
uses: actions/setup-node@v3
with:
node-version: "14"
- name: Install Terraform
if: inputs.skip-prepare == 'false'
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ inputs.TERRAFORM_VERSION }}
terraform_wrapper: false
- name: Initialize Terraform
if: inputs.skip-prepare == 'false'
working-directory: terraform-snapshot/terraform/
shell: bash
run: terraform init
- name: Validate terraform
working-directory: terraform-snapshot/terraform/
shell: bash
run: terraform validate
- name: Spawn cluster with Terraform
working-directory: terraform-snapshot/terraform/
shell: bash
env:
TF_VAR_prefix: ${{ github.workflow }}-${{ github.run_number }}-${{ inputs.NAME }}
TF_VAR_os: "${{ inputs.OS }}"
TF_VAR_nodes_count: "${{ inputs.NODES_COUNT }}"
TF_VAR_restore_env: "${{ inputs.RESTORE_ENV }}"
TF_VAR_rhsm_username: "${{ inputs.rhsm-username }}"
TF_VAR_rhsm_password: "${{ inputs.rhsm-password }}"
TF_VAR_ingress_remote_ip_prefix: "${{ inputs.AUTHORIZED_CIDRS }}"
MAX_RETRIES: "3"
TFVARS_DIR: "${{ github.workspace }}/.github/spawn/tfvars"
run: |
declare -a TF_OPTS=(
"-auto-approve"
"-var-file $TFVARS_DIR/common.tfvars"
"-var-file $TFVARS_DIR/${{ inputs.CLOUD }}.tfvars"
)
for try in $(seq 1 ${MAX_RETRIES}); do
if terraform apply ${TF_OPTS[@]} ${{ inputs.args }}; then
break
elif [ $try -lt $MAX_RETRIES ]; then
sleep 150
else
echo "Error: unable to spawn openstack virtual infra after" \
"$MAX_RETRIES tries" >&2
exit 1
fi
done
- name: Save node IPs in output
id: output_ips
working-directory: terraform-snapshot/terraform
shell: bash
run: terraform output -json ips
outputs:
ips:
description: JSON string representing all access IPs for the spawned machines
value: ${{ steps.output_ips.outputs.stdout }}