-
Couldn't load subscription status.
- Fork 28
Add Terraform deployment engine for cloud resources #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d094656
e571d93
30117ee
1635ac2
e2d90a9
df05e26
13fba68
39c3ca4
3eb0cb7
8d6246b
ccbd1c8
45c4d39
1304e19
ddfdd80
cdcaed2
26ce3f0
ca8f4e9
78c76fa
a55260a
43f3809
275ad9f
efc4739
35cdc5d
e4d4338
ddac819
09c08a1
992122b
8b9c340
128dac7
14986d9
6a13b52
617d68c
287c30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright 2021 Cloudera, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| - name: Create directory for processed Terraform template files | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_template_dir }}/infra" | ||
| state: directory | ||
|
|
||
| - name: Create artefact directory for Terraform infra code | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_artefact_dir }}/infra" | ||
| state: directory | ||
|
|
||
| # Apply template for Terraform provider | ||
| - name: Generate Terraform Provider | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/provider.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/provider.tf" | ||
|
|
||
| # Apply template for Terraform backend state | ||
| - name: Generate Terraform Backend State | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/backend_state.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/backend_state.tf" | ||
|
|
||
| # Apply template for Terraform variables | ||
| - name: Generate Terraform Variables | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/terraform_variables.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/variables.tf" | ||
| no_log: false | ||
|
|
||
| # Apply template for Terraform infra.... | ||
| # ...network resources | ||
| - name: Generate Terraform infra file for network resources | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/infra_{{ infra__type }}_network.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/infra_network.tf" | ||
| no_log: false | ||
|
|
||
| # ...storage resources | ||
| - name: Generating Terraform infra file for storage resources | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/infra_{{ infra__type }}_storage.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/infra_storage.tf" | ||
| no_log: false | ||
|
|
||
| # ...compute resources | ||
| - name: Generating Terraform infra file for compute resources | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/infra_{{ infra__type }}_compute.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/infra_compute.tf" | ||
| no_log: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright 2021 Cloudera, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| - name: Create directory for processed Terraform template files | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_template_dir }}/infra" | ||
| state: directory | ||
|
|
||
| # Apply template for Terraform provider | ||
| - name: Generate Terraform Provider | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/provider.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/provider.tf" | ||
|
|
||
| # Apply template for Terraform backend state | ||
| - name: Generate Terraform Backend State | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/backend_state.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/backend_state.tf" | ||
|
|
||
| # Apply template for Terraform variables | ||
| - name: Generate Terraform Variables | ||
| ansible.builtin.template: | ||
| src: 'template/{{ infra__type }}/terraform_variables.tf.j2' | ||
| dest: "{{ infra__terraform_template_dir }}/infra/variables.tf" | ||
| no_log: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
|
|
||
| # Copyright 2021 Cloudera, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| - name: Ensure the Terraform workspace directory exists | ||
| ansible.builtin.copy: | ||
| src: "{{ infra__terraform_template_dir }}/infra/" | ||
| dest: "{{ infra__terraform_workspace_dir }}/infra" | ||
|
|
||
| - name: Copy Terraform infra code to the artefact directory | ||
| ansible.builtin.copy: | ||
| src: "{{ infra__terraform_template_dir }}/infra/" | ||
| dest: "{{ infra__terraform_artefact_dir }}/infra" | ||
|
|
||
| - name: Applying Terraform | ||
Chaffelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| community.general.terraform: | ||
| project_path: "{{ infra__terraform_workspace_dir }}/infra" | ||
| state: "present" | ||
| force_init: yes | ||
| register: tf_result | ||
| retries: 3 | ||
| delay: 10 | ||
| until: tf_result is succeeded | ||
|
|
||
| - name: Remove the Terraform template directory | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_template_dir }}/infra" | ||
| state: absent | ||
|
|
||
| - name: Remove the Terraform workspace directory when using remote state | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_workspace_dir }}/infra" | ||
| state: absent | ||
| when: infra__terraform_state_storage in ['remote_s3'] | ||
|
|
||
| # Get information about Dynamic Inventory VMs if created via Terraform | ||
wmudge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Fetch EC2 Instance info for Dynamic Inventory Nodes | ||
| register: __infra_dynamic_inventory_discovered | ||
| community.aws.ec2_instance_info: | ||
| region: "{{ infra__region }}" | ||
| filters: "{{ __filters | items2dict }}" | ||
| vars: | ||
| __filters: | ||
| - key: "tag:{{ infra__dynamic_inventory_tag_key }}" | ||
| value: "{{ infra__dynamic_inventory_tag_value }}*" | ||
|
|
||
| - name: Create output Dictionary for producing Static Inventory artefact | ||
| ansible.builtin.set_fact: | ||
| infra__dynamic_inventory_host_entries: "{{ infra__dynamic_inventory_host_entries | default([]) | union([host_entry]) }}" | ||
| vars: | ||
| host_entry: "{{ [__infra_di_item.private_dns_name, 'ansible_host=' + __infra_di_item.public_ip_address, infra__dynamic_inventory_connectors] | join(' ') }}" | ||
| loop: "{{ __infra_dynamic_inventory_discovered.instances }}" | ||
| loop_control: | ||
| loop_var: __infra_di_item | ||
|
|
||
| # If created Utility Instance via Terraform then | ||
Chaffelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # need to get it's info and add to an Ansible host group | ||
| - name: Add Utility Instance to host group | ||
| when: infra__create_utility_service | ||
| block: | ||
| - name: Discover the Utility Instance details | ||
| community.aws.ec2_instance_info: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use output variables in TF? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, I will test this and submit a separate PR if it looks good. |
||
| region: "{{ infra__region }}" | ||
| filters: "{{ __filters | items2dict }}" | ||
| vars: | ||
| __filters: | ||
| - key: "tag:Name" | ||
| value: "{{ infra__namespace }}*" | ||
| register: __infra_utility_compute_discovered | ||
|
|
||
| - name: Add discovered Utility Instance to host group | ||
| ansible.builtin.add_host: | ||
| hostname: "{{__infra_utility_compute_discovered.instances[0].public_ip_address}}" | ||
| ansible_user: "{{ infra__dynamic_inventory_images_default[infra__type][infra__dynamic_inventory_os].user }}" | ||
| ansible_ssh_private_key_file: "{{ (infra__private_key_file == '') | ternary(omit, infra__private_key_file) }}" | ||
| groupname: cldr_utility | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
|
|
||
| # Copyright 2021 Cloudera, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| - name: Ensure the Terraform workspace directory exists | ||
| ansible.builtin.copy: | ||
| src: "{{ infra__terraform_template_dir }}/infra/" | ||
| dest: "{{ infra__terraform_workspace_dir }}/infra" | ||
|
|
||
| - name: Destroy Terraform infra resources | ||
Chaffelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| community.general.terraform: | ||
| project_path: "{{ infra__terraform_workspace_dir }}/infra" | ||
| state: "absent" | ||
| force_init: yes | ||
| register: tf_result | ||
| retries: 3 | ||
| delay: 10 | ||
| until: tf_result is succeeded | ||
|
|
||
| - name: Remove the Terraform template directory | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_template_dir }}/infra" | ||
| state: absent | ||
|
|
||
| - name: Remove the Terraform workspace directory | ||
| ansible.builtin.file: | ||
| path: "{{ infra__terraform_workspace_dir }}/infra" | ||
| state: absent | ||
Uh oh!
There was an error while loading. Please reload this page.