|
| 1 | +--- |
| 2 | +# Create an RDS instance. |
| 3 | +- hosts: "_{{ _aws_resource_name | regex_replace('-', '_') }}" |
| 4 | + connection: local |
| 5 | + become: false |
| 6 | + |
| 7 | + vars: |
| 8 | + _init: |
| 9 | + vars_dirs: |
| 10 | + - "{{ _ce_provision_build_dir }}/vars/_global" |
| 11 | + - "{{ _ce_provision_build_dir }}/vars/_regions/{{ _aws_region }}/_common" |
| 12 | + - "{{ _ce_provision_build_dir }}/vars/_regions/{{ _aws_region }}/{{ _env_type }}" |
| 13 | + - "{{ _ce_provision_build_dir }}/vars/{{ _aws_resource_name }}" |
| 14 | + |
| 15 | + tasks: |
| 16 | + - ansible.builtin.import_role: |
| 17 | + name: _init |
| 18 | + |
| 19 | + # Automate subnet fetching |
| 20 | + - name: Create empty var to hold subnet IDs. |
| 21 | + ansible.builtin.set_fact: |
| 22 | + _aws_rds_vpc_subnet_ids: [] |
| 23 | + |
| 24 | + - name: Gather VPC information. |
| 25 | + amazon.aws.ec2_vpc_net_info: |
| 26 | + profile: "{{ aws_rds.aws_profile }}" |
| 27 | + region: "{{ aws_rds.region }}" |
| 28 | + filters: |
| 29 | + "tag:Name": "{{ _infra_name }}" |
| 30 | + register: _aws_rds_vpc |
| 31 | + |
| 32 | + - name: Set the VPC id from name. |
| 33 | + ansible.builtin.set_fact: |
| 34 | + _aws_rds_vpc_id: "{{ _aws_rds_vpc.vpcs[0].vpc_id }}" |
| 35 | + |
| 36 | + - name: Gather public subnet information. |
| 37 | + amazon.aws.ec2_vpc_subnet_info: |
| 38 | + profile: "{{ aws_rds.aws_profile }}" |
| 39 | + region: "{{ aws_rds.region }}" |
| 40 | + filters: |
| 41 | + vpc-id: "{{ _aws_rds_vpc_id }}" |
| 42 | + tag:Env: "{{ _env_type }}" |
| 43 | + tag:Profile: "core" |
| 44 | + register: _aws_rds_vpc_subnets |
| 45 | + |
| 46 | + - name: Place subnet IDs in a list. |
| 47 | + ansible.builtin.set_fact: |
| 48 | + _aws_rds_vpc_subnet_ids: "{{ _aws_rds_vpc_subnet_ids + [item.subnet_id] }}" |
| 49 | + loop: "{{ _aws_rds_vpc_subnets.subnets }}" |
| 50 | + |
| 51 | + # Build the RDS instance. |
| 52 | + - ansible.builtin.import_role: |
| 53 | + name: aws/aws_rds |
| 54 | + |
| 55 | + - ansible.builtin.import_role: |
| 56 | + name: _exit |
0 commit comments