Exemple #1
0
    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)
 def create_apigw_method(self, template: Template):
     if self.apigw_method_aws_object_ready():
         template.add_resource(self.apigw_method_aws_object,
                               ignore_duplicate=True)
     if self.apigw_method_lbd_permission_aws_object_ready():
         template.add_resource(self.apigw_method_lbd_permission_aws_object,
                               ignore_duplicate=True)
 def create_s3_event_bucket(self, template: Template):
     if self.s3_event_bucket_aws_object_ready():
         template.add_resource(self.s3_event_bucket_aws_object,
                               ignore_duplicate=True)
     if self.s3_event_bucket_lbd_permission_aws_object_ready():
         template.add_resource(
             self.s3_event_bucket_lbd_permission_aws_object,
             ignore_duplicate=True)
 def create_scheduled_job_event(self, template: Template):
     if self.scheduled_job_event_rule_aws_objects_ready():
         for _, value in self.scheduled_job_event_rule_aws_objects.items():
             template.add_resource(value, ignore_duplicate=True)
     if self.scheduled_job_event_lbd_permission_aws_objects_ready():
         for _, value in self.scheduled_job_event_lbd_permission_aws_objects.items(
         ):
             template.add_resource(value, ignore_duplicate=True)
Exemple #5
0
def test_mutable_aws_object():
    """
    确定 ``mate.AWSObject`` 变化时, 对应的 ``mate.AWSObject.aws_object`` 也应该
    跟着变化.
    """
    from troposphere_mate import iam

    tpl = Template()
    my_policy = iam.ManagedPolicy(
        title="MyPolicy",
        template=tpl,
        PolicyDocument={},
    )
    my_role = iam.Role(
        title="MyRole",
        template=tpl,
        RoleName="my-role",
        AssumeRolePolicyDocument={},
    )
    assert tpl.to_dict(
    )["Resources"]["MyRole"]["Properties"]["RoleName"] == "my-role"
    assert "ManagedPolicyArns" not in tpl.to_dict(
    )["Resources"]["MyRole"]["Properties"]

    my_role.RoleName = "my-role-two"
    my_role.ManagedPolicyArns = [Ref(my_policy)]
    assert tpl.to_dict(
    )["Resources"]["MyRole"]["Properties"]["RoleName"] == "my-role-two"
    assert tpl.to_dict(
    )["Resources"]["MyRole"]["Properties"]["ManagedPolicyArns"] == [{
        "Ref":
        "MyPolicy"
    }]

    outputs = [
        Output(
            "MyRolePath",
            Value=GetAtt(my_role, "Path"),
            DependsOn=my_role,
        )
    ]
    for output in outputs:
        tpl.add_output(output)
    assert tpl.to_dict()["Outputs"]["MyRolePath"]["Value"] == {
        "Fn::GetAtt": ["MyRole", "Path"]
    }

    dct = tpl.to_dict()

    tpl2 = Template()
    tpl2.add_resource(my_policy)
    tpl2.add_resource(my_role)
    for output in outputs:
        tpl2.add_output(output)
    dct2 = tpl2.to_dict()

    assert dct == dct2
 def create_apigw_method_options_for_cors(self, template: Template):
     if self.apigw_method_options_for_cors_aws_object_ready():
         template.add_resource(
             self.apigw_method_options_for_cors_aws_object,
             ignore_duplicate=True)
 def create_apigw_resource(self, template: Template):
     if self.apigw_resource_aws_object_ready():
         template.add_resource(self.apigw_resource_aws_object,
                               ignore_duplicate=True)
 def create_lbd_func(self, template: Template):
     if self.lbd_func_aws_object_ready():
         template.add_resource(self.lbd_func_aws_object,
                               ignore_duplicate=True)