https://pulumi.com logo
#aws
Title
# aws
a

astonishing-dinner-89046

07/21/2021, 4:13 AM
Howdy. I’m trying to retrieve the default security group using
aws.ec2.get_security_group
. I’m able to export the default vpc id and default SG id but it’s throwing an error. Any ideas?
Copy code
# Retrieve the Default VPC
defaultvpc = aws.ec2.get_vpc(
    default=True
    )

# Retrieve the Default Security Group
default_sg = aws.ec2.get_security_group(name='default')

Diagnostics:
    ValueError: unexpected input of type GetSecurityGroupResult
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
 
Outputs:
  + default_sg          : "sg-9ac15fe8"
  + vpc_id              : "vpc-595e9c4g"
and if I run pulumi up again w/o changing anything, it’s a different error.
Copy code
RuntimeError: Event loop is closed
    exception calling callback for <Future at 0x10ffc1e20 state=finished returned RegisterResourceResponse>
    Traceback (most recent call last):
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/concurrent/futures/_base.py", line 328, in _invoke_callbacks
        callback(self)
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/futures.py", line 374, in _call_set_state
        dest_loop.call_soon_threadsafe(_set_state, destination, source)
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 764, in call_soon_threadsafe
        self._check_closed()
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 508, in _check_closed
        raise RuntimeError('Event loop is closed')
    RuntimeError: Event loop is closed

Outputs:
  + default_sg          : "sg-9ac15fe8"
  + vpc_id              : "vpc-595e9c4g"
c

cool-fireman-90027

07/21/2021, 12:35 PM
Hi, Here is some sample code that does something similar.
a

astonishing-dinner-89046

07/21/2021, 4:43 PM
The example code is exactly what I have in my code.
b

broad-hairdresser-1495

07/22/2021, 3:18 PM
@astonishing-dinner-89046 try something with Filter instead:
Copy code
default_sg = aws.ec2.get_security_group(filters=[{'Name': 'group-name', 'Values': [resource["name"]]}])
For more info on how filter works you can find it here: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html search for
--filters (list)
2 Views