0
votes
AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      AvailabilityZones:
        - ap-southeast-1
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******
      Metadata:
        'AWS::CloudFormation::Designer':
          id: 3f17841f-7296-4aeb-a464-94dbbf6542fd
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******

Getting error Template is not valid: Template format error: Unresolved resource dependencies [subnet-, sg-, subnet-, vpc-*] in the Resources block of the template

PLease hel me to add

1

1 Answers

1
votes

If vpc-******, subnet-******, sg-********** are actual IDs of your existing VPC, subnets, and security group, then you do not need !Ref to reference them.

Just provide them without !Ref, e.g.

SecurityGroups:
  - sg-**********
Subnets:
  - subnet-******
  - subnet-*******

VpcId: vpc-******

New template version:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      IpAddressType: ipv4
      Name: mytestingELB
      Scheme: internet-facing
      Type: application
      SecurityGroups:
        - !Ref sg-**********
      Subnets:
        - !Ref subnet-******
        - !Ref subnet-*******

  MyTargetGroup
      'AWS::ElasticLoadBalancingV2::TargetGroup':
        Properties:
          HealthCheckIntervalSeconds: '30'
          HealthCheckPath: /
          HealthCheckProtocol: HTTP
          HealthCheckTimeoutSeconds: '5'
          HealthyThresholdCount: '5'
          Matcher:
            HttpCode: '200'
          Name: testingtargetgroup
          Port: '80'
          Protocol: HTTP
          TargetType: instance
          UnhealthyThresholdCount: '2'
          VpcId: !Ref vpc-******

MyTargetGroup was added and AvailabilityZones and Metadata removed.