Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gene1wood/74c6e891f17667797d0c6d7c121b2789 to your computer and use it in GitHub Desktop.
Save gene1wood/74c6e891f17667797d0c6d7c121b2789 to your computer and use it in GitHub Desktop.
How to fix "Provided Target Groups may not be valid" on AWS CloudFormation stack update

If you

  • Create a CloudFormation template that creates an Auto Scale Group
  • Set the TargetGroupARNs field in the Auto Scale Group to the output from the Target Group's LoadBalancerArns attribute (which is obtained with GetAtt)
  • Do a stack update

You will encounter a stack update failure with the error message Provided Target Groups may not be valid

Instead of using GetAtt of the LoadBalancerArns of the Target Group, use the Ref of the Target Group and put the single resulting ARN into a list when you set the TargetGroupARNs in the Auto Scale Group

Before

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 443
      Protocol: HTTP
      VpcId: !Ref VpcId
  AutoScaleGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      LaunchConfigurationName: !Ref LaunchConfiguration
      TargetGroupARNs: !GetAtt TargetGroup.LoadBalancerArns

After

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 443
      Protocol: HTTP
      VpcId: !Ref VpcId
  AutoScaleGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      LaunchConfigurationName: !Ref LaunchConfiguration
      TargetGroupARNs:
        - !Ref TargetGroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment