troposphere
troposphere copied to clipboard
TypeError: {'LabelMatchStatement': {'Key': 'foo', 'Scope': 'bar'}} is not a valid Statement
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)