-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtfeapi.tfvars.sh.example
executable file
·94 lines (79 loc) · 4.45 KB
/
tfeapi.tfvars.sh.example
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
#!/bin/bash
########################
# EDIT THESE VARIABLES #
########################
BEARER_TOKEN="YOUR_TFE_API_TOKEN"
AWS_ACCESS_KEY="YOUR_AWS_ACCESS_KEY_ID"
AWS_SECRET_KEY="YOUR_SECRET_KEY_ID"
AWS_REGION="us-east-1"
AWS_AZS='[\"us-east-1a\",\"us-east-1b\",\"us-east-1c\"]'
KEY_PAIR="YOUR_SSH_KEY_PAIR"
UNIT_PREFIX="prefix"
INSTANCE_SIZE="t3.micro"
NUM_WORKER_NODES="6"
OWNER_EMAIL="YOUR_EMAIL_ADDRESS"
ORG_NAME="YOUR_TFE_ORGANIZATION_NAME"
WORKSPACE_NAME="YOUR_TFE_WORKSPACE_NAME"
#########################
# END EDITING VARIABLES #
#########################
# Get the workspace id from the workspace name
WORKSPACE_ID=$(curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
https://app.terraform.io/api/v2/organizations/${ORG_NAME}/workspaces/${WORKSPACE_NAME} | jq -r .data.id)
# Create all variables for the specified workspace
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "aws_access_key", "value": "'${AWS_ACCESS_KEY}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "aws_secret_key", "value": "'${AWS_SECRET_KEY}'", "description": "", "category": "terraform", "hcl": false, "sensitive": true } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "aws_region", "value": "'${AWS_REGION}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "aws_azs", "value": "'${AWS_AZS}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "key_pair", "value": "'${KEY_PAIR}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "unit_prefix", "value": "'${UNIT_PREFIX}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "instance_size", "value": "'${INSTANCE_SIZE}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "num_worker_nodes", "value": "'${NUM_WORKER_NODES}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars
curl -s \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data '{ "data": { "type": "vars", "attributes": { "key": "owner_email", "value": "'${OWNER_EMAIL}'", "description": "", "category": "terraform", "hcl": false, "sensitive": false } } }' \
https://app.terraform.io/api/v2/workspaces/${WORKSPACE_ID}/vars