-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf_plan.py
73 lines (62 loc) · 2.21 KB
/
tf_plan.py
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
import tf_models
import boto_tool
import json
def tfNatInstance(args=None):
'''
Required Variables from args:
region : string of source instance region
name : string of instance tag:Name
subnetId : string of subnet to assign NAT instance too
keyName : string of aws keypair name
tags : list of dicts [{'Key':'Value'},...]
vpcSecurityGroupIds : list of strings of SGs
sourceDestCheck : boolean (NAT = False, Bastion = True)
'''
try: # Gather required variables
if not args:
print 'No args passed'
return
else:
data = args
region = data.get('region')
name = data.get('name')
subnetId = data.get('subnetId')
keyName = data.get('keyName')
tags = data.get('tags')
vpcSecurityGroupIds = data.get('vpcSecurityGroupIds')
associatePublicIpAddress = True
sourceDestCheck = data.get('sourceDestCheck')
except Exception as e:
print str(e)
return
errSet = set() # Record errors
msgSet = set() # Record warnings
# Check for requirements
required = [name, region]
if None in required:
errSet.add('Required variables are missing')
try:
tags = json.loads(tags) if tags else None
except Exception as e:
errSet.add(str(e))
try:
vpcSecurityGroupIds = json.loads(
vpcSecurityGroupIds) if vpcSecurityGroupIds else None
except Exception as e:
errSet.add(str(e))
# Quit if error in inputs
if len(errSet) > 0:
print list(errSet)
return
ami = boto_tool.latestVpcNatImageId(region)
instanceType = 't2.micro'
return tf_models.Terraform.awsInstance(
name,
region,
ami,
instanceType,
subnetId,
keyName,
tags,
vpcSecurityGroupIds,
associatePublicIpAddress)