ImportError: cannot import name 'SecurityGroup'

9 views
Skip to first unread message

Frank

unread,
Nov 16, 2022, 7:28:17 AM11/16/22
to cloudtools-dev
Hi,

I'm very new to troposphere, my goal is to use it as IaC for AWS, I noticed that there is not much documentation or examples in comparison with Terraform or Ansible.

I'm trying some code and it happens that now that I wanted to import "securitygroup" I get error below.

ERROR:
from troposphere.ecs import (SecurityGroup, SecurityGroupRule)
ImportError: cannot import name 'SecurityGroup' from 'troposphere.ecs' (/home/blabla/.local/lib/python3.8/site-packages/troposphere/ecs.py)



I can import in my script many functions but these two, it is just adding them and I get the error, btw I see all the libraries under "ecs.py".

from troposphere.ecs import (
AwsvpcConfiguration,
Cluster,
ContainerDefinition,
NetworkConfiguration,
PortMapping,
Service,
TaskDefinition,
SecurityGroup,
SecurityGroupRule,
)

The only differences I see against the repo is that in the repo (https://github.com/cloudtools/troposphere/blob/6499cd57991761857f893fa7d608c4f660f1946d/examples/VPC_single_instance_in_subnet.py#L25) they imported only networking related functions.

Is there anyone able to point out what I am missing in here?.
Maybe I do need to build a separate stack with another script?, thank you.

Kyle Finley

unread,
Nov 16, 2022, 7:44:10 AM11/16/22
to Frank, cloudtools-dev
`from troposphere.ecs` needs to be `from troposphere.ec2` for SecurityGroup and SecurityGroupRule.

For resources and complex properties, you can generally refer to the CloudFormation documentation to get an idea of where to import them from. For example AWS::EC2::SecurityGroup would be `from troposphere.ec2 import SecurityGroup` or you can use `from troposphere import ec2` and consume the resource as `ec2.SecurityGroup`.


--
You received this message because you are subscribed to the Google Groups "cloudtools-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloudtools-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloudtools-dev/98801fc8-7c08-4abf-a03f-87cadd502b78n%40googlegroups.com.

Frank

unread,
Nov 16, 2022, 8:32:44 AM11/16/22
to cloudtools-dev
Got you, very clear :-D, cheers. 
Reply all
Reply to author
Forward
0 new messages