Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: {'LabelMatchStatement': {'Key': 'foo', 'Scope': 'bar'}} is not a valid Statement #2122

Open
delkopiso opened this issue Feb 12, 2023 · 0 comments

Comments

@delkopiso
Copy link

Problem

The error TypeError: {'LabelMatchStatement': {'Key': 'foo', 'Scope': 'bar'}} is not a valid Statement is returned when ingesting a CloudFormation template with TemplateGenerator.

Expected behavior

Any template built with the troposphere Template should be digestible via TemplateGenerator.

Reproduction steps

import json

from troposphere import Template
from troposphere.template_generator import TemplateGenerator
from troposphere.wafv2 import (
    Statement,
    WebACLRule,
    RuleAction,
    BlockAction,
    VisibilityConfig,
    WebACL,
    AllowAction,
    DefaultAction,
    LabelMatchStatement,
)


def build_template() -> Template:
    t = Template()
    t.set_version()
    t.set_description("reproduction case.")

    t.add_resource(
        WebACL(
            "waf",
            DefaultAction=DefaultAction(Allow=AllowAction()),
            Description="description of waf",
            Rules=[
                WebACLRule(
                    Name="rule1",
                    Action=RuleAction(Block=BlockAction()),
                    Priority=0,
                    Statement=Statement(
                        LabelMatchStatement=LabelMatchStatement(
                            Key="foo", Scope="bar",
                        )
                    ),
                    VisibilityConfig=VisibilityConfig(
                        CloudWatchMetricsEnabled=True,
                        MetricName="metric",
                        SampledRequestsEnabled=False,
                    ),
                ),
            ],
            Scope="REGIONAL",
            VisibilityConfig=VisibilityConfig(
                CloudWatchMetricsEnabled=True,
                MetricName="metric",
                SampledRequestsEnabled=False,
            ),
        )
    )

    return t


if __name__ == '__main__':
    built_template = build_template()
    built_json = built_template.to_json()
    print(built_json)
    generated_template = TemplateGenerator(json.loads(built_json))
    generated_json = generated_template.to_json()
    print(generated_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant