diff --git a/roles/ec2_instance_create/README.md b/roles/ec2_instance_create/README.md index aa2b4ac..7751556 100644 --- a/roles/ec2_instance_create/README.md +++ b/roles/ec2_instance_create/README.md @@ -37,10 +37,6 @@ The following variables can be set in the role to customize EC2 instance creatio * **ec2_instance_create_vpc_subnet_id**: (Required) The ID of the VPC subnet in which the instance will be launched. - * **ec2_instance_create_vpc_id**: (Optional) - The ID of the VPC used for security group and internet gateway. - Required if `ec2_instance_create_associate_external_sg` is `true` or `ec2_instance_create_associate_igw` is `true`. - * **ec2_instance_create_external_sg_id**: (Optional) The ID or name of the existing security group to be associated with EC2 instance. Mutually exclusive with `ec2_instance_create_associate_external_sg`. @@ -49,12 +45,16 @@ The following variables can be set in the role to customize EC2 instance creatio A dictionary of tags to assign to the EC2 instance. * **ec2_instance_create_wait_for_boot**: (Optional) - Whether to wait for the EC2 instance to be in the "running" state before continuing. Default is `true`. + Whether to wait for the EC2 instance to be in the "running" or "terminated" state before continuing. Default is `true`. ### Optional Networking Resources #### Elastic IP +* **ec2_instance_create_vpc_id**: (Optional) + The ID of the VPC used for security group and internet gateway. + Required if `ec2_instance_create_associate_external_sg` is `true` or `ec2_instance_create_associate_igw` is `true`. + * **ec2_instance_create_associate_eip**: (Optional) Whether to create an Elastic IP (EIP) and associate it with the EC2 instance. Default is `false`. If set to `true` and provided VPC doesn't have an Internet Gateway (IGW) attached, please set `ec2_instance_create_associate_igw` to true to avoid failure due to VPC not having IGW attached. diff --git a/roles/ec2_instance_create/defaults/main.yml b/roles/ec2_instance_create/defaults/main.yml index 59aef90..1a9bad1 100644 --- a/roles/ec2_instance_create/defaults/main.yml +++ b/roles/ec2_instance_create/defaults/main.yml @@ -1,4 +1,5 @@ --- +ec2_instance_create_operation: create ec2_instance_create_associate_eip: false ec2_instance_create_associate_external_sg: false ec2_instance_create_associate_igw: false diff --git a/roles/ec2_instance_create/tasks/ec2_instance_create_operations.yml b/roles/ec2_instance_create/tasks/ec2_instance_create_operations.yml index a26833b..0c6e903 100644 --- a/roles/ec2_instance_create/tasks/ec2_instance_create_operations.yml +++ b/roles/ec2_instance_create/tasks/ec2_instance_create_operations.yml @@ -7,7 +7,7 @@ Please provide only one to either associate existing or create new sg." when: ec2_instance_create_external_sg_id is defined and ec2_instance_create_associate_external_sg is defined and ec2_instance_create_external_sg_id != None and ec2_instance_create_associate_external_sg is true -- name: Verify that the instance and security group with same name does not exist +- name: Verify that an instance with same name does not exist block: - name: Get instane info with provided name amazon.aws.ec2_instance_info: @@ -56,8 +56,8 @@ block: - name: Define security group amazon.aws.ec2_security_group: - name: "{{ ec2_instance_create_external_sg_name | default('ec2_instance_create-default-external-sg') }}" - description: "{{ ec2_instance_create_external_sg_description | default('Security group for external access') }}" + name: "{{ ec2_instance_create_external_sg_name }}" + description: "{{ ec2_instance_create_external_sg_description }}" vpc_id: "{{ ec2_instance_create_vpc_id }}" rules: "{{ ec2_instance_create_external_sg_rules }}" tags: "{{ ec2_instance_create_sg_tags | default(omit) }}" @@ -68,7 +68,7 @@ instance_ids: - "{{ ec2_instance.instance_ids[0] }}" security_groups: - - "{{ ec2_instance_create_external_sg_name | default('ec2_instance_create-default-external-sg') }}" + - "{{ ec2_instance_create_external_sg_name }}" vpc_subnet_id: "{{ ec2_instance_create_vpc_subnet_id }}" register: ec2_instance_associate_external_sg