Skip to content

Commit

Permalink
fix terminate task
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar242 committed Nov 25, 2024
1 parent ca18ea3 commit 5c272d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
22 changes: 22 additions & 0 deletions roles/ec2_instance_create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Here's an example of how to use the role in a playbook.
Component: my-test-instance
Environment: Testing
ec2_instance_create_wait_for_boot: true
ec2_instance_create_vpc_id: vpc-xxxx
# Optionally, enable security group creation
ec2_instance_create_associate_external_sg: true
ec2_instance_create_external_sg_name: my-custom-sg
Expand All @@ -128,6 +129,27 @@ Here's an example of how to use the role in a playbook.
ec2_instance_create_eip_tags:
Component: my-custom-eip
Environment: Testing
# Optionally, enable Internet Gateway association
ec2_instance_create_associate_igw: true
ec2_instance_create_igw_tags:
Environment: Testing
Name: "{{ resource_prefix }}-igw"

---
- name: Playbook for deleting EC2 instance and other role resources using cloud.aws_ops.ec2_instance_create role
hosts: localhost
gather_facts: false
roles:
- role: cloud.aws_ops.ec2_instance_create
vars:
ec2_instance_create_operation: delete
ec2_instance_create_aws_region: us-west-2
ec2_instance_create_instance_name: my-test-instance
ec2_instance_create_wait_for_boot: true
ec2_instance_create_associate_external_sg: true
ec2_instance_create_external_sg_name: my-custom-sg
ec2_instance_create_associate_igw: true
ec2_instance_create_vpc_id: vpc-xxxx

License
-------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
---
- name: Terminate EC2 instance
- name: Terminate EC2 Instance
amazon.aws.ec2_instance:
region: "{{ ec2_instance_create_aws_region }}"
name: "{{ ec2_instance_create_instance_name }}"
instance_type: "{{ ec2_instance_create_instance_type }}"
image_id: "{{ ec2_instance_create_ami_id }}"
key_name: "{{ ec2_instance_create_key_name }}"
vpc_subnet_id: "{{ ec2_instance_create_vpc_subnet_id }}"
security_group: "{{ ec2_instance_create_external_sg_id | default(omit) }}"
tags: "{{ ec2_instance_create_tags | default(omit) }}"
wait: "{{ ec2_instance_create_wait_for_boot }}"
state: absent
wait: "{{ ec2_instance_create_wait_for_boot }}"
filters:
tag:Name: "{{ ec2_instance_create_instance_name }}"
instance-state-name: ["running"]
when: ec2_instance_create_instance_name is defined and ec2_instance_create_instance_name | length > 0

- name: Delete security group if created
Expand Down

0 comments on commit 5c272d9

Please sign in to comment.