-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (56 loc) · 1.83 KB
/
create-terraform-cloud-workspace-for-aws-ephemeral-environment.terraform.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
name: Create Terraform Cloud Workspace for AWS ephemeral environment
on:
workflow_call:
inputs:
product:
required: true
type: string
service:
required: true
type: string
branch:
required: true
type: string
secrets:
TF_API_TOKEN:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
outputs:
tf-workspace:
description: "Terraform workspace name within the organization"
value: ${{ jobs.create-environment.outputs.tf-workspace }}
jobs:
create-environment:
runs-on: ubuntu-latest
outputs:
tf-workspace: ${{ steps.tf-workspace.outputs.workspace }}
steps:
- name: Checkout client infrastructure repository
uses: actions/checkout@v3
with:
repository: codingones/ephemeral-environment-infrastructure
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_wrapper: false
- name: Terraform Init
run: terraform init
- name: Terraform Apply
run: >-
terraform apply
-auto-approve
-input=false
-var="aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}"
-var="aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}"
-var="product=${{ inputs.product }}"
-var="service=${{ inputs.service }}"
-var="branch=$(echo ${{ inputs.branch }} | sed -r 's/refs\/heads\///')"
-var="tf_api_token=${{ secrets.TF_API_TOKEN }}"
- name: Set the terraform workspace name output as a workflow output
id: tf-workspace
run: |
echo "workspace=$(terraform output -raw workspace_name)" >>$GITHUB_OUTPUT