Skip to content

Commit 2c476c6

Browse files
committed
Update AWS VPC and subnet ID assignment to support runlevel, then upstream, and finally discovery
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent 86866a8 commit 2c476c6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

roles/platform/tasks/initialize_setup_aws.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
plat__aws_xaccount_external_id: "{{ plat__cdp_xaccount_external_id }}"
4848
plat__aws_xaccount_account_id: "{{ plat__cdp_xaccount_account_id }}"
4949

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 or established by Infrastructure
52+
when: plat__aws_vpc_id == "" and infra__aws_vpc_id is undefined
5353
block:
54-
- name: Query AWS VPC
54+
- name: Query AWS VPC by name
5555
amazon.aws.ec2_vpc_net_info:
5656
region: "{{ plat__region }}"
5757
filters:
@@ -63,19 +63,19 @@
6363
ansible.builtin.set_fact:
6464
plat__aws_vpc_id: "{{ __aws_vpc_info.vpcs[0].id }}"
6565

66-
- name: Set fact for AWS VPC ID by assignment
67-
when: infra__aws_vpc_id is defined
66+
- name: Set fact for AWS VPC ID if established by Infrastructure
67+
when: plat__aws_vpc_id == "" and infra__aws_vpc_id is defined
6868
ansible.builtin.set_fact:
6969
plat__aws_vpc_id: "{{ infra__aws_vpc_id }}"
7070

71-
- name: Discover AWS VPC Subnets
72-
when: infra__aws_subnet_ids is undefined
71+
- name: Handle AWS Subnet IDs if not defined
72+
when: not plat__aws_public_subnet_ids or not plat__aws_private_subnet_ids # Defaults are empty lists
7373
block:
7474
- name: Query AWS Subnets
7575
amazon.aws.ec2_vpc_subnet_info:
7676
region: "{{ plat__region }}"
7777
filters:
78-
"tag:Name": "{{ plat__namespace }}"
78+
vpc-id: "{{ plat__aws_vpc_id }}"
7979
register: __aws_subnets_info
8080

8181
- name: Assert discovered AWS Subnets
@@ -131,13 +131,15 @@
131131
plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}"
132132
plat__endpoint_access_scheme: "PUBLIC"
133133

134+
# TODO Collapse the two SG queries together
134135
- name: Discover AWS Security Group for Knox
135136
when: infra__aws_security_group_knox_id is undefined
136137
block:
137138
- name: Query AWS Security Group for Knox
138139
amazon.aws.ec2_group_info:
139140
region: "{{ plat__region }}"
140141
filters:
142+
vpc-id: "{{ plat__aws_vpc_id }}"
141143
group-name: "{{ plat__security_group_knox_name }}"
142144
register: __aws_security_group_knox_info
143145

@@ -158,6 +160,7 @@
158160
amazon.aws.ec2_group_info:
159161
region: "{{ plat__region }}"
160162
filters:
163+
vpc-id: "{{ plat__aws_vpc_id }}"
161164
group-name: "{{ plat__security_group_default_name }}"
162165
register: __aws_security_group_default_info
163166

0 commit comments

Comments
 (0)