https://pulumi.com logo
#general
Title
# general
k

kind-minister-39119

03/13/2020, 1:11 AM
Hey guys. New to pulumi, using the python aws module> I want to create an ec2 instance in an existing VPC. I can
get_vpc
and
get_subnet
, but
aws.ec2.Instance
does not give me the opportunity to specify a VPC ID. The result is when I specify the subnet, I get this error:
Copy code
aws:ec2:Instance (ansible-master):
    error: Error launching source instance: InvalidGroup.NotFound: The security group 'mgmt-ansible-master-sg-xxxx' does not exist in VPC 'vpc-xxxxxx'
        status code: 400, request id: xxxxx
Copy code
vpc = aws.ec2.get_vpc(cidr_block="172.18.0.0/16")
subnet = aws.ec2.get_subnet(vpc_id=vpc.id, cidr_block="172.18.1.0/24")

group = aws.ec2.SecurityGroup('mgmt-ansible-master-sg',
    description='Ansible Master Security Group',
    ingress=[
        { 'protocol': 'tcp', 'from_port': 22, 'to_port': 22, 'cidr_blocks': ['172.18.0.0/24'] }
    ],
    egress=[
        { 'protocol': '-1', 'from_port': 0, 'to_port': 0, 'cidr_blocks': ['0.0.0.0/0'] }
    ], vpc_id=vpc.id)

server = aws.ec2.Instance("ansible-master",
        instance_type=size,
        security_groups=[group.name],
        ami=ami.id, key_name='mgmt', subnet_id=subnet.id)
c

colossal-ram-89482

03/13/2020, 2:47 AM
@kind-minister-39119 I believe you want to try
vpc_security_group_ids
instead of
security_groups
🙏 1