def test_remove_parameter_and_output(self): tpl = Template() p1 = Parameter("P1", Type="string") o1 = Output("O1", Value=Ref("P1")) # before state tpl.add_parameter(p1) tpl.add_output(o1) assert len(tpl.parameters) == 1 assert len(tpl.outputs) == 1 # test remove by object tpl.remove_parameter(p1) tpl.remove_output(o1) assert len(tpl.parameters) == 0 assert len(tpl.outputs) == 0 # before state tpl.add_parameter(p1) tpl.add_output(o1) assert len(tpl.parameters) == 1 assert len(tpl.outputs) == 1 # test remove by str tpl.remove_parameter(p1.title) tpl.remove_output(o1.title) assert len(tpl.parameters) == 0 assert len(tpl.outputs) == 0
class CannedCommonEc2IamRole(MultiEnvBasicConfig): template = None # type: Template iam_role_ec2_s3_full_access = None # type: iam.Role iam_instance_profile_ec2_s3_full_access = None # type: iam.Role def create_template(self): self.template = Template() self.param_env_name = param_env_name self.param_env_name.Default = self.ENVIRONMENT_NAME.get_value() self.template.add_parameter(param_env_name) self.iam_role_ec2_s3_full_access = iam.Role( "IamRoleEc2S3FullAccess", template=self.template, RoleName=helper_fn_sub("{}-ec2-s3-full-access", self.param_env_name), AssumeRolePolicyDocument=create_assume_role_policy_document( [AWSServiceName.amazon_Elastic_Compute_Cloud_Amazon_EC2]), ManagedPolicyArns=[AWSManagedPolicyArn.amazonS3FullAccess]) self.iam_instance_profile_ec2_s3_full_access = iam.InstanceProfile( "IamInstanceProfileS3FullAccess", template=self.template, InstanceProfileName=helper_fn_sub("{}-ec2-s3-full-access", self.param_env_name), Roles=[ self.iam_role_ec2_s3_full_access.iam_role_name, ]) return self.template
def test_add_parameter_resource_output(self): from troposphere_mate import apigateway tpl = Template() param_project_name = Parameter("ProjectName", Type="String") rest_api = apigateway.RestApi( "RestApi", template=tpl, Name=Ref(param_project_name), EndpointConfiguration=apigateway.EndpointConfiguration( Types=["REGIONAL"])) output_rest_api_id = Output("RestApiId", Value=Ref(rest_api)) # test ignore_duplicate argument tpl.add_parameter(param_project_name) with raises(ValueError): tpl.add_parameter(param_project_name) tpl.add_parameter(param_project_name, ignore_duplicate=True) with raises(ValueError): tpl.add_resource(rest_api) tpl.add_resource(rest_api, ignore_duplicate=True) tpl.add_output(output_rest_api_id) with raises(ValueError): tpl.add_output(output_rest_api_id) tpl.add_output(output_rest_api_id, ignore_duplicate=True)
Default=config.PROJECT_NAME.get_value()) param_project_name_slug = Parameter( "ProjectNameSlug", Type="String", Default=config.PROJECT_NAME_SLUG.get_value()) param_stage = Parameter("Stage", Type="String", Default=config.STAGE.get_value()) param_env_name = Parameter("EnvironmentName", Type="String", Default=config.ENVIRONMENT_NAME.get_value()) template.add_parameter(param_project_name) template.add_parameter(param_project_name_slug) template.add_parameter(param_stage) template.add_parameter(param_env_name) ecr_repo_webapp = ecr.Repository( "EcrRepoWebApp", RepositoryName=config.ECR_REPO_NAME_WEBAPP.get_value(), LifecyclePolicy=ecr.LifecyclePolicy(LifecyclePolicyText=json.dumps({ "rules": [{ "rulePriority": 1, "description": "keep untagged (historical) image for N days", "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days",
) # IMPORTANT! # import the nested stack python module, # allows to cross reference parameter or output and # bind "AWS::Cloudformation::Stack" with nested stack template from . import tier_1_iam_role template = Template() param_env_name = Parameter( "EnvironmentName", Type="String", ) template.add_parameter(param_env_name) iam_role_stack = cloudformation.Stack( "IamRoleStack", template=template, TemplateURL="", # cross reference parameter Parameters={ tier_1_iam_role.param_env_name.title: Ref(param_env_name), }, ) # bind nested stack with a template link_stack_template(stack=iam_role_stack, template=tier_1_iam_role.template) iam_instance_profile = iam.InstanceProfile( "IamInstanceProfileWebServer",