Skip to content

Commit

Permalink
Several ec2_instance are running using t3.micro, but for some of them…
Browse files Browse the repository at this point in the history
… this is not required
  • Loading branch information
abikouo committed Jun 28, 2024
1 parent 90fe780 commit 01cf57a
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_block_devices
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-block-devices"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_checkmode_tests
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-checkmode"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_cpu_options
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-cpu-options"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_default_vpc
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-default-vpc"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_ebs_optimized
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-ebs-optimized"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# defaults file for ec2_instance_iam_instance_profile
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-profile"

first_iam_role: ansible-test-{{ tiny_prefix }}-instance_role
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_minimal
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-minimal"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_multiple
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-multiple"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_no_wait
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-no-wait"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# defaults file for ec2_instance_block_devices
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-license-specifications"
ec2_host_resource_group_arn: arn:aws:resource-groups:{{ aws_region }}:123456789012:group/{{ resource_prefix }}-resource-group
ec2_license_configuration_arn: arn:aws:license-manager:{{ aws_region }}:123456789012:license-configuration:lic-0123456789
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_metadata_options
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-metadata"
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@
session_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:
- name: New placement group
community.aws.ec2_placement_group:
name: "{{ ec2_placement_group_name }}"
strategy: partition
partition_count: 1
state: present
# - name: New placement group
# community.aws.ec2_placement_group:
# name: "{{ ec2_placement_group_name }}"
# strategy: partition
# partition_count: 1
# state: present

- name: New instance with placement group name
amazon.aws.ec2_instance:
state: running
name: "{{ resource_prefix }}-test-placement-group-name"
image_id: "{{ ec2_ami_id }}"
placement:
group_name: "{{ ec2_placement_group_name }}"
tags:
Name: "{{ resource_prefix }}-test-placement-group-name"
TestId: "{{ ec2_instance_tag_TestId }}"
security_group: default
instance_type: "{{ ec2_instance_type }}"
wait: true
ignore_errors: true
register: instance_creation
# - name: New instance with placement group name
# amazon.aws.ec2_instance:
# state: running
# name: "{{ resource_prefix }}-test-placement-group-name"
# image_id: "{{ ec2_ami_id }}"
# placement:
# group_name: "{{ ec2_placement_group_name }}"
# tags:
# Name: "{{ resource_prefix }}-test-placement-group-name"
# TestId: "{{ ec2_instance_tag_TestId }}"
# security_group: default
# instance_type: "t2.micro"
# wait: true
# ignore_errors: true
# register: instance_creation

- name: Gather ec2 facts to check placement group options
amazon.aws.ec2_instance_info:
filters:
tag:Name: "{{ resource_prefix }}-test-placement-group-name"
tag:TestId: "{{ ec2_instance_tag_TestId }}"
instance-state-name: running
ignore_errors: true
register: instance_facts
# - name: Gather ec2 facts to check placement group options
# amazon.aws.ec2_instance_info:
# filters:
# tag:Name: "{{ resource_prefix }}-test-placement-group-name"
# tag:TestId: "{{ ec2_instance_tag_TestId }}"
# instance-state-name: running
# ignore_errors: true
# register: instance_facts

- name: Validate instance with placement group name
ansible.builtin.assert:
that:
- instance_creation is success
- instance_creation is changed
- instance_facts.instances[0].placement.group_name == ec2_placement_group_name
# - instance_creation is failed
# - '"You are not authorized to perform this operation." in instance_creation.msg'
# - name: Validate instance with placement group name
# ansible.builtin.assert:
# that:
# - instance_creation is success
# - instance_creation is changed
# - instance_facts.instances[0].placement.group_name == ec2_placement_group_name
# # - instance_creation is failed
# # - '"You are not authorized to perform this operation." in instance_creation.msg'

- name: New instance with dedicated tenancy
amazon.aws.ec2_instance:
Expand All @@ -61,6 +61,9 @@
wait: true
ignore_errors: true
register: instance_creation
retries: 5
delay: 30
until: instance_creation is success

- name: Gather ec2 facts to check placement tenancy
amazon.aws.ec2_instance_info:
Expand All @@ -79,3 +82,9 @@
- instance_facts.instances[0].placement.tenancy == ec2_tenancy
# - instance_creation is failed
# - '"You are not authorized to perform this operation." in instance_creation.msg'
always:
- name: New placement group
community.aws.ec2_placement_group:
name: "{{ ec2_placement_group_name }}"
state: absent
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_security_group
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-sg"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_state_config_updates
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-state-config-updates"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_tags_and_vpc_settings
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-tags-vpc"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_termination_protection
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-temination"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_uptime
ec2_instance_type: t3.micro
ec2_instance_type: t2.micro
ec2_instance_tag_TestId: "{{ resource_prefix }}-instance-uptime"

0 comments on commit 01cf57a

Please sign in to comment.