Skip to content

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

Description

@sid21rane

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions