Skip to content

Commit bac243d

Browse files
authored
Convert terraform related global variables to a dictionary (#82)
Signed-off-by: Jim Enright <jenright@cloudera.com>
1 parent 48b5819 commit bac243d

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
- name: Remove Terraform remote state resources if requested
4242
when:
4343
- globals.infra_deployment_engine == 'terraform'
44-
- globals.terraform_auto_remote_state | bool
45-
- globals.terraform_state_storage in ['remote_s3']
44+
- globals.terraform.auto_remote_state | bool
45+
- globals.terraform.state_storage in ['remote_s3']
4646
ansible.builtin.include_role:
4747
name: cloudera_deploy
4848
tasks_from: auto_terraform_state

readme.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,27 +464,28 @@ Terraform can optionally be used to create the cloud infrastructure. This will a
464464
| `ansible`
465465
| Needs to be set to `terraform` for Terraform-deployment.
466466

467-
|`terraform_base_dir`
467+
4+| The parameters below are specified as keys in the `terraform` dictionary
468+
|`terraform.**base_dir**`
468469
| Top-level directory where all Terraform assets will be placed. Includes processed Jinja template files for Terraform, timestamped artefact of Terraform files and the workspace directory where terraform apply/destroy is run.
469470
| `~/.config/cloudera-deploy/terraform`
470471
|
471472

472-
|`terraform_state_storage`
473+
|`terraform.**state_storage**`
473474
|The type of backend storage to use for the Terraform state.
474475
| `local`
475476
| Current options are `local` or `remote_s3`
476477

477-
|`terraform_auto_remote_state`
478+
|`terraform.**auto_remote_state**`
478479
| Flag to allow Cloudera Deploy automatically provision remote state resources as part of its initialization. This will also teardown these resources during cleanup.
479480
| `False`
480481
|
481482

482-
|`terraform_remote_state_bucket`
483+
|`terraform.**remote_state_bucket**`
483484
|The name of the Terraform state storage bucket.
484485
|
485486
| Required if using `remote_s3` state storage. Value is derived from `name_prefix` if terraform_auto_remote_state is True.
486487

487-
|`terraform_remote_state_lock_table`
488+
|`terraform.**remote_state_lock_table**`
488489
|The name of the table to track locks of remote Terraform state.
489490
|
490491
| Required if using `remote_s3` state storage. Value is derived from `name_prefix` if terraform_auto_remote_state is True.

roles/cloudera_deploy/tasks/auto_terraform_state.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
- name: Resources for remote_s3 state storage
1818
when:
19-
- globals.terraform_state_storage == 'remote_s3'
19+
- globals.terraform.state_storage == 'remote_s3'
2020
block:
2121

2222
# Create or Teardown the resources
2323
- name: AWS Bucket for Remote State Storage
2424
amazon.aws.aws_s3:
2525
region: "{{ globals.region }}"
26-
bucket: "{{ globals.terraform_remote_state_bucket}}"
26+
bucket: "{{ globals.terraform.remote_state_bucket}}"
2727
mode: "{{ ('teardown' not in ansible_run_tags) | ternary('create', 'delete') }}" # Check ansible tag to determine action
2828
permission: private
2929
register: __infra_aws_storage_locations_info
3030

3131
- name: AWS DynamoDB for Remote State Locking
3232
community.aws.dynamodb_table:
3333
region: "{{ globals.region }}"
34-
name: "{{ globals.terraform_remote_state_lock_table }}"
34+
name: "{{ globals.terraform.remote_state_lock_table }}"
3535
read_capacity: 1
3636
write_capacity: 1
3737
hash_key_name: LockID
@@ -43,6 +43,6 @@
4343
ansible.builtin.debug:
4444
msg:
4545
- "Resources for remote_s3 Terraform State created."
46-
- "S3 Bucket Name: {{ globals.terraform_remote_state_bucket}}"
47-
- "DynamoDB Locking Table: {{ globals.terraform_remote_state_lock_table}}"
46+
- "S3 Bucket Name: {{ globals.terraform.remote_state_bucket}}"
47+
- "DynamoDB Locking Table: {{ globals.terraform.remote_state_lock_table}}"
4848
verbosity: 3

roles/cloudera_deploy/tasks/init.yml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,12 @@
175175
region: "{{ infra_region | default(default_infra_region) }}"
176176
infra_deployment_engine: "{{ infra_deployment_engine | default(default_infra_deployment_engine) }}"
177177
infra_type: "{{ infra_type | default(default_infra_type) }}"
178-
terraform_base_dir: "{{ terraform_base_dir | default(default_terraform_base_dir) | expanduser }}"
179-
terraform_state_storage: "{{ terraform_state_storage | default(omit) }}"
180-
terraform_auto_remote_state: "{{ terraform_auto_remote_state | default(False) }}"
181-
terraform_remote_state_bucket: "{{ terraform_remote_state_bucket | default(omit) }}"
182-
terraform_remote_state_lock_table: "{{ terraform_remote_state_lock_table | default(omit) }}"
178+
terraform:
179+
base_dir: "{{ terraform.base_dir | default(default_terraform_base_dir) | expanduser }}"
180+
state_storage: "{{ terraform.state_storage | default(omit) }}"
181+
auto_remote_state: "{{ terraform.auto_remote_state | default(False) }}"
182+
remote_state_bucket: "{{ terraform.remote_state_bucket | default(omit) }}"
183+
remote_state_lock_table: "{{ terraform.remote_state_lock_table | default(omit) }}"
183184
ssh:
184185
public_key_id: "{{ public_key_id | default(omit) }}"
185186
public_key_file: "{{ public_key_file | default(omit) }}"
@@ -235,8 +236,8 @@
235236
- globals.infra_deployment_engine == 'terraform'
236237
ansible.builtin.assert:
237238
that:
238-
- globals.terraform_base_dir is defined
239-
- globals.terraform_base_dir | length > 0
239+
- globals.terraform.base_dir is defined
240+
- globals.terraform.base_dir | length > 0
240241
fail_msg: "You must supply a 'terraform_base_dir' where Terraform assets will be placed"
241242
quiet: yes
242243

@@ -245,8 +246,8 @@
245246
- globals.infra_deployment_engine == 'terraform'
246247
ansible.builtin.assert:
247248
that:
248-
- (globals.terraform_auto_remote_state|bool is sameas true) or (globals.terraform_auto_remote_state|bool is sameas false)
249-
fail_msg: "The terraform_auto_remote_state variable must be a boolean variable"
249+
- (globals.terraform.auto_remote_state|bool is sameas true) or (globals.terraform.auto_remote_state|bool is sameas false)
250+
fail_msg: "The terraform.auto_remote_state variable must be a boolean variable"
250251
quiet: yes
251252

252253
# SSH
@@ -443,27 +444,29 @@
443444
when:
444445
- init__call_cloud_role | bool
445446
- globals.infra_deployment_engine == 'terraform'
446-
- globals.terraform_auto_remote_state | bool
447-
- globals.terraform_state_storage in ['remote_s3']
447+
- globals.terraform.auto_remote_state | bool
448+
- globals.terraform.state_storage in ['remote_s3']
448449
block:
449450
# Set resource variable names if not already done
450451
- name: Set variables for remote state bucket if not set
451-
when: (globals.terraform_remote_state_bucket is not defined) or
452-
( (globals.terraform_remote_state_bucket) | length == 0)
452+
when: (globals.terraform.remote_state_bucket is not defined) or
453+
( (globals.terraform.remote_state_bucket) | length == 0)
453454
ansible.builtin.set_fact:
454455
globals: "{{ globals | default({}) | combine(remote_state_vars, recursive=True) }}"
455456
vars:
456457
remote_state_vars:
457-
terraform_remote_state_bucket: "{{ [globals.name_prefix, 'state-bucket'] | join('-') }}"
458+
terraform:
459+
remote_state_bucket: "{{ [globals.name_prefix, 'state-bucket'] | join('-') }}"
458460

459461
- name: Set variables for remote state lock table if not set
460-
when: (globals.terraform_remote_state_lock_table is not defined) or
461-
(globals.terraform_remote_state_lock_table | length == 0)
462+
when: (globals.terraform.remote_state_lock_table is not defined) or
463+
(globals.terraform.remote_state_lock_table | length == 0)
462464
ansible.builtin.set_fact:
463465
globals: "{{ globals | default({}) | combine(remote_state_vars, recursive=True) }}"
464466
vars:
465467
remote_state_vars:
466-
terraform_remote_state_lock_table: "{{ [globals.name_prefix, 'state-lock-table'] | join('-') }}"
468+
terraform:
469+
remote_state_lock_table: "{{ [globals.name_prefix, 'state-lock-table'] | join('-') }}"
467470

468471
- name: Create remote state resources
469472
when: "'teardown' not in ansible_run_tags"

0 commit comments

Comments
 (0)