1313import yaml
1414from collections import OrderedDict
1515from git import Repo
16-
16+ import stacker . actions . build
1717import botocore .exceptions
1818
1919logger = logging .getLogger (__name__ )
@@ -465,7 +465,7 @@ def s3_bucket_location_constraint(region):
465465 return region
466466
467467
468- def ensure_s3_bucket (s3_client , bucket_name , bucket_region ):
468+ def ensure_s3_bucket (s3_client , bucket_name , bucket_region , context ):
469469 """Ensure an s3 bucket exists, if it does not then create it.
470470
471471 Args:
@@ -474,6 +474,9 @@ def ensure_s3_bucket(s3_client, bucket_name, bucket_region):
474474 bucket_name (str): The bucket being checked/created.
475475 bucket_region (str, optional): The region to create the bucket in. If
476476 not provided, will be determined by s3_client's region.
477+ context (:class:`stacker.context.Context`): context instance, used to
478+ get tags from the stacker run
479+
477480 """
478481 try :
479482 s3_client .head_bucket (Bucket = bucket_name )
@@ -488,7 +491,10 @@ def ensure_s3_bucket(s3_client, bucket_name, bucket_region):
488491 create_args ["CreateBucketConfiguration" ] = {
489492 "LocationConstraint" : location_constraint
490493 }
494+ tagset = stacker .actions .build .build_stack_tags (context )
491495 s3_client .create_bucket (** create_args )
496+ s3_client .put_bucket_tagging (Bucket = bucket_name ,
497+ Tagging = {'TagSet' : tagset })
492498 elif e .response ['Error' ]['Message' ] == "Forbidden" :
493499 logger .exception ("Access denied for bucket %s. Did " +
494500 "you remember to use a globally unique name?" ,
0 commit comments