|
47 | 47 | plat__aws_xaccount_external_id: "{{ plat__cdp_xaccount_external_id }}" |
48 | 48 | plat__aws_xaccount_account_id: "{{ plat__cdp_xaccount_account_id }}" |
49 | 49 |
|
50 | | -# TODO - Confirm the two following tasks are the design pattern we want: checking for a set_fact from another role before establishing its own role fact |
51 | | -- name: Discover AWS VPC |
52 | | - when: infra__aws_vpc_id is undefined |
| 50 | +# Runlevel first, upstream second, and discover third |
| 51 | +- name: Discover AWS VPC if not defined |
| 52 | + when: plat__aws_vpc_id == "" and infra__aws_vpc_id is undefined |
53 | 53 | block: |
54 | | - - name: Query AWS VPC |
| 54 | + - name: Query AWS VPC by name |
55 | 55 | amazon.aws.ec2_vpc_net_info: |
56 | 56 | region: "{{ plat__region }}" |
57 | 57 | filters: |
58 | 58 | "tag:Name": "{{ plat__vpc_name }}" |
59 | 59 | register: __aws_vpc_info |
60 | 60 |
|
| 61 | + - name: Assert discovered AWS VPC |
| 62 | + ansible.builtin.assert: |
| 63 | + that: __aws_vpc_info.vpcs | length == 1 |
| 64 | + fail_msg: "No AWS VPC discovered" |
| 65 | + quiet: yes |
| 66 | + |
61 | 67 | - name: Set fact for AWS VPC ID |
62 | 68 | when: __aws_vpc_info is defined |
63 | 69 | ansible.builtin.set_fact: |
64 | 70 | plat__aws_vpc_id: "{{ __aws_vpc_info.vpcs[0].id }}" |
65 | 71 |
|
66 | | -- name: Set fact for AWS VPC ID by assignment |
| 72 | +- name: Set fact for AWS VPC ID if established by Infrastructure |
67 | 73 | when: infra__aws_vpc_id is defined |
68 | 74 | ansible.builtin.set_fact: |
69 | 75 | plat__aws_vpc_id: "{{ infra__aws_vpc_id }}" |
70 | 76 |
|
71 | | -- name: Discover AWS VPC Subnets |
72 | | - when: infra__aws_subnet_ids is undefined |
| 77 | +# Runlevel first, upstream second, and discover third |
| 78 | +- name: Handle AWS Public and Private VPC Subnets if not defined |
| 79 | + when: not plat__aws_public_subnet_ids or not plat__aws_private_subnet_ids |
73 | 80 | block: |
74 | 81 | - name: Query AWS Subnets |
75 | 82 | amazon.aws.ec2_vpc_subnet_info: |
76 | 83 | region: "{{ plat__region }}" |
77 | 84 | filters: |
78 | | - "tag:Name": "{{ plat__namespace }}" |
| 85 | + vpc-id: "{{ plat__aws_vpc_id }}" |
79 | 86 | register: __aws_subnets_info |
80 | 87 |
|
81 | 88 | - name: Assert discovered AWS Subnets |
|
120 | 127 | label: "{{ __aws_subnet_item.subnet_id }}" |
121 | 128 | loop: "{{ __aws_subnets_info.subnets | rejectattr('map_public_ip_on_launch') }}" |
122 | 129 |
|
123 | | - - name: Set fact for AWS Private Subnet IDs |
| 130 | + - name: Set fact for AWS Private Subnet IDs |
124 | 131 | ansible.builtin.set_fact: |
125 | 132 | plat__aws_private_subnet_ids: "{{ __aws_private_subnet_ids | default([]) }}" |
126 | 133 |
|
127 | | -# TODO: Discover AWS VPC Public Subnets if infra__ is not present |
| 134 | +- name: Set fact for AWS Subnet IDs and define generic subnet IDs |
| 135 | + ansible.builtin.set_fact: |
| 136 | + plat__aws_subnet_ids: "{{ plat__aws_public_subnet_ids | union(plat__aws_private_subnet_ids) }}" |
| 137 | + plat__public_subnet_ids: "{{ plat__aws_public_subnet_ids }}" |
| 138 | + plat__private_subnet_ids: "{{ plat__aws_private_subnet_ids }}" |
| 139 | + |
| 140 | +# TODO: Move endpoint access scheme to instantiation section |
128 | 141 | - name: Set public subnets for public endpoint access |
129 | 142 | when: plat__public_endpoint_access |
130 | 143 | ansible.builtin.set_fact: |
131 | | - plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}" |
132 | 144 | plat__endpoint_access_scheme: "PUBLIC" |
133 | 145 |
|
134 | 146 | - name: Discover AWS Security Group for Knox |
|
0 commit comments