Add cloudformation update from s3 support (#1377)
* Fix variable name typo * Make it possible to delete EC2 instances from cloudformation json * Add support for updating a cloudformation stack from an s3 template url
This commit is contained in:
parent
52ce8d378f
commit
92f5f7b263
4 changed files with 73 additions and 22 deletions
|
|
@ -1,18 +1,13 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import boto
|
||||
import boto.s3
|
||||
import boto.s3.key
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_cloudformation, mock_s3, mock_sqs
|
||||
|
||||
import json
|
||||
import sure # noqa
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import random
|
||||
|
||||
from moto import mock_cloudformation, mock_s3, mock_sqs, mock_ec2
|
||||
|
||||
dummy_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
|
|
@ -39,7 +34,6 @@ dummy_template = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
dummy_template_yaml = """---
|
||||
AWSTemplateFormatVersion: 2010-09-09
|
||||
Description: Stack1 with yaml template
|
||||
|
|
@ -57,7 +51,6 @@ Resources:
|
|||
Value: Name tag for tests
|
||||
"""
|
||||
|
||||
|
||||
dummy_template_yaml_with_short_form_func = """---
|
||||
AWSTemplateFormatVersion: 2010-09-09
|
||||
Description: Stack1 with yaml template
|
||||
|
|
@ -75,7 +68,6 @@ Resources:
|
|||
Value: Name tag for tests
|
||||
"""
|
||||
|
||||
|
||||
dummy_template_yaml_with_ref = """---
|
||||
AWSTemplateFormatVersion: 2010-09-09
|
||||
Description: Stack1 with yaml template
|
||||
|
|
@ -100,7 +92,6 @@ Resources:
|
|||
Value: !Ref TagName
|
||||
"""
|
||||
|
||||
|
||||
dummy_update_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
"Parameters": {
|
||||
|
|
@ -131,12 +122,12 @@ dummy_output_template = {
|
|||
}
|
||||
}
|
||||
},
|
||||
"Outputs" : {
|
||||
"StackVPC" : {
|
||||
"Description" : "The ID of the VPC",
|
||||
"Value" : "VPCID",
|
||||
"Export" : {
|
||||
"Name" : "My VPC ID"
|
||||
"Outputs": {
|
||||
"StackVPC": {
|
||||
"Description": "The ID of the VPC",
|
||||
"Value": "VPCID",
|
||||
"Export": {
|
||||
"Name": "My VPC ID"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -156,7 +147,7 @@ dummy_import_template = {
|
|||
}
|
||||
|
||||
dummy_template_json = json.dumps(dummy_template)
|
||||
dummy_update_template_json = json.dumps(dummy_template)
|
||||
dummy_update_template_json = json.dumps(dummy_update_template)
|
||||
dummy_output_template_json = json.dumps(dummy_output_template)
|
||||
dummy_import_template_json = json.dumps(dummy_import_template)
|
||||
|
||||
|
|
@ -172,6 +163,7 @@ def test_boto3_create_stack():
|
|||
cf_conn.get_template(StackName="test_stack")['TemplateBody'].should.equal(
|
||||
dummy_template)
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
def test_boto3_create_stack_with_yaml():
|
||||
cf_conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||
|
|
@ -283,6 +275,41 @@ def test_create_stack_from_s3_url():
|
|||
'TemplateBody'].should.equal(dummy_template)
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
@mock_s3
|
||||
@mock_ec2
|
||||
def test_update_stack_from_s3_url():
|
||||
s3 = boto3.client('s3')
|
||||
s3_conn = boto3.resource('s3')
|
||||
|
||||
cf_conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||
cf_conn.create_stack(
|
||||
StackName="update_stack_from_url",
|
||||
TemplateBody=dummy_template_json,
|
||||
Tags=[{'Key': 'foo', 'Value': 'bar'}],
|
||||
)
|
||||
|
||||
s3_conn.create_bucket(Bucket="foobar")
|
||||
|
||||
s3_conn.Object(
|
||||
'foobar', 'template-key').put(Body=dummy_update_template_json)
|
||||
key_url = s3.generate_presigned_url(
|
||||
ClientMethod='get_object',
|
||||
Params={
|
||||
'Bucket': 'foobar',
|
||||
'Key': 'template-key'
|
||||
}
|
||||
)
|
||||
|
||||
cf_conn.update_stack(
|
||||
StackName="update_stack_from_url",
|
||||
TemplateURL=key_url,
|
||||
)
|
||||
|
||||
cf_conn.get_template(StackName="update_stack_from_url")[
|
||||
'TemplateBody'].should.equal(dummy_update_template)
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
def test_describe_stack_pagination():
|
||||
conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||
|
|
@ -382,6 +409,7 @@ def test_delete_stack_from_resource():
|
|||
|
||||
|
||||
@mock_cloudformation
|
||||
@mock_ec2
|
||||
def test_delete_stack_by_name():
|
||||
cf_conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||
cf_conn.create_stack(
|
||||
|
|
@ -412,6 +440,7 @@ def test_describe_deleted_stack():
|
|||
|
||||
|
||||
@mock_cloudformation
|
||||
@mock_ec2
|
||||
def test_describe_updated_stack():
|
||||
cf_conn = boto3.client('cloudformation', region_name='us-east-1')
|
||||
cf_conn.create_stack(
|
||||
|
|
@ -502,6 +531,7 @@ def test_stack_tags():
|
|||
|
||||
|
||||
@mock_cloudformation
|
||||
@mock_ec2
|
||||
def test_stack_events():
|
||||
cf = boto3.resource('cloudformation', region_name='us-east-1')
|
||||
stack = cf.create_stack(
|
||||
|
|
@ -617,6 +647,7 @@ def test_export_names_must_be_unique():
|
|||
TemplateBody=dummy_output_template_json,
|
||||
)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
@mock_cloudformation
|
||||
def test_stack_with_imports():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue