Use boto normalized location for bucket creation

If a bucket is being created in us-east-1, the module passed
'us-east-1' to boto's s3.create_bucket method rather than
Location.DEFAULT (an empty string). This caused boto to generate
invalid XML which AWS was unable to interpret.
This commit is contained in:
Ryan Sydnor 2015-11-20 13:55:44 -05:00 committed by Matt Clay
parent b3ffcd7c6c
commit 1899e9e6cc

View file

@ -133,11 +133,10 @@ def create_tags_container(tags):
tags_obj.add_tag_set(tag_set) tags_obj.add_tag_set(tag_set)
return tags_obj return tags_obj
def create_bucket(connection, module): def create_bucket(connection, module, location):
policy = module.params.get("policy") policy = module.params.get("policy")
name = module.params.get("name") name = module.params.get("name")
region = module.params.get("region")
requester_pays = module.params.get("requester_pays") requester_pays = module.params.get("requester_pays")
tags = module.params.get("tags") tags = module.params.get("tags")
versioning = module.params.get("versioning") versioning = module.params.get("versioning")
@ -147,7 +146,7 @@ def create_bucket(connection, module):
bucket = connection.get_bucket(name) bucket = connection.get_bucket(name)
except S3ResponseError, e: except S3ResponseError, e:
try: try:
bucket = connection.create_bucket(name, location=region) bucket = connection.create_bucket(name, location=location)
changed = True changed = True
except S3CreateError, e: except S3CreateError, e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
@ -380,7 +379,7 @@ def main():
state = module.params.get("state") state = module.params.get("state")
if state == 'present': if state == 'present':
create_bucket(connection, module) create_bucket(connection, module, location)
elif state == 'absent': elif state == 'absent':
destroy_bucket(connection, module) destroy_bucket(connection, module)