cloudtools / troposphere

troposphere - Python library to create AWS CloudFormation descriptions
BSD 2-Clause "Simplified" License
4.93k stars 1.44k forks source link

E3012 Specify only 'SubnetMappings' or 'Subnets' #2152

Open sid21rane opened 1 year ago

sid21rane commented 1 year ago

I am using Troposphere version 3.2.2 and Python 3.7.

I want to create 2 application load balancers and I am using albv2 template for the same. One load balancer is Internet facing and another is private hence I want to attach 3 public subnets (one for each AZ) to the internet facing load balancer and 3 private subnets (one for each AZ) to the private load balancer. I am doing that with ImportValue.

While doing that I am getting an error - E3012 Specify only 'SubnetMappings' or 'Subnets'. I am using "Subnets" at both places. Ideally this shouldn't have been an issue since the subnets are different and getting attached to different load balancers. Can someone guide please.

My code -

ABCALB = elbv2.LoadBalancer(
    "ApplicationLoadBalancer",
    Scheme="internet-facing",
    SecurityGroups=[
        If("IsTrue", Ref(AlbSecurityGroupPublic), Ref(AlbSecurityGroupPrivate))
    ],
    Subnets=[
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PublicSubnet1a")
        ),
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PublicSubnet1b")
        ),
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PublicSubnet1c")
        ),
    ],
    Tags=get_tags(
        Sub("${EnvironmentName}-ABC-ALB"), disableDD=True
    ),
    Type="application",
    LoadBalancerAttributes=[
        elbv2.LoadBalancerAttributes(Key="access_logs.s3.enabled", Value="true"),
        elbv2.LoadBalancerAttributes(
            Key="access_logs.s3.bucket",
            Value=Sub("${EnvironmentName}-ABC-elb"),
        ),
        elbv2.LoadBalancerAttributes(
            Key="deletion_protection.enabled", Value="true"
        ),
        elbv2.LoadBalancerAttributes(
            Key="idle_timeout.timeout_seconds", Value="180"
        ),
    ],
)
template.add_resource(ABCALB)

ABCALBInternal = elbv2.LoadBalancer(
    "ApplicationInternalLoadBalancer",
    Scheme="internal",
    SecurityGroups=[
        If("IsTrue", Ref(AlbSecurityGroupPublic), Ref(AlbSecurityGroupPrivate))
    ],
    Subnets=[
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PrivateSubnet1a")
        ),
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PrivateSubnet1b")
        ),
        ImportValue(
            Sub("${EnvironmentName}-ABC-vpc::PrivateSubnet1c")
        ),
    ],
    Tags=get_tags(Sub("${EnvironmentName}ABC-internal-ALB")),
    Type="application",
    LoadBalancerAttributes=[
        elbv2.LoadBalancerAttributes(Key="access_logs.s3.enabled", Value="true"),
        elbv2.LoadBalancerAttributes(
            Key="access_logs.s3.bucket",
            Value=Sub("${EnvironmentName}-ABC-internal-elb"),
        ),
        elbv2.LoadBalancerAttributes(
            Key="deletion_protection.enabled", Value="true"
        ),
        elbv2.LoadBalancerAttributes(
            Key="idle_timeout.timeout_seconds", Value="180"
        ),
    ],
)
template.add_resource(ABCALBInternal)
sid21rane commented 1 year ago

Hi,

Can someone help please.

regards, Siddharth Rane