Skip to content

Commit d136a08

Browse files
Garison DraperGarison Draper
authored andcommitted
added help comments and set to update tags on every run
1 parent b9928ba commit d136a08

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stacker/util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,18 @@ def ensure_s3_bucket(s3_client, bucket_name, bucket_region, context):
475475
bucket_region (str, optional): The region to create the bucket in. If
476476
not provided, will be determined by s3_client's region.
477477
context (:class:`stacker.context.Context`): context instance, used to
478-
get tags from the stacker run
478+
set tags on the S3 bucket created from the stacker config
479479
480480
"""
481481
try:
482+
# Checking is bucket exists
482483
s3_client.head_bucket(Bucket=bucket_name)
484+
# pulling tags from context
485+
tagset = stacker.actions.build.build_stack_tags(context)
486+
# setting tags on every run - must have permission to perform
487+
# the s3:PutBucketTagging action
488+
s3_client.put_bucket_tagging(Bucket=bucket_name,
489+
Tagging={'TagSet': tagset})
483490
except botocore.exceptions.ClientError as e:
484491
if e.response['Error']['Message'] == "Not Found":
485492
logger.debug("Creating bucket %s.", bucket_name)
@@ -491,8 +498,11 @@ def ensure_s3_bucket(s3_client, bucket_name, bucket_region, context):
491498
create_args["CreateBucketConfiguration"] = {
492499
"LocationConstraint": location_constraint
493500
}
501+
# pulling tags from context
494502
tagset = stacker.actions.build.build_stack_tags(context)
495503
s3_client.create_bucket(**create_args)
504+
# setting tags on every run - must have permission to perform
505+
# the s3:PutBucketTagging action
496506
s3_client.put_bucket_tagging(Bucket=bucket_name,
497507
Tagging={'TagSet': tagset})
498508
elif e.response['Error']['Message'] == "Forbidden":

0 commit comments

Comments
 (0)