-
Notifications
You must be signed in to change notification settings - Fork 14
/
conditions.py
114 lines (100 loc) · 2.59 KB
/
conditions.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
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
103
104
105
106
107
108
109
110
111
112
113
114
from troposphere import Template, Parameter, Ref, Condition, Equals, And, Or, Not, If
from troposphere import ec2
t = Template()
t.add_parameter(
[
Parameter(
'One',
Type='String',
),
Parameter(
'Two',
Type='String',
),
Parameter(
'Three',
Type='String',
),
Parameter(
'Four',
Type='String',
),
Parameter(
'SshKeyName',
Type='String',
)
]
)
t.add_condition('OneEqualsFoo',
Equals(
Ref('One'),
'Foo'
)
)
t.add_condition('NotOneEqualsFoo',
Not(
Condition('OneEqualsFoo')
)
)
t.add_condition('BarEqualsTwo',
Equals(
'Bar',
Ref('Two')
)
)
t.add_condition('ThreeEqualsFour',
Equals(
Ref('Three'),
Ref('Four')
)
)
t.add_condition('OneEqualsFooOrBarEqualsTwo',
Or(
Condition('OneEqualsFoo'),
Condition('BarEqualsTwo')
)
)
t.add_condition('OneEqualsFooAndNotBarEqualsTwo',
And(
Condition('OneEqualsFoo'),
Not(Condition('BarEqualsTwo'))
)
)
t.add_condition('OneEqualsFooAndBarEqualsTwoAndThreeEqualsPft',
And(
Condition('OneEqualsFoo'),
Condition('BarEqualsTwo'),
Equals(Ref('Three'), 'Pft')
)
)
t.add_condition('OneIsQuzAndThreeEqualsFour',
And(
Equals(Ref('One'), 'Quz'),
Condition('ThreeEqualsFour')
)
)
t.add_condition('LaunchInstance',
And(
Condition('OneEqualsFoo'),
Condition('NotOneEqualsFoo'),
Condition('BarEqualsTwo'),
Condition('OneEqualsFooAndNotBarEqualsTwo'),
Condition('OneIsQuzAndThreeEqualsFour')
)
)
t.add_condition('LaunchWithGusto',
And(
Condition('LaunchInstance'),
Equals(Ref('One'), 'Gusto')
)
)
t.add_resource(
ec2.Instance(
'Ec2Instance',
Condition='LaunchInstance',
ImageId=If('ConditionNameEqualsFoo', 'ami-12345678', 'ami-87654321'),
InstanceType='t1.micro',
KeyName=Ref('SshKeyName')
)
)
print(t.to_yaml())