question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create SecurityGroupIngress

See original GitHub issue

Hi, This is mostly not a bug but how to go about it. How can we add SecurityGroupIngress or SecurityGroupEgress referring to SecurityGroup created part of the same stack. My requirement is to loop through rules(how many ever are input) and create them referring to the SG and not defining the rules inline with the SG as shown in examples. I am trying something like:

   for r in rules:
      t.add_resource(SecurityGroupEgress=[
           SecurityGroupRule(
           IpProtocol=r[1],
           FromPort=r[2],
           ToPort=r[3],
           CidrIp=r[4],
           )
           ],
           GroupId=Ref(sg_name)
           )

I tried variations like

   t.add_resource(SecurityGroupEgress[
           SecurityGroupRule(

OR

 t.add_resource(SecurityGroupEgress(
           SecurityGroupRule(
           IpProtocol=r[1],

But am not able to find a way to declare/define SecurtiyGroupIngress or SecurtiyGroupEgress as a resource. I have to add the rules separately after defining the SG since I have to run loops.

Please help me what I might be missing.

Also, more of a generic question, what is the best way to use Python loops with troposphere. Obvious ways are in play since loops work for distinct add_resource and variable assignment works within add_resource but there’s no provision(expectedly) to run loops within add_resource.

Regards.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
aehlkecommented, Sep 1, 2016

Sorry, I was getting confused due to dealing with both non-VPC and VPC security groups, which have different cloudformation requirements around using group names vs. IDs, surprisingly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS::EC2::SecurityGroupIngress - AWS CloudFormation
Creates rules that grant full ICMP, UDP, and TCP access. If you specify SourceSecurityGroupName or SourceSecurityGroupId and that security group is owned by...
Read more >
Declaring Multiple Ingress/Egress Rules in an AWS::EC2
You can embed multiple ingress/egress rules in a single AWS::EC2::SecurityGroup CloudFormation template Resource declaration.
Read more >
aws-cloudformation-user-guide/aws-properties-ec2-security ...
AWS::EC2::SecurityGroupIngress. Adds an inbound rule to a security group. An inbound rule permits instances to receive traffic from the specified IPv4 or ...
Read more >
How to create SecurityGroupIngress objects? - Stack Overflow
Use software.amazon.awscdk.services.ec2.CfnSecurityGroup.IngressProperty instead of CfnSecurityGroupIngress : IngressProperty .builder() .
Read more >
Creating an RDS instance with CloudFormation
As part of our Runbooks series, learn how to create an RDS instance with ... Type: "AWS::EC2::SecurityGroup" Properties: GroupName: "Example ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found