awslabs / diagram-as-code

Diagram-as-code for AWS architecture.
Apache License 2.0
405 stars 22 forks source link

Target resource is not drawn when related to resources in the same layer #73

Open a2ush opened 1 month ago

a2ush commented 1 month ago

Issue detail

Target resource is not drawn when related to resources in the same layer.

Reproduce process

Subnets are same layer in this template. In this case, the ELB is a child resource of the two subnets, and then it is not rendered.

Yaml template

Resources:
  VPC1:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VPCCIDR    
      EnableDnsSupport: true
      EnableDnsHostnames: true
  Subnet1:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC1
      MapPublicIpOnLaunch: false
  Subnet2:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC1
      MapPublicIpOnLaunch: false
  NLB: 
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties: 
      Scheme: "internal"
      Subnets: 
        - !Ref Subnet1    ## <------- here
        - !Ref Subnet2    ## <------- here
      Type: network

NLB

a2ush commented 1 month ago

workaround : comment out the subnets

Resources:
...
  NLB: 
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties: 
      Scheme: "internal"
      # Subnets: 
      #   - !Ref Subnet1
      #   - !Ref Subnet2

If you want to put the ELB icon into the VPC, you can describe it as the following;

Resources:
...
  NLB: 
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties: 
      Scheme: "internal"
      VpcId: !Ref VPC1

In CloudFormation, Resource type AWS::ElasticLoadBalancingV2::LoadBalancer does not have "VpcId" Property[1]. However, since awsdac just looks at dependencies based on !Ref or DependsOn, there is no problem in assigning non-existent properties to resources.

NLB3

[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html