diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/Makefile b/Makefile index 48a729c..92b235e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ export PATH := $(shell pwd)/tmp:$(PATH) .ONESHELL .PHONY: up update-box destroy-box remove-tmp clean example .DEFAULT_GOAL := up +#### Pre requisites #### +install: + mkdir -p tmp;(cd tmp; git clone --depth=1 https://github.com/fredrikhgrelland/vagrant-hashistack.git; cd vagrant-hashistack; make install); rm -rf tmp/vagrant-hashistack + #### Development #### # start commands dev: update-box @@ -24,21 +28,25 @@ endif test: clean up -example: custom_ca +template-example: custom_ca ifdef CI # CI is set in Github Actions - cd test_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} vagrant up --provision + cd template_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} vagrant up --provision else - cp -f docker/conf/certificates/*.crt test_example/docker/conf/certificates - cd test_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} CUSTOM_CA=${CUSTOM_CA} ANSIBLE_ARGS='--extra-vars "local_test=true"' vagrant up --provision + if [ -f "docker/conf/certificates/*.crt" ]; then cp -f docker/conf/certificates/*.crt template_example/docker/conf/certificates; fi + cd template_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} CUSTOM_CA=${CUSTOM_CA} ANSIBLE_ARGS='--extra-vars "local_test=true"' vagrant up --provision +endif + +template-example: custom_ca +ifdef CI # CI is set in Github Actions + cd template_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} vagrant up --provision +else + if [ -f "docker/conf/certificates/*.crt" ]; then cp -f docker/conf/certificates/*.crt template_example/docker/conf/certificates; fi + cd template_example; SSL_CERT_FILE=${SSL_CERT_FILE} CURL_CA_BUNDLE=${CURL_CA_BUNDLE} CUSTOM_CA=${CUSTOM_CA} ANSIBLE_ARGS='--extra-vars "local_test=true"' vagrant up --provision endif # clean commands -# clean commands -destroy: +destroy-box: vagrant destroy -f - rm terraform.tfstate || true - rm terraform.tfstate.backup || true - rm example/terraform.tfstate || true remove-tmp: rm -rf ./tmp diff --git a/README_template.md b/README_template.md new file mode 100644 index 0000000..fb0e273 --- /dev/null +++ b/README_template.md @@ -0,0 +1,51 @@ + +

+ +> :warning: The text under headlines are examples, and should be removed. +> +> :warning: Remove this line and the one above! + +# Terraform-module name + +## Compatibility +List of compatible versions. E.g. +1. Terraform 0.12.2 or newer +2. Nomad 0.12 or newer + +## Usage + +### Requirements +#### Required software +1. Software 1 +2. Software 2 + +#### Other +Any other requirements. E.g. "This needs to be run on a Debian system" + +### Providers +A description of the providers that the module uses. E.g. "This module uses the [Nomad](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs) and [Vault](https://registry.terraform.io/providers/hashicorp/vault/latest/docs) providers" + +## Inputs +|Name |Description |Type |Default |Required | +|:--|:--|:--|:-:|:-:| +| | |bool |true |yes | + +## Outputs +|Name |Description |Type |Default |Required | +|:--|:--|:--|:-:|:-:| +| | |bool |true |yes | + +### Example +Example-code that shows how to use the module, and, if applicable, its different use cases. +```hcl-terraform +module "example"{ + source = "./" +} +``` + +### Verifying setup +Description of expected end result and how to check it. E.g. "After a successful run Presto should be available at localhost:8080". + +## Authors + +## License \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile index 938c2dd..5c1c0e1 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,13 +1,2 @@ -Vagrant.configure("2") do |config| - config.vm.box = "fredrikhgrelland/hashistack" - config.vm.box_version = ">= 0.3, < 0.4" - config.vm.provider "virtualbox" do |vb| - vb.linked_clone = true - vb.cpus = 3 - vb.memory = 8192 - end - config.vm.provision "ansible_local" do |ansible| - ansible.provisioning_path = "/vagrant/dev/ansible" - ansible.playbook = "playbook.yml" # Note this playbook is, in this context, /ansible/playbook.yml - end -end +default_vagrantfile = "Vagrantfile.default" +load default_vagrantfile if File.exists?(default_vagrantfile) diff --git a/Vagrantfile.default b/Vagrantfile.default new file mode 100644 index 0000000..ce7ae6f --- /dev/null +++ b/Vagrantfile.default @@ -0,0 +1,13 @@ +Vagrant.configure("2") do |config| + config.vm.box = "fredrikhgrelland/hashistack" + config.vm.box_version = ">= 0.4, < 0.5" + config.vm.provider "virtualbox" do |vb| + vb.linked_clone = true + vb.cpus = 3 + vb.memory = 8192 + end + config.vm.provision "ansible_local" do |ansible| + ansible.provisioning_path = "/vagrant/dev/ansible" + ansible.playbook = "playbook.yml" # Note this playbook is, in this context, /ansible/playbook.yml + end +end diff --git a/dev/ansible/README.md b/dev/ansible/README.md index 256dfda..23cb2c8 100644 --- a/dev/ansible/README.md +++ b/dev/ansible/README.md @@ -3,4 +3,4 @@ This is a good starting point where you may run a series of sequential steps. In the example, we use ansible to initialize and start a terraform job which in turn starts nomad jobs in parallel. -Se [example](../../test_example/dev/ansible) \ No newline at end of file +See [example](../../template_example/dev/ansible) diff --git a/dev/vagrant/conf/README.md b/dev/vagrant/conf/README.md index 7657570..ee61d43 100644 --- a/dev/vagrant/conf/README.md +++ b/dev/vagrant/conf/README.md @@ -11,6 +11,7 @@ You may add a `pre_ansible.sh` script file to this directory to run any alterati This might come handy if you need to change or replace that bootstrap process. For example you replacing the entire `/etc/ansible` directory. For most cases, you are probably looking to add configuration in [pre/poststart bootstrap](pre_bootstrap/README.md) + #### Post If you need to run additional commands after ansible bootstrap has happened, you may add a `post_ansible.sh`. This might come in handy if you would like to pat your self on tha back or test a recent configuration change before anything you might add to your own Vagrantfile. @@ -28,4 +29,4 @@ There are two primary cases for customization. ### Add pre and post bootstrap tasks - [pre_bootstrap](pre_bootstrap/README.md) -- [post_bootstrap](post_bootstrap/README.md) \ No newline at end of file +- [post_bootstrap](post_bootstrap/README.md) diff --git a/dev/vagrant/conf/consul/README.md b/dev/vagrant/conf/consul/README.md index a9b927b..ea1694b 100644 --- a/dev/vagrant/conf/consul/README.md +++ b/dev/vagrant/conf/consul/README.md @@ -5,4 +5,5 @@ Any valid configuration added to this directory will append the configuration, i Adding a file `99-override.hcl` you will ensure it will be appended last, and 00-override.hcl will be read first. Any valid configuration from [https://www.consul.io/docs/agent/options.html#configuration_files](https://www.consul.io/docs/agent/options.html#configuration_files) will work. -See [example](../../../../test_example/dev/vagrant/conf/consul/99-override.hcl) + +See [example](../../../../template_example/dev/vagrant/conf/consul/99-override.hcl) diff --git a/dev/vagrant/conf/nomad/README.md b/dev/vagrant/conf/nomad/README.md index c08e492..3b09566 100644 --- a/dev/vagrant/conf/nomad/README.md +++ b/dev/vagrant/conf/nomad/README.md @@ -16,4 +16,4 @@ client { } ``` -See [example](../../../../test_example/dev/vagrant/conf/nomad/99-override.hcl) \ No newline at end of file +See [example](../../../../template_example/dev/vagrant/conf/nomad/99-override.hcl) diff --git a/dev/vagrant/conf/pre_bootstrap/README.md b/dev/vagrant/conf/pre_bootstrap/README.md index 4350d9a..e2585c8 100644 --- a/dev/vagrant/conf/pre_bootstrap/README.md +++ b/dev/vagrant/conf/pre_bootstrap/README.md @@ -12,4 +12,5 @@ The files e.g. 0-example.yml must only include pure ansible task syntax: msg: This would be a prestart task ``` -See [example](../../../../test_example/dev/vagrant/conf/pre_bootstrap/00-prestart-example.yml) \ No newline at end of file + +See [example](../../../../template_example/dev/vagrant/conf/pre_bootstrap/00-prestart-example.yml) diff --git a/dev/vagrant/conf/vault/README.md b/dev/vagrant/conf/vault/README.md index 1819c1b..8af0685 100644 --- a/dev/vagrant/conf/vault/README.md +++ b/dev/vagrant/conf/vault/README.md @@ -6,4 +6,4 @@ Any valid configuration added to this directory will append the configuration, i Adding a file `99-override.hcl` you will ensure it will be appended last, and 00-override.hcl will be read first. Any valid configuration from [https://www.vaultproject.io/docs/configuration](https://www.vaultproject.io/docs/configuration) will work. -See [example](../../../../test_example/dev/vagrant/conf/vault/99-override.hcl) \ No newline at end of file +See [example](../../../../template_example/dev/vagrant/conf/vault/99-override.hcl) diff --git a/docker/README.md b/docker/README.md index 2228af7..d1ca9db 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,8 +9,8 @@ If you have docker installed on your machine, you may `cd docker; docker build - This image can be built and operated behind a corporate proxy where the base os needs to trust a custom CA. While building locally using the Makefile, you may set the environment variable CUSTOM_CA to a custom .crt file in order to import it into the docker image. See [conf/certificates](conf/certificates) -See [../test_example/docker/Dockerfile](../test_example/docker/Dockerfile) for examples on how to import and trust CA for centos/debian/alpine based docker images. +See [../template_example/docker/Dockerfile](../template_example/docker/Dockerfile) for examples on how to import and trust CA for centos/debian/alpine based docker images. ## Building and testing the docker-image within the vagrant-hashistack box -We advise you to build and test your docker image within the hashistack eco-system. Running `make test` will launch the [default playbook](../dev/ansible/playbook.yml) inside the box, and [test_example/](../test_example/) shows a simple build process for building and running the docker image using this. Refer to books in [test_example/dev/ansible](../test_example/dev/ansible) to see details. +We advise you to build and test your docker image within the hashistack eco-system. Running `make test` will launch the [default playbook](../dev/ansible/playbook.yml) inside the box, and [template_example/](../template_example/) shows a simple build process for building and running the docker image using this. Refer to books in [template_example/dev/ansible](../template_example/dev/ansible) to see details. diff --git a/example/README.md b/example/README.md index 37fe4f2..77d4817 100644 --- a/example/README.md +++ b/example/README.md @@ -1,3 +1,6 @@ # This is a terraform module example -TODO: explain \ No newline at end of file +The current directory contains terraform related files that use the module in `../`. See [template_example](../template_example/example/). + +## References +- [Creating Modules - official terraform documentation](https://www.terraform.io/docs/modules/index.html) diff --git a/template_example/.env b/template_example/.env new file mode 100644 index 0000000..16ca13c --- /dev/null +++ b/template_example/.env @@ -0,0 +1,4 @@ +#Control box features +#consul_acl=true +#consul_acl_default_policy=allow +#nomad_acl=false \ No newline at end of file diff --git a/template_example/Vagrantfile b/template_example/Vagrantfile new file mode 100644 index 0000000..80d35e8 --- /dev/null +++ b/template_example/Vagrantfile @@ -0,0 +1,2 @@ +default_vagrantfile = "../Vagrantfile.default" +load default_vagrantfile if File.exists?(default_vagrantfile) \ No newline at end of file diff --git a/template_example/conf/nomad/countdash.hcl b/template_example/conf/nomad/countdash.hcl new file mode 100644 index 0000000..d7a2890 --- /dev/null +++ b/template_example/conf/nomad/countdash.hcl @@ -0,0 +1,84 @@ +job "countdash" { + datacenters = ["dc1"] + group "api" { + network { + mode = "bridge" + } + + service { + name = "count-api" + port = "9001" + + connect { + sidecar_service {} + } + check { + expose = true + name = "api-alive" + type = "http" + path = "/health" + interval = "10s" + timeout = "2s" + } + } + + task "web" { + driver = "docker" + artifact { + source = "s3::http://127.0.0.1:9000/dev/tmp/docker_image.tar" + options { + aws_access_key_id = "minioadmin" + aws_access_key_secret = "minioadmin" + } + } + config { + load = "docker_image.tar" + image = "docker_image:local" + } + } + } + + group "dashboard" { + network { + mode ="bridge" + port "http" { + static = 9002 + to = 9002 + } + } + + service { + name = "count-dashboard" + port = "9002" + + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "count-api" + local_bind_port = 8080 + } + } + } + } + check { + expose = true + name = "dashboard-alive" + type = "http" + path = "/health" + interval = "10s" + timeout = "2s" + } + } + + task "dashboard" { + driver = "docker" + env { + COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}" + } + config { + image = "hashicorpnomad/counter-dashboard:v1" + } + } + } +} diff --git a/template_example/dev/ansible/01_build_docker_image.yml b/template_example/dev/ansible/01_build_docker_image.yml new file mode 100644 index 0000000..372ec0d --- /dev/null +++ b/template_example/dev/ansible/01_build_docker_image.yml @@ -0,0 +1,35 @@ +- name: Remove docker image + docker_image: + name: docker_image + tag: local + force_absent: true + state: absent + +- name: Build docker image + docker_image: + name: docker_image + tag: local + build: + path: /vagrant/docker + pull: false + args: + TEST_DOWNLOAD_BUILD_ARGUMENT: https://nrk.no + source: build + +# NB! Folder /vagrant is mounted to Minio +# Folder `dev` is going to be a bucket name +- name: Create tmp if it does not exist + file: + path: /vagrant/dev/tmp + state: directory + mode: '0755' + owner: vagrant + group: vagrant + +- name: Archive docker image + docker_image: + name: docker_image + tag: local + http_timeout: 120 + archive_path: /vagrant/dev/tmp/docker_image.tar + source: local diff --git a/template_example/dev/ansible/02_run_terraform.yml b/template_example/dev/ansible/02_run_terraform.yml new file mode 100644 index 0000000..cc381f2 --- /dev/null +++ b/template_example/dev/ansible/02_run_terraform.yml @@ -0,0 +1,10 @@ +- name: Terraform + terraform: + project_path: ../../example + force_init: true + state: present + register: terraform + +- name: Terraform stdout + debug: + msg: "{{terraform.stdout}}" \ No newline at end of file diff --git a/template_example/dev/ansible/playbook.yml b/template_example/dev/ansible/playbook.yml new file mode 100644 index 0000000..5ccb21b --- /dev/null +++ b/template_example/dev/ansible/playbook.yml @@ -0,0 +1,7 @@ +--- +- hosts: all + become: yes + tasks: + - name: Include and run tasks + include_tasks: "{{ item }}" + loop: "{{ query('fileglob', \"/vagrant/dev/ansible/*.yml\", wantlist=true) | reject('search','playbook.yml') | list | sort }}" \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/consul/99-override.hcl b/template_example/dev/vagrant/conf/consul/99-override.hcl new file mode 100644 index 0000000..d2b8041 --- /dev/null +++ b/template_example/dev/vagrant/conf/consul/99-override.hcl @@ -0,0 +1 @@ +#Any vaild configuration from https://www.consul.io/docs/agent/options.html#configuration_files \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/nomad/99-override.hcl b/template_example/dev/vagrant/conf/nomad/99-override.hcl new file mode 100644 index 0000000..d817340 --- /dev/null +++ b/template_example/dev/vagrant/conf/nomad/99-override.hcl @@ -0,0 +1 @@ +#Any vaild configuration from https://www.nomadproject.io/docs/configuration#general-parameters \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/post_ansible.sh b/template_example/dev/vagrant/conf/post_ansible.sh new file mode 100644 index 0000000..d09910c --- /dev/null +++ b/template_example/dev/vagrant/conf/post_ansible.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Running /vagrant/dev/vagrant/conf/post_ansible.sh" \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/post_bootstrap/00-poststart-example.yml b/template_example/dev/vagrant/conf/post_bootstrap/00-poststart-example.yml new file mode 100644 index 0000000..7bf4f56 --- /dev/null +++ b/template_example/dev/vagrant/conf/post_bootstrap/00-poststart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of poststart + debug: + msg: This is the first poststart task ( 00-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/post_bootstrap/01-poststart-example.yml b/template_example/dev/vagrant/conf/post_bootstrap/01-poststart-example.yml new file mode 100644 index 0000000..4fc2a1b --- /dev/null +++ b/template_example/dev/vagrant/conf/post_bootstrap/01-poststart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of poststart + debug: + msg: This is the second poststart task ( 01-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/post_bootstrap/02-poststart-example.yml b/template_example/dev/vagrant/conf/post_bootstrap/02-poststart-example.yml new file mode 100644 index 0000000..fc045ea --- /dev/null +++ b/template_example/dev/vagrant/conf/post_bootstrap/02-poststart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of poststart + debug: + msg: This is the third poststart task ( 02-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/pre_ansible.sh b/template_example/dev/vagrant/conf/pre_ansible.sh new file mode 100644 index 0000000..4695070 --- /dev/null +++ b/template_example/dev/vagrant/conf/pre_ansible.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Running /vagrant/dev/vagrant/conf/pre_ansible.sh" \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/pre_bootstrap/00-prestart-example.yml b/template_example/dev/vagrant/conf/pre_bootstrap/00-prestart-example.yml new file mode 100644 index 0000000..4bcb7a7 --- /dev/null +++ b/template_example/dev/vagrant/conf/pre_bootstrap/00-prestart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of prestart + debug: + msg: This is the first prestart task ( 00-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/pre_bootstrap/01-prestart-example.yml b/template_example/dev/vagrant/conf/pre_bootstrap/01-prestart-example.yml new file mode 100644 index 0000000..07002cc --- /dev/null +++ b/template_example/dev/vagrant/conf/pre_bootstrap/01-prestart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of prestart + debug: + msg: This is the second prestart task ( 01-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/pre_bootstrap/02-prestart-example.yml b/template_example/dev/vagrant/conf/pre_bootstrap/02-prestart-example.yml new file mode 100644 index 0000000..deeb4d3 --- /dev/null +++ b/template_example/dev/vagrant/conf/pre_bootstrap/02-prestart-example.yml @@ -0,0 +1,3 @@ +- name: Task that shows usage of prestart + debug: + msg: This is the third prestart task ( 02-poststart-example.yml ) \ No newline at end of file diff --git a/template_example/dev/vagrant/conf/vault/99-override.hcl b/template_example/dev/vagrant/conf/vault/99-override.hcl new file mode 100644 index 0000000..2a828c6 --- /dev/null +++ b/template_example/dev/vagrant/conf/vault/99-override.hcl @@ -0,0 +1 @@ +#Any vaild configuration from https://www.vaultproject.io/docs/configuration \ No newline at end of file diff --git a/template_example/docker/.dockerignore b/template_example/docker/.dockerignore new file mode 100644 index 0000000..bdef5a7 --- /dev/null +++ b/template_example/docker/.dockerignore @@ -0,0 +1,4 @@ +* +!bin +!lib +!conf \ No newline at end of file diff --git a/template_example/docker/Dockerfile b/template_example/docker/Dockerfile new file mode 100644 index 0000000..b8ca278 --- /dev/null +++ b/template_example/docker/Dockerfile @@ -0,0 +1,56 @@ +########################################## +########### READ THIS FIRST ############## +########################################## +## This docker build is special... ## +## It wil leverage multi stage builds ## +## to test centos/debian/alpine ## +## certificate trust before building ## +## the docker image used in the example ## +########################################## + +FROM centos:8 + +# Allow buildtime config +ARG TEST_DOWNLOAD_BUILD_ARGUMENT=https://nrk.no + +#Add ca_certificates to the image ( if trust is not already added through base image ) +COPY conf/certificates /usr/share/pki/ca-trust-source/anchors/ + +#Install certs +RUN \ + #Update CA_Certs + update-ca-trust 2>/dev/null || true && echo "NOTE: CA warnings suppressed." \ + #Test download ( does ssl trust work ) + && curl -s -L -o /dev/null ${TEST_DOWNLOAD_BUILD_ARGUMENT} || printf "\n###############\nERROR: You are probably behind a corporate proxy. Add your custom ca .crt in the conf/certificates docker build folder\n###############\n" + +FROM debian:stretch + +# Allow buildtime config +ARG TEST_DOWNLOAD_BUILD_ARGUMENT=https://nrk.no + +#Add ca_certificates to the image ( if trust is not already added through base image ) +COPY conf/certificates /usr/local/share/ca-certificates + +#Install certs +# hadolint ignore=DL3015 +RUN \ + #Update CA_Certs + apt-get update && apt-get install -y curl=7.52.1-5+deb9u11 && rm -rf /var/lib/apt/lists/* \ + && update-ca-certificates 2>/dev/null || true && echo "NOTE: CA warnings suppressed." \ + #Test download ( does ssl trust work ) + && curl -s -L -o /dev/null ${TEST_DOWNLOAD_BUILD_ARGUMENT} || printf "\n###############\nERROR: You are probably behind a corporate proxy. Add your custom ca .crt in the conf/certificates docker build folder\n###############\n" + + +FROM hashicorpnomad/counter-api:v1 + +# Allow buildtime config +ARG TEST_DOWNLOAD_BUILD_ARGUMENT=https://nrk.no + +#Add ca_certificates to the image ( if trust is not already added through base image ) +COPY conf/certificates /usr/local/share/ca-certificates + +RUN apk --no-cache add curl=~7 ca-certificates=~20190108 \ + && find /usr/local/share/ca-certificates -not -name "*.crt" -type f -delete \ + && update-ca-certificates 2>/dev/null || true && echo "NOTE: CA warnings suppressed." \ + # Test download + && curl -s -L -o /dev/null ${TEST_DOWNLOAD_BUILD_ARGUMENT} || printf "\n###############\nERROR: You are probably behind a corporate proxy. Add your custom ca .crt in the conf/certificates docker build folder\n###############\n" diff --git a/template_example/docker/conf/certificates/.gitignore b/template_example/docker/conf/certificates/.gitignore new file mode 100644 index 0000000..ee0cb61 --- /dev/null +++ b/template_example/docker/conf/certificates/.gitignore @@ -0,0 +1 @@ +*.crt \ No newline at end of file diff --git a/template_example/docker/conf/certificates/README.md b/template_example/docker/conf/certificates/README.md new file mode 100644 index 0000000..5829d33 --- /dev/null +++ b/template_example/docker/conf/certificates/README.md @@ -0,0 +1,2 @@ +# Custom CA certificates +If the env variable `CUSTOM_CA` is pointing to a certificate file, it will be copied into this directory by the Makefile. \ No newline at end of file diff --git a/template_example/example/main.tf b/template_example/example/main.tf new file mode 100644 index 0000000..6bb90a1 --- /dev/null +++ b/template_example/example/main.tf @@ -0,0 +1,7 @@ +module "countdash" { + source = "./.." +} + +provider "vault" { + address = "http://127.0.0.1:8200" +} \ No newline at end of file diff --git a/template_example/example/nomad_acl_test.tf b/template_example/example/nomad_acl_test.tf new file mode 100644 index 0000000..2ed9a35 --- /dev/null +++ b/template_example/example/nomad_acl_test.tf @@ -0,0 +1,12 @@ +data "vault_generic_secret" "nomad_secret_id" { + # Set count of this data source to 1 if ACLs are enabled in Nomad, and 0 if not + count = var.nomad_acl ? 1 : 0 + path = "nomad/creds/write" +} + +provider "nomad" { + address = "http://127.0.0.1:4646" + # Add a secret_id if ACLs are enabled in nomad + secret_id = var.nomad_acl ? data.vault_generic_secret.nomad_secret_id[0].data.secret_id : null +} + diff --git a/template_example/example/variables.tf b/template_example/example/variables.tf new file mode 100644 index 0000000..55cbd1b --- /dev/null +++ b/template_example/example/variables.tf @@ -0,0 +1,3 @@ +variable "nomad_acl" { + type = bool +} \ No newline at end of file diff --git a/template_example/main.tf b/template_example/main.tf new file mode 100644 index 0000000..4a066ce --- /dev/null +++ b/template_example/main.tf @@ -0,0 +1,4 @@ +resource "nomad_job" "countdash" { + jobspec = file("${path.module}/conf/nomad/countdash.hcl") + detach = false +} \ No newline at end of file diff --git a/template_example/outputs.tf b/template_example/outputs.tf new file mode 100644 index 0000000..a711302 --- /dev/null +++ b/template_example/outputs.tf @@ -0,0 +1,3 @@ +output "nomad_job" { + value = nomad_job.countdash +} \ No newline at end of file diff --git a/template_example/variables.tf b/template_example/variables.tf new file mode 100644 index 0000000..e69de29