-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathshippable.yml
102 lines (98 loc) · 3.5 KB
/
shippable.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
resources:
# Automation scripts repo
- name: aws_vpc_tf_repo
type: gitRepo
integration: "dr_gh"
versionTemplate:
sourceName: "devops-recipes/prov_aws_vpc_terraform"
branch: master
# Terraform State
- name: aws_vpc_tf_state
type: state
# Output of VPC provisioning
- name: aws_vpc_tf_info
type: params
versionTemplate:
params:
SEED: "initial_version"
jobs:
# Provision AWS VPC with Terraform
- name: prov_aws_vpc_tr
type: runSh
integrations:
- dr_aws
steps:
- IN: aws_vpc_tf_repo
- IN: aws_vpc_tf_state
switch: off
- TASK:
name: prov_vpc
runtime:
options:
env:
- vpc_region: "us-east-1"
- vpc_name: "demo_vpc_tf"
- vpc_cidr_block: "10.10.0.0/16"
- vpc_access_from_ip_range: "0.0.0.0/0"
- vpc_public_subnet_1_cidr: "10.10.10.0/24"
- vpc_private_subnet_1_cidr: "10.10.11.0/24"
script:
- pushd $(shipctl get_resource_state "aws_vpc_tf_repo")
- export AWS_ACCESS_KEY_ID=$(shipctl get_integration_field dr_aws "accessKey")
- export AWS_SECRET_ACCESS_KEY=$(shipctl get_integration_field dr_aws "secretKey")
- shipctl copy_file_from_resource_state aws_vpc_tf_state terraform.tfstate .
- shipctl replace terraform.tfvars
- terraform init
- terraform apply -auto-approve -var-file=terraform.tfvars
- OUT: aws_vpc_tf_info
overwrite: true
- OUT: aws_vpc_tf_state
on_success:
script:
- shipctl put_resource_state_multi aws_vpc_tf_info "versionName=$vpc_name" "vpc_id=$(terraform output vpc_id)" "vpc_region=$vpc_region" "vpc_public_sg_id=$(terraform output vpc_public_sg_id)" "vpc_public_sn_id=$(terraform output vpc_public_sn_id)" "vpc_private_sg_id=$(terraform output vpc_private_sg_id)" "vpc_private_sn_id=$(terraform output vpc_private_sn_id)"
always:
script:
- shipctl copy_file_to_resource_state terraform.tfstate aws_vpc_tf_state
- popd
flags:
- aws_vpc
- aws
- terraform
## De-Provision VPC
# - name: deprov_aws_vpc_tf
# type: runSh
# integrations:
# - dr_aws
# steps:
# - IN: aws_vpc_tf_repo
# - IN: aws_vpc_tf_state
# switch: off
# - IN: aws_vpc_tf_info
# switch: off
# - TASK:
# name: deprov_vpc
# runtime:
# options:
# env:
# - vpc_region: "us-east-1"
# - vpc_name: "demo_vpc_tf"
# - vpc_cidr_block: "10.10.0.0/16"
# - vpc_access_from_ip_range: "0.0.0.0/0"
# - vpc_public_subnet_1_cidr: "10.10.10.0/24"
# - vpc_private_subnet_1_cidr: "10.10.11.0/24"
# script:
# - export AWS_ACCESS_KEY_ID=$(shipctl get_integration_field dr_aws "accessKey")
# - export AWS_SECRET_ACCESS_KEY=$(shipctl get_integration_field dr_aws "secretKey")
# - pushd $(shipctl get_resource_state "aws_vpc_tf_repo")
# - shipctl copy_file_from_resource_state aws_vpc_tf_state terraform.tfstate .
# - shipctl replace terraform.tfvars
# - terraform init
# - terraform destroy -force -auto-approve -var-file=terraform.tfvars
# - OUT: aws_vpc_tf_state
# always:
# script:
# - shipctl copy_file_to_resource_state terraform.tfstate aws_vpc_tf_state
# flags:
# - aws_vpc
# - aws
# - terraform