ec2_vpc – Manage EC2 VPCs¶
Create, update or delete an AWS EC2 Virtual Private Cloud.
Examples¶
- name: Create a VPC
ec2_vpc:
name: my-vpc
cidr: 10.0.0.0/16
instance_tenancy: dedicated
register: result
- name: Update VPC's instance tenancy
ec2_vpc:
id: "{{ result.object.id }}"
instance_tenancy: default
- name: Clear all VPC's tags
ec2_vpc:
id: "{{ result.object.id }}"
clear_tags: true
- name: Delete a VPC
ec2_vpc:
id: "{{ result.object.id }}"
state: absent
See Also¶
See also
Parameters¶
- auth (optional)
Parameters for authenticating with the AWS service. Each of them may be defined via environment variables.
type: dict- access_key (optional)
The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment variable will be checked.
Mutually exclusive with profile.
type: str- profile (optional)
The name of the AWS profile configured with
aws configure
.Can be used instead of explicitly specifying your access credentials and region.
Use
default
to use the default profile.Mutually exclusive with access_key and secret_key.
type: str- region (optional)
The name of the AWS region.
If not set, the value of the AWS_REGION environment variable will be checked.
If you set a profile that specifies a default region, that region is used and you can omit this parameter. Use this parameter to override the profile’s default region.
type: str- secret_key (optional)
The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment variable will be checked.
Mutually exclusive with profile.
type: str- url (optional)
The URL to the AWS service related to the resource. By default, this is automatically determined through the region parameter.
If not set explicitly, the value of the AWS_<SERVICE>_URL environment variable will be used.
The services currently supported are EC2 and S3.
type: str
- cidr (optional)
IPv4 network range to assign to the VPC, in CIDR notation.
This parameter is required unless id is provided.
In the absence of id, the value of this parameter will be used together with the value of name to uniquely identify the VPC.
type: str- clear_tags (optional)
Whether to clear any existing tags on the resource that are not explicitly stated in tags.
By default, existing tags are kept on the resource.
When this parameter is set to
true
, any pre-existing tags on the resource (including the name tag) are removed. To clear all tags except the name tag, make sure to provide the name parameter.type: bool- id (optional)
ID of the resource to perform the task on.
If specified, this parameter is used to identify the resource.
Omit this parameter when you are first creating the resource.
type: str- instance_tenancy (optional)
Allowed tenancy for EC2 instances launched into the VPC.
Once a VPC is created with
dedicated
tenancy, you may update the parameter todefault
, but not vice versa. Note that the the change will take effect for newly launched instances only.type: strchoices: default, dedicated- name (optional)
Name of the VPC.
This parameter is required unless id is provided.
The value of this parameter will be used together with the value of cidr to uniquely identify the VPC.
type: str- state (optional)
Target state of the AWS resource.
type: strdefault: presentchoices: present, absent- tags (optional)
Metadata for the AWS resource as key/value pairs.
Keys and values are case-sensitive.
type: dict
Return Values¶
- object (success and I(state=present)), dict, {‘object’: {‘id’: ‘vpc-123456’, ‘cidr’: ‘10.0.0.0/16’, ‘instance_tenancy’: ‘dedicated’, ‘tags’: {‘bu’: ‘finance’}}}
An object representing an EC2 VPC.
- id (always), str,
The ID of the VPC.
- cidr (always), str,
The CIDR block for the VPC.
- instance_tenancy (always), str,
The instance tenancy setting for instances launched in the VPC.
- tags (always), dict,
The tags assigned to the VPC.