Skip to content

Commit

Permalink
Add terraform-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeeq committed Jan 16, 2024
1 parent 462bd59 commit 10074ed
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions playbooks/generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
- apps/aws-cli
- apps/terraform
- apps/terragrunt
- apps/terraform-docs
13 changes: 13 additions & 0 deletions roles/apps/terraform-docs/tasks/get_latest_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Get latest version of terraform_docs
shell: curl -Is https://github.com/terraform-docs/terraform-docs/releases/latest | grep -i 'location:' | cut -f2 -d'v' | cut -f1 -d'"'
register: version
changed_when: false

- name: "Latest version of terraform_docs:"
debug:
var: version.stdout

- name: "Set fact with latest version of terraform_docs"
set_fact:
terraform_docs_version: "{{ version.stdout }}"
25 changes: 25 additions & 0 deletions roles/apps/terraform-docs/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Directory for terraform_docs
file:
path: /tmp/terraform_docs
state: directory

- name: Download terraform_docs binary
get_url:
url: "https://github.com/terraform-docs/terraform-docs/releases/download/v{{ terraform_docs_version }}/terraform-docs-v{{ terraform_docs_version }}-linux-amd64.tar.gz"
dest: /tmp/terraform_docs/terraform_docs.tar.gz

- name: Unarchive a file that is already on the remote machine
unarchive:
src: /tmp/terraform_docs/terraform_docs.tar.gz
dest: /tmp/terraform_docs
remote_src: yes

- name: Copy terraform_docs
copy:
src: "/tmp/terraform_docs/terraform-docs"
dest: "/usr/local/bin/terraform-docs"
remote_src: true
mode: 0755
owner: root
group: root
18 changes: 18 additions & 0 deletions roles/apps/terraform-docs/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Get installed version
become: true
become_user: "{{ user_name }}"
shell: terraform-docs version | awk '{print $3}' | cut -f2 -d'v'
register: installed_terraform_docs_version
changed_when: false
ignore_errors: true

- name: "Installed version of terraform_docs:"
debug:
var: installed_terraform_docs_version.stdout

- include_tasks: get_latest_version.yml
when: terraform_docs_version is not defined

- include_tasks: install.yml
when: installed_terraform_docs_version.stdout != terraform_docs_version

0 comments on commit 10074ed

Please sign in to comment.