# salt.states.boto_ec2

Manage EC2

New in version 2015.8.0.

This module provides an interface to the Elastic Compute Cloud (EC2) service from AWS.

The below code creates a key pair:

    create-key-pair:
      boto_ec2.key_present:
        - name: mykeypair
        - save_private: /root/
        - region: eu-west-1
        - keyid: GKTADJGHEIQSXMKKRBJ08H
        - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    import-key-pair:
       boto_ec2.key_present:
        - name: mykeypair
        - upload_public: 'ssh-rsa AAAA'
        - keyid: GKTADJGHEIQSXMKKRBJ08H
        - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

You can also use salt:// in order to define the public key.

    import-key-pair:
       boto_ec2.key_present:
        - name: mykeypair
        - upload_public: salt://mybase/public_key.pub
        - keyid: GKTADJGHEIQSXMKKRBJ08H
        - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

The below code deletes a key pair:

    delete-key-pair:
      boto_ec2.key_absent:
        - name: mykeypair
        - region: eu-west-1
        - keyid: GKTADJGHEIQSXMKKRBJ08H
        - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

salt.states.boto_ec2.eni_absent(name, release_eip=False, region=None, key=None, keyid=None, profile=None)

  Ensure the EC2 ENI is absent.

  New in version 2016.3.0.

  name

    Name tag associated with the ENI.

  release_eip

    True/False - release any EIP associated with the ENI

  region

    Region to connect to.

  key

    Secret key to be used.

  keyid

    Access key to be used.

  profile

    A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.eni_present(name, subnet_id=None, subnet_name=None, private_ip_address=None, description=None, groups=None, source_dest_check=True, allocate_eip=None, arecords=None, region=None, key=None, keyid=None, profile=None)

  Ensure the EC2 ENI exists.

  New in version 2016.3.0.

  name

    Name tag associated with the ENI.

  subnet_id

    The VPC subnet ID the ENI will exist within.

  subnet_name

    The VPC subnet name the ENI will exist within.

  private_ip_address

    The private ip address to use for this ENI. If this is not specified AWS will automatically assign a private IP address to the ENI. Must be specified at creation time; will be ignored afterward.

  description

    Description of the key.

  groups

    A list of security groups to apply to the ENI.

  source_dest_check

    Boolean specifying whether source/destination checking is enabled on the ENI.

  allocate_eip

    allocate and associate an EIP to the ENI. Could be 'standard' to allocate Elastic IP to EC2 region or 'vpc' to get it for a particular VPC

    Changed in version 2016.11.0.

  arecords

    A list of arecord dicts with attributes needed for the DNS add_record state. By default the boto_route53.add_record state will be used, which requires: name, zone, ttl, and identifier. See the boto_route53 state for information about these attributes. Other DNS modules can be called by specifying the provider keyword. By default, the private ENI IP address will be used, set 'public: True' in the arecord dict to use the ENI's public IP address

    New in version 2016.3.0.

  region

    Region to connect to.

  key

    Secret key to be used.

  keyid

    Access key to be used.

  profile

    A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.instance_absent(name, instance_name=None, instance_id=None, release_eip=False, region=None, key=None, keyid=None, profile=None, filters=None)

  Ensure an EC2 instance does not exist (is stopped and removed).

  Changed in version 2016.11.0.

  name

    (string) - The name of the state definition.

  instance_name

    (string) - The name of the instance.

  instance_id

    (string) - The ID of the instance.

  release_eip

    (bool) - Release any associated EIPs during termination.

  region

    (string) - Region to connect to.

  key

    (string) - Secret key to be used.

  keyid

    (string) - Access key to be used.

  profile

    (variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

  filters

    (dict) - A dict of additional filters to use in matching the instance to delete.

  YAML example fragment:

      - filters:
          vpc-id: vpc-abcdef12

salt.states.boto_ec2.instance_present(name, instance_name=None, instance_id=None, image_id=None, image_name=None, tags=None, key_name=None, security_groups=None, user_data=None, instance_type=None, placement=None, kernel_id=None, ramdisk_id=None, vpc_id=None, vpc_name=None, monitoring_enabled=None, subnet_id=None, subnet_name=None, private_ip_address=None, block_device_map=None, disable_api_termination=None, instance_initiated_shutdown_behavior=None, placement_group=None, client_token=None, security_group_ids=None, security_group_names=None, additional_info=None, tenancy=None, instance_profile_arn=None, instance_profile_name=None, ebs_optimized=None, network_interfaces=None, network_interface_name=None, network_interface_id=None, attributes=None, target_state=None, public_ip=None, allocation_id=None, allocate_eip=False, region=None, key=None, keyid=None, profile=None)

  Ensure an EC2 instance is running with the given attributes and state.

  name

    (string) - The name of the state definition. Recommended that this match the instance_name attribute (generally the FQDN of the instance).

  instance_name

    (string) - The name of the instance, generally its FQDN. Exclusive with 'instance_id'.

  instance_id

    (string) - The ID of the instance (if known). Exclusive with 'instance_name'.

  image_id

    (string) – The ID of the AMI image to run.

  image_name

    (string) – The name of the AMI image to run.

  tags

    (dict) - Tags to apply to the instance.

  key_name

    (string) – The name of the key pair with which to launch instances.

  security_groups

    (list of strings) – The names of the EC2 classic security groups with which to associate instances

  user_data

    (string) – The Base64-encoded MIME user data to be made available to the instance(s) in this reservation.

  instance_type

    (string) – The EC2 instance size/type. Note that only certain types are compatible with HVM based AMIs.

  placement

    (string) – The Availability Zone to launch the instance into.

  kernel_id

    (string) – The ID of the kernel with which to launch the instances.

  ramdisk_id

    (string) – The ID of the RAM disk with which to launch the instances.

  vpc_id

    (string) - The ID of a VPC to attach the instance to.

  vpc_name

    (string) - The name of a VPC to attach the instance to.

  monitoring_enabled

    (bool) – Enable detailed CloudWatch monitoring on the instance.

  subnet_id

    (string) – The ID of the subnet within which to launch the instances for VPC.

  subnet_name

    (string) – The name of the subnet within which to launch the instances for VPC.

  private_ip_address

    (string) – If you’re using VPC, you can optionally use this parameter to assign the instance a specific available IP address from the subnet (e.g., 10.0.0.25).

  block_device_map

    (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.

  disable_api_termination

    (bool) – If True, the instances will be locked and will not be able to be terminated via the API.

  instance_initiated_shutdown_behavior

    (string) – Specifies whether the instance stops or terminates on instance-initiated shutdown. Valid values are:

    - 'stop'

    - 'terminate'

  placement_group

    (string) – If specified, this is the name of the placement group in which the instance(s) will be launched.

  client_token

    (string) – Unique, case-sensitive identifier you provide to ensure idempotency of the request. Maximum 64 ASCII characters.

  security_group_ids

    (list of strings) – The IDs of the VPC security groups with which to associate instances.

  security_group_names

    (list of strings) – The names of the VPC security groups with which to associate instances.

  additional_info

    (string) – Specifies additional information to make available to the instance(s).

  tenancy

    (string) – The tenancy of the instance you want to launch. An instance with a tenancy of ‘dedicated’ runs on single-tenant hardware and can only be launched into a VPC. Valid values are:”default” or “dedicated”. NOTE: To use dedicated tenancy you MUST specify a VPC subnet-ID as well.

  instance_profile_arn

    (string) – The Amazon resource name (ARN) of the IAM Instance Profile (IIP) to associate with the instances.

  instance_profile_name

    (string) – The name of the IAM Instance Profile (IIP) to associate with the instances.

  ebs_optimized

    (bool) – Whether the instance is optimized for EBS I/O. This optimization provides dedicated throughput to Amazon EBS and a tuned configuration stack to provide optimal EBS I/O performance. This optimization isn’t available with all instance types.

  network_interfaces

    (boto.ec2.networkinterface.NetworkInterfaceCollection) – A NetworkInterfaceCollection data structure containing the ENI specifications for the instance.

  network_interface_name

    > (string) - The name of Elastic Network Interface to attach

    New in version 2016.11.0.

  network_interface_id

    > (string) - The id of Elastic Network Interface to attach

    New in version 2016.11.0.

  attributes

    (dict) - Instance attributes and value to be applied to the instance. Available options are:

    - instanceType - A valid instance type (m1.small)

    - kernel - Kernel ID (None)

    - ramdisk - Ramdisk ID (None)

    - userData - Base64 encoded String (None)

    - disableApiTermination - Boolean (true)

    - instanceInitiatedShutdownBehavior - stop|terminate

    - blockDeviceMapping - List of strings - ie: [‘/dev/sda=false’]

    - sourceDestCheck - Boolean (true)

    - groupSet - Set of Security Groups or IDs

    - ebsOptimized - Boolean (false)

    - sriovNetSupport - String - ie: ‘simple’

  target_state

    (string) - The desired target state of the instance. Available options are:

    - running

    - stopped

    Note that this option is currently UNIMPLEMENTED.

  public_ip:

    (string) - The IP of a previously allocated EIP address, which will be attached to the instance. EC2 Classic instances ONLY - for VCP pass in an allocation_id instead.

  allocation_id:

    (string) - The ID of a previously allocated EIP address, which will be attached to the instance. VPC instances ONLY - for Classic pass in a public_ip instead.

  allocate_eip:

    (bool) - Allocate and attach an EIP on-the-fly for this instance. Note you'll want to release this address when terminating the instance, either manually or via the 'release_eip' flag to 'instance_absent'.

  region

    (string) - Region to connect to.

  key

    (string) - Secret key to be used.

  keyid

    (string) - Access key to be used.

  profile

    (variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

  New in version 2016.3.0.

salt.states.boto_ec2.key_absent(name, region=None, key=None, keyid=None, profile=None)

  Deletes a key pair

salt.states.boto_ec2.key_present(name, save_private=None, upload_public=None, region=None, key=None, keyid=None, profile=None)

  Ensure key pair is present.

salt.states.boto_ec2.private_ips_absent(name, network_interface_name=None, network_interface_id=None, private_ip_addresses=None, region=None, key=None, keyid=None, profile=None)

  Ensure an ENI does not have secondary private ip addresses associated with it

  name

    (String) - State definition name

  network_interface_id

    (String) - The EC2 network interface id, example eni-123456789

  private_ip_addresses

    (List or String) - The secondary private ip address(es) that should be absent on the ENI.

  region

    (string) - Region to connect to.

  key

    (string) - Secret key to be used.

  keyid

    (string) - Access key to be used.

  profile

    (variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.private_ips_present(name, network_interface_name=None, network_interface_id=None, private_ip_addresses=None, allow_reassignment=False, region=None, key=None, keyid=None, profile=None)

  Ensure an ENI has secondary private ip addresses associated with it

  name

    (String) - State definition name

  network_interface_id

    (String) - The EC2 network interface id, example eni-123456789

  private_ip_addresses

    (List or String) - The secondary private ip address(es) that should be present on the ENI.

  allow_reassignment

    (Boolean) - If true, will reassign a secondary private ip address associated with another ENI. If false, state will fail if the secondary private ip address is associated with another ENI.

  region

    (string) - Region to connect to.

  key

    (string) - Secret key to be used.

  keyid

    (string) - Access key to be used.

  profile

    (variable) - A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.snapshot_created(name, ami_name, instance_name, wait_until_available=True, wait_timeout_seconds=300, **kwargs)

  Create a snapshot from the given instance

  New in version 2016.3.0.

salt.states.boto_ec2.volume_absent(name, volume_name=None, volume_id=None, instance_name=None, instance_id=None, device=None, region=None, key=None, keyid=None, profile=None)

  Ensure the EC2 volume is detached and absent.

  New in version 2016.11.0.

  name

    State definition name.

  volume_name

    Name tag associated with the volume. For safety, if this matches more than one volume, the state will refuse to apply.

  volume_id

    Resource ID of the volume.

  instance_name

    Only remove volume if it is attached to instance with this Name tag. Exclusive with 'instance_id'. Requires 'device'.

  instance_id

    Only remove volume if it is attached to this instance. Exclusive with 'instance_name'. Requires 'device'.

  device

    Match by device rather than ID. Requires one of 'instance_name' or 'instance_id'.

  region

    Region to connect to.

  key

    Secret key to be used.

  keyid

    Access key to be used.

  profile

    A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.volume_present(name, volume_name=None, volume_id=None, instance_name=None, instance_id=None, device=None, size=None, snapshot_id=None, volume_type=None, iops=None, encrypted=False, kms_key_id=None, region=None, key=None, keyid=None, profile=None)

  Ensure the EC2 volume is present and attached.

  name

    State definition name.

  volume_name

    The Name tag value for the volume. If no volume with that matching name tag is found, a new volume will be created. If multiple volumes are matched, the state will fail.

  volume_id

    Resource ID of the volume. Exclusive with 'volume_name'.

  instance_name

    Attach volume to instance with this Name tag. Exclusive with 'instance_id'.

  instance_id

    Attach volume to instance with this ID. Exclusive with 'instance_name'.

  device

    The device on the instance through which the volume is exposed (e.g. /dev/sdh)

  size

    The size of the new volume, in GiB. If you're creating the volume from a snapshot and don't specify a volume size, the default is the snapshot size. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.

  snapshot_id

    The snapshot ID from which the new Volume will be created. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.

  volume_type

    The type of the volume. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'. Valid volume types for AWS can be found here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html

  iops

    The provisioned IOPS you want to associate with this volume. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.

  encrypted

    Specifies whether the volume should be encrypted. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'.

  kms_key_id

    If encrypted is True, this KMS Key ID may be specified to encrypt volume with this key. Optionally specified at volume creation time; will be ignored afterward. Requires 'volume_name'. e.g.: arn:aws:kms:us-east-1:012345678910:key/abcd1234-a123-456a-a12b-a123b4cd56ef

  region

    Region to connect to.

  key

    Secret key to be used.

  keyid

    Access key to be used.

  profile

    A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.

salt.states.boto_ec2.volumes_tagged(name, tag_maps, authoritative=False, region=None, key=None, keyid=None, profile=None)

  Ensure EC2 volume(s) matching the given filters have the defined tags.

  New in version 2016.11.0.

  name

    State definition name.

  tag_maps

    List of dicts of filters and tags, where 'filters' is a dict suitable for passing to the 'filters' argument of boto_ec2.get_all_volumes(), and 'tags' is a dict of tags to be set on volumes as matched by the given filters. The filter syntax is extended to permit passing either a list of volume_ids or an instance_name (with instance_name being the Name tag of the instance to which the desired volumes are mapped). Each mapping in the list is applied separately, so multiple sets of volumes can be all tagged differently with one call to this function.

  YAML example fragment:

      - filters:
          attachment.instance_id: i-abcdef12
        tags:
          Name: dev-int-abcdef12.aws-foo.com
      - filters:
          attachment.device: /dev/sdf
        tags:
          ManagedSnapshots: true
          BillingGroup: bubba.hotep@aws-foo.com
      - filters:
          instance_name: prd-foo-01.aws-foo.com
        tags:
          Name: prd-foo-01.aws-foo.com
          BillingGroup: infra-team@aws-foo.com
      - filters:
          volume_ids: [ vol-12345689, vol-abcdef12 ]
        tags:
          BillingGroup: infra-team@aws-foo.com

  authoritative

    Should un-declared tags currently set on matched volumes be deleted? Boolean.

  region

    Region to connect to.

  key

    Secret key to be used.

  keyid

    Access key to be used.

  profile

    A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key and keyid.