Skip to content

Commit b1ac8ff

Browse files
committed
Cleanup of Terraform tasks and variables
Signed-off-by: Jim Enright <[email protected]>
1 parent 79f7e0b commit b1ac8ff

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

roles/infrastructure/tasks/setup_terraform.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ansible.builtin.copy:
2424
src: "{{ infra__terraform_template_dir }}/infra/"
2525
dest: "{{ infra__terraform_workspace_dir }}/workspace/infra"
26-
# when: not workdir.stat.exists # TODO: This won't override if any changes to .tf are made. Good or Bad?
26+
# when: not workdir.stat.exists # NOTE: When uncommented won't override workspace dir if any changes to .tf are made.
2727

2828
- name: Copy Terraform infra code to the artefact directory
2929
ansible.builtin.copy:
@@ -59,4 +59,26 @@
5959
ansible.builtin.file:
6060
path: "{{ infra__terraform_workspace_dir }}/workspace/infra"
6161
state: absent
62-
when: infra__terraform_state_storage in ['remote_s3']
62+
when: infra__terraform_state_storage in ['remote_s3']
63+
64+
# If created Utility Instance via Terraform then
65+
# need to get it's info and add to an Ansible host group
66+
- name: Add Utility Instance to host group
67+
when: infra__create_utility_service
68+
block:
69+
- name: Discover the Utility Instance details
70+
community.aws.ec2_instance_info:
71+
region: "{{ infra__region }}"
72+
filters: "{{ __filters | items2dict }}"
73+
vars:
74+
__filters:
75+
- key: "tag:Name"
76+
value: "{{ infra__namespace }}*"
77+
register: __infra_utility_compute_discovered
78+
79+
- name: Add discovered Utility Instance to host group
80+
ansible.builtin.add_host:
81+
hostname: "{{__infra_utility_compute_discovered.instances[0].public_ip_address}}"
82+
ansible_user: "{{ infra__dynamic_inventory_images_default[infra__type][infra__dynamic_inventory_os].user }}"
83+
ansible_ssh_private_key_file: "{{ (infra__private_key_file == '') | ternary(omit, infra__private_key_file) }}"
84+
groupname: cldr_utility

roles/infrastructure/template/aws/infra_aws_storage.tf.j2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
resource "aws_s3_bucket" "{{ __aws_storage_location_item }}" {
55
bucket = "{{ __aws_storage_location_item }}"
66
acl = "private"
7+
8+
{% if infra__teardown_deletes_data %}
79
force_destroy = true
10+
{% else %}
11+
{# TODO: How to skip teardown of this resource if infra__teardown_deletes_data is False #}
12+
lifecycle {
13+
# A Terraform destroy of this resource will result in an error message.
14+
prevent_destroy = true
15+
}
16+
{% endif %}
817

918
tags = merge(var.env_tags,{Name = "{{ __aws_storage_location_item }}"})
1019
}

roles/platform/tasks/setup_aws_terraform_authz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ansible.builtin.copy:
2424
src: "{{ plat__terraform_template_dir }}/plat/"
2525
dest: "{{ plat__terraform_workspace_dir }}/workspace/plat"
26-
# when: not workdir.stat.exists # TODO: This won't override if any changes to .tf are made. Good or Bad?
26+
# when: not workdir.stat.exists # NOTE: When uncommented won't override workspace dir if any changes to .tf are made.
2727

2828
- name: Copy Terraform plat code to the artefact directory
2929
ansible.builtin.copy:

0 commit comments

Comments
 (0)