Last active
May 27, 2019 13:18
-
-
Save serverhorror/0096da538c5cba1236b3262d4e4fadc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python .\aws\test_templateIteration.py | |
Outputs: | |
Output0: | |
Description: Output0 | |
Value: Output0 | |
Output1: | |
Description: Output1 | |
Value: Output1 | |
Output2: | |
Description: Output2 | |
Value: Output2 | |
Resources: {} | |
Parameters: | |
Parameter0: | |
Default: 'Coming from: Output0' | |
Type: AWS::EC2::VPC::Id | |
Parameter1: | |
Default: 'Coming from: Output1' | |
Type: AWS::EC2::VPC::Id | |
Parameter2: | |
Default: 'Coming from: Output2' | |
Type: AWS::EC2::VPC::Id | |
Resources: {} | |
. | |
---------------------------------------------------------------------- | |
Ran 1 test in 0.013s | |
OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from troposphere import Output, Parameter, Template | |
class TestTemplIteration(unittest.TestCase): | |
def testTemplateIteration(self): | |
providerTempl = Template() | |
num_outputs = 3 | |
for i in range(num_outputs): | |
o = Output("Output{!s}".format(i), | |
Description="Output{!s}".format(i), | |
Value="Output{!s}".format(i)) | |
providerTempl.add_output(o) | |
self.assertEqual(num_outputs, len(providerTempl.outputs)) | |
print(providerTempl.to_yaml()) | |
consumerTempl = Template() | |
for i, key in enumerate(providerTempl.outputs): | |
origin = key # providerTempl.outputs[i] | |
param = p = Parameter( | |
"Parameter{}".format(i), | |
Type="AWS::EC2::VPC::Id", | |
Default="Coming from: {!s}".format(providerTempl.outputs[key].title)) | |
consumerTempl.add_parameter(p) | |
self.assertEqual(len(consumerTempl.parameters), len(providerTempl.outputs)) | |
print(consumerTempl.to_yaml()) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment