Skip to content

Commit fdb2691

Browse files
committed
adds support for baking AMIs in a different AZ
1 parent 9365df5 commit fdb2691

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

vars/ciinaboxVPC.groovy

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
example usage
88
ciinaboxVPC(
99
ciinabox: 'ciinabox',
10-
region: env.REGION
10+
region: env.REGION,
11+
availabilityZone: 'a'
1112
)
13+
the optional az attribute allows you to override which availability zone is returned
1214
************************************/
1315
@Grab(group='com.amazonaws', module='aws-java-sdk-cloudformation', version='1.11.359')
1416

@@ -18,7 +20,9 @@ import com.amazonaws.services.cloudformation.model.*
1820
def call(body) {
1921
def config = body
2022

21-
def ciinabox = ciinaboxStack(config.get('ciinabox', 'ciinabox'), config.region)
23+
az = config.get('availabilityZone', 'a').toUpperCase()
24+
ciinaboxName = config.get('ciinabox', 'ciinabox')
25+
def ciinabox = ciinaboxStack(ciinaboxName, config.region)
2226
if(ciinabox) {
2327
def outputs = [:]
2428
ciinabox.outputs.each { output ->
@@ -30,15 +34,15 @@ def call(body) {
3034
if(exist) {
3135
new File(paramsFile).delete()
3236
}
33-
writeFile file: paramsFile, text: toJson(outputs)
37+
writeFile file: paramsFile, text: toJson(outputs, az)
3438
} else {
3539
throw new RuntimeException("no ciinabox stack ${ciinabox} found")
3640
}
3741

3842
}
3943

4044
@NonCPS
41-
def ciinaboxStack(stackName, region) {
45+
def ciinaboxStack(stackName, region, az) {
4246
try {
4347
def cf = setupClient(region)
4448
DescribeStacksResult result = cf.describeStacks(new DescribeStacksRequest().withStackName(stackName))
@@ -53,11 +57,12 @@ def ciinaboxStack(stackName, region) {
5357
}
5458

5559
@NonCPS
56-
def toJson(outputs) {
60+
def toJson(outputs, az) {
61+
subnet = "ECSPrivateSubnet${az}"
5762
def json_text = """{
5863
"region": "${outputs['Region']}",
5964
"vpc_id": "${outputs['VPCId']}",
60-
"subnet_id": "${outputs['ECSPrivateSubnetA']}",
65+
"subnet_id": "${outputs[subnet]}",
6166
"security_group": "${outputs['SecurityGroup']}",
6267
"packer_role": "${outputs['ECSRole']}",
6368
"packer_instance_profile": "${outputs['ECSInstanceProfile']}"

0 commit comments

Comments
 (0)