Giter Site home page Giter Site logo

Self-referencing SecurityGroups about cfndsl HOT 3 CLOSED

cfndsl avatar cfndsl commented on July 19, 2024
Self-referencing SecurityGroups

from cfndsl.

Comments (3)

kenong avatar kenong commented on July 19, 2024

Hi Josh,

Have you tried something like this:

...
  Resource("WebSecurityGroup") {
    Type "AWS::EC2::SecurityGroup"
    Property "GroupDescription", "Security policies for web servers"
    Property "VpcId", "vpc-b543o123"
  }

  Resource("WebSecurityGroupIngress") {
    Type "AWS::EC2::SecurityGroupIngress"
    Property "GroupId", Ref("WebSecurityGroup")
    Property "IpProtocol", "tcp"
    Property "FromPort", 8080
    Property "ToPort", 8080
    Property "SourceSecurityGroupId", Ref("WebLBSecurityGroup")
  }

  Resource("WebSecurityGroupIngress8080") {
    Type "AWS::EC2::SecurityGroupIngress"
    Property "GroupId", Ref("WebSecurityGroup")
    Property "IpProtocol", "tcp"
    Property "FromPort", 8080
    Property "ToPort", 8080
    Property "SourceSecurityGroupId", Ref("WebSecurityGroup")
  }

  Resource("WebSecurityGroupEgress8080") {
    Type "AWS::EC2::SecurityGroupEgress"
    Property "GroupId", Ref("WebSecurityGroup")
    Property "IpProtocol", "tcp"
    Property "FromPort", 8080
    Property "ToPort", 8080
    Property "DestinationSecurityGroupId", Ref("WebSecurityGroup")
  }
...

it produced this for me:

...
      "WebSecurityGroup" : {
         "Type" : "AWS::EC2::SecurityGroup",
         "Properties" : {
            "VpcId" : "vpc-b543o123",
            "GroupDescription" : "Security policies for web servers"
         }
      },
      "WebSecurityGroupIngress" : {
         "Type" : "AWS::EC2::SecurityGroupIngress",
         "Properties" : {
            "ToPort" : 8080,
            "GroupId" : {
               "Ref" : "WebSecurityGroup"
            },
            "FromPort" : 8080,
            "SourceSecurityGroupId" : {
               "Ref" : "WebLBSecurityGroup"
            },
            "IpProtocol" : "tcp"
         }
      },
      "WebSecurityGroupIngress8080" : {
         "Type" : "AWS::EC2::SecurityGroupIngress",
         "Properties" : {
            "ToPort" : 8080,
            "GroupId" : {
               "Ref" : "WebSecurityGroup"
            },
            "FromPort" : 8080,
            "SourceSecurityGroupId" : {
               "Ref" : "WebSecurityGroup"
            },
            "IpProtocol" : "tcp"
         }
      },
      "WebSecurityGroupEgress8080" : {
         "Type" : "AWS::EC2::SecurityGroupEgress",
         "Properties" : {
            "DestinationSecurityGroupId" : {
               "Ref" : "WebSecurityGroup"
            },
            "ToPort" : 8080,
            "GroupId" : {
               "Ref" : "WebSecurityGroup"
            },
            "FromPort" : 8080,
            "IpProtocol" : "tcp"
         }
      },
...

from cfndsl.

howech avatar howech commented on July 19, 2024

@kenong, while the code you show gives the correct output, it avoids all of the type checking mechanisms that cfndsl has to offer. An equivalent snippet that should produce the same results is

  EC2_SecurityGroup(:WebSecurityGroup) {                                                                           
    GroupDescription "Security policies for web servers"                                                           
    VpcId "vpc-b543o123"                                                                                           
  }                                                                                                                

  EC2_SecurityGroupIngress(:WebSecurityGroupIngress) {                                                             
    GroupId Ref(:WebSecurityGroup)                                                                                 
    IpProtocol "tcp"                                                                                               
    FromPort 8080                                                                                                  
    ToPort 8080                                                                                                    
    SourceSecurityGroupId Ref(:WebSecurityGroup)                                                                   
  }                                                                                                                

  EC2_SecurityGroupIngress(:WebSecurityGroupIngress8080) {                                                         
   GroupId Ref(:WebSecurityGroup)                                                                                  
   IpProtocol "tcp"                                                                                                
   FromPort 8080                                                                                                   
   ToPort 8080                                                                                                     
   SourceSecurityGroupId Ref(:WebSecurityGroup)                                                                    
  }                                                                                                                

  EC2_SecurityGroupEgress(:WebSecurityGroupEgress8080) {                                                           
    GroupId Ref(:WebSecurityGroup)                                                                                 
    IpProtocol "tcp"                                                                                               
    FromPort 8080                                                                                                  
    ToPort 8080                                                                                                    
    DestinationSecurityGroupId Ref(:WebSecurityGroup)                                                              
  }        

However, it turns out there are some typos in aws_types.yaml in the source code that cause this to not work. Expect a pull request and fix soon.

from cfndsl.

howech avatar howech commented on July 19, 2024

I think that this issue is fixed.

from cfndsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.