Assign Existing Security Groups to an Instance

I am trying to filter some existing security groups to a new ec2 instance and ran into an error.

    security_groups = DataAwsSecurityGroups(self,"sg",filter= [{
        "name": "tag:Name",
        "values": ["Windows"]
    }])
   instance = Instance(self, "compute",
                         ami=ami.id,
                         instance_type=instance_type,
                         security_groups = security_groups,
                         #TODO: Find a better way to query subnet
                         subnet_id = Fn.element(Token.as_list(subnets.ids), 0)
    )
TypeError: type of argument security_groups must be one of (Sequence[str], NoneType); got imports.aws.data_aws_security_groups.DataAwsSecurityGroups instead

Hi @lmayorga1980 :wave:

The security_groups property accepts a list of names of security groups (AWS Terraform provider docs) and the DataAwsSecurityGroups data source (docs) only has a list of ids (security_groups.ids) which you could try passing to that property but might not work – I’m not that experienced with AWS.

This issue (albeit old), seems related: How to give a single security group for an aws instance ? · Issue #2164 · hashicorp/terraform · GitHub

– Ansgar

Is there a way to check all the classes available per programming language?

They are indexed here for example: Construct Hub