| 1 |
- name: Configure pre-requisites for test, VPC and KMS resources |
| 2 |
block: |
| 3 |
- name: Create VPC for use in testing |
| 4 |
ec2_vpc_net: |
| 5 |
name: "{{ tiny_prefix }}-vpc" |
| 6 |
state: present |
| 7 |
cidr_block: 10.55.0.0/16 |
| 8 |
tenancy: default |
| 9 |
tags: |
| 10 |
AnsibleEIPTest: "{{ tiny_prefix }}-vpc" |
| 11 |
AnsibleTest: AnsibleTestVpc |
| 12 |
register: testing_vpc |
| 13 |
|
| 14 |
- name: Wait until VPC is created. |
| 15 |
ec2_vpc_net_info: |
| 16 |
filters: |
| 17 |
tag:AnsibleEIPTest: |
| 18 |
- "{{ tiny_prefix }}-vpc" |
| 19 |
register: vpc_info |
| 20 |
retries: 120 |
| 21 |
delay: 5 |
| 22 |
until: |
| 23 |
- vpc_info.vpcs | length > 0 |
| 24 |
- vpc_info.vpcs[0].state == 'available' |
| 25 |
|
| 26 |
- name: Create internet gateway for use in testing |
| 27 |
ec2_vpc_igw: |
| 28 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 29 |
state: present |
| 30 |
resource_tags: |
| 31 |
Name: "{{ tiny_prefix }}-igw" |
| 32 |
AnsibleTest: AnsibleTestVpc |
| 33 |
register: igw |
| 34 |
|
| 35 |
# The list of AZs varies across regions and accounts. |
| 36 |
# Gather info and pick two AZs for test purpose. |
| 37 |
- name: gather AZ info in VPC for test purpose |
| 38 |
amazon.aws.aws_az_info: |
| 39 |
region: "{{ aws_region }}" |
| 40 |
register: az_info |
| 41 |
- assert: |
| 42 |
that: |
| 43 |
# We cannot run the test if this region does not have at least 2 AZs |
| 44 |
- "az_info.availability_zones | length >= 2" |
| 45 |
- set_fact: |
| 46 |
test_az_zone1: "{{ az_info.availability_zones[0].zone_name }}" |
| 47 |
test_az_zone2: "{{ az_info.availability_zones[1].zone_name }}" |
| 48 |
- name: Create subnet_1 for use in testing |
| 49 |
ec2_vpc_subnet: |
| 50 |
state: present |
| 51 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 52 |
cidr: 10.55.77.0/24 |
| 53 |
az: "{{ test_az_zone1 }}" |
| 54 |
resource_tags: |
| 55 |
Name: "{{ tiny_prefix }}-subnet_1" |
| 56 |
AnsibleTest: AnsibleTestVpc |
| 57 |
wait: true |
| 58 |
register: testing_subnet_1 |
| 59 |
|
| 60 |
- name: Create subnet_2 for use in testing |
| 61 |
ec2_vpc_subnet: |
| 62 |
state: present |
| 63 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 64 |
cidr: 10.55.78.0/24 |
| 65 |
az: "{{ test_az_zone2 }}" |
| 66 |
resource_tags: |
| 67 |
Name: "{{ tiny_prefix }}-subnet_2" |
| 68 |
AnsibleTest: AnsibleTestVpc |
| 69 |
wait: true |
| 70 |
register: testing_subnet_2 |
| 71 |
|
| 72 |
- name: Create routing rules |
| 73 |
ec2_vpc_route_table: |
| 74 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 75 |
routes: |
| 76 |
- dest: 0.0.0.0/0 |
| 77 |
gateway_id: "{{ igw.gateway_id }}" |
| 78 |
subnets: |
| 79 |
- "{{ testing_subnet_1.subnet.id }}" |
| 80 |
- "{{ testing_subnet_2.subnet.id }}" |
| 81 |
tags: |
| 82 |
Name: "{{ tiny_prefix }}-route" |
| 83 |
AnsibleTest: AnsibleTestVpc |
| 84 |
|
| 85 |
- name: Create security group for use in testing |
| 86 |
ec2_security_group: |
| 87 |
name: "{{ tiny_prefix }}-sg" |
| 88 |
description: a security group for ansible tests |
| 89 |
vpc_id: "{{ testing_vpc.vpc.id }}" |
| 90 |
tags: |
| 91 |
Name: "{{ tiny_prefix }}-sg" |
| 92 |
AnsibleTest: AnsibleTestVpc |
| 93 |
rules: |
| 94 |
- proto: tcp |
| 95 |
from_port: 22 |
| 96 |
to_port: 22 |
| 97 |
cidr_ip: 0.0.0.0/0 |
| 98 |
- proto: tcp |
| 99 |
from_port: 80 |
| 100 |
to_port: 80 |
| 101 |
cidr_ip: 0.0.0.0/0 |
| 102 |
register: sg |
| 103 |
|
| 104 |
# A private route53 zone is needed to configure a custom endpoint in the OpenSearch cluster. |
| 105 |
# See https://docs.aws.amazon.com/opensearch-service/latest/developerguide/customendpoint.html |
| 106 |
- name: Create private Route53 zone for the VPC |
| 107 |
register: route53_zone |
| 108 |
route53_zone: |
| 109 |
comment: "zone for ansible integration tests" |
| 110 |
zone: "ansible-integ-test.com" |
| 111 |
state: present |
| 112 |
vpc_id: '{{ testing_vpc.vpc.id }}' |
| 113 |
tags: |
| 114 |
Name: "{{ tiny_prefix }}-zone" |
| 115 |
AnsibleTest: AnsibleTestVpc |
| 116 |
|
| 117 |
- name: Set fact for route53 zone id |
| 118 |
set_fact: |
| 119 |
route53_zone_id: "{{ route53_zone.result.zone_id }}" |
| 120 |
|
| 121 |
- name: Create KMS key for test purpose |
| 122 |
# The key is needed for OpenSearch encryption at rest. |
| 123 |
kms_key: |
| 124 |
alias: "{{ tiny_prefix }}-kms" |
| 125 |
description: a key used for encryption at rest in test OpenSearch cluster |
| 126 |
state: present |
| 127 |
enabled: yes |
| 128 |
key_spec: SYMMETRIC_DEFAULT |
| 129 |
key_usage: ENCRYPT_DECRYPT |
| 130 |
policy: "{{ lookup('template', 'kms_policy.j2') }}" |
| 131 |
tags: |
| 132 |
Name: "{{ tiny_prefix }}-kms" |
| 133 |
AnsibleTest: AnsibleTestVpc |
| 134 |
register: kms_test_key |