From 940c00de4c768a4faf70da78f3b12d6ec4949561 Mon Sep 17 00:00:00 2001 From: "Diaz de Arcaya Serrano, Josu" <josu.diazdearcaya@tecnalia.com> Date: Thu, 21 Apr 2022 13:34:43 +0200 Subject: [PATCH] Adjust repository format according to issue #1 --- .gitignore | 3 ++ config.yaml | 5 ++++ landing.sh | 44 ------------------------------ client.tf => stage1/client.tf | 17 ------------ stage1/config.yaml | 8 ++++++ outputs.tf => stage1/outputs.tf | 0 stage2/config.yaml | 5 ++++ {files => stage2/files}/index.html | 0 stage2/inventory.j2 | 5 ++++ client.yml => stage2/main.yml | 2 +- 10 files changed, 27 insertions(+), 62 deletions(-) create mode 100644 .gitignore create mode 100644 config.yaml delete mode 100755 landing.sh rename client.tf => stage1/client.tf (61%) create mode 100644 stage1/config.yaml rename outputs.tf => stage1/outputs.tf (100%) create mode 100644 stage2/config.yaml rename {files => stage2/files}/index.html (100%) create mode 100644 stage2/inventory.j2 rename client.yml => stage2/main.yml (90%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..672798a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.terraform* +terraform.tfstate* +inventory diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..40b5c6f --- /dev/null +++ b/config.yaml @@ -0,0 +1,5 @@ +--- +iac: + - stage1 + - stage2 +... diff --git a/landing.sh b/landing.sh deleted file mode 100755 index 83e75fe..0000000 --- a/landing.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# A POSIX variable -OPTIND=1 # Reset in case getopts has been used previously in the shell. - -usage="usage: landing-script.sh [-h] [-i] [-a] [-d] - -This script serves as the entrypoint for the IEM - -arguments: - -h show this help message and exit - -i init configuration - -a create or update infrastructure - -d destroy infrastructure" - -init() { - # the following line is only for testing purposes - ssh-keygen -f ~/.ssh/id_rsa -N "" <<< n - # the line above is only for testing purposes - terraform init -} - -apply() { - terraform apply -auto-approve -} - -destroy() { - terraform destroy -auto-approve -} - -while getopts "h?iad" opt; do - case "$opt" in - h|\?) - echo "$usage" - exit 0 - ;; - i) init - ;; - a) apply - ;; - d) destroy - ;; - esac -done diff --git a/client.tf b/stage1/client.tf similarity index 61% rename from client.tf rename to stage1/client.tf index d8b9896..8e97a02 100644 --- a/client.tf +++ b/stage1/client.tf @@ -29,23 +29,6 @@ resource "aws_instance" "server0" { instance_type = local.instance_type key_name = "deployer-key" - provisioner "remote-exec" { - inline = [ - "sudo apt update", - "sudo apt install nginx -y", - ] - connection { - type = "ssh" - host = self.public_ip - user = "ubuntu" - private_key = "${file("~/.ssh/id_rsa")}" - } - } - - provisioner "local-exec" { - command = "ansible-playbook -u ubuntu -i '${self.public_ip},' client.yml" - } - tags = { Name = "hello-nginx" } diff --git a/stage1/config.yaml b/stage1/config.yaml new file mode 100644 index 0000000..5a94ef9 --- /dev/null +++ b/stage1/config.yaml @@ -0,0 +1,8 @@ +--- +input: + - AWS_ACCESS_KEY_ID + - AWS_SECRET_ACCESS_KEY +output: + - instance_server0_ip +engine: terraform +... diff --git a/outputs.tf b/stage1/outputs.tf similarity index 100% rename from outputs.tf rename to stage1/outputs.tf diff --git a/stage2/config.yaml b/stage2/config.yaml new file mode 100644 index 0000000..6ebbee9 --- /dev/null +++ b/stage2/config.yaml @@ -0,0 +1,5 @@ +--- +input: + - instance_server0_ip +engine: ansible +... diff --git a/files/index.html b/stage2/files/index.html similarity index 100% rename from files/index.html rename to stage2/files/index.html diff --git a/stage2/inventory.j2 b/stage2/inventory.j2 new file mode 100644 index 0000000..176c95e --- /dev/null +++ b/stage2/inventory.j2 @@ -0,0 +1,5 @@ +[all:vars] +ansible_user=ubuntu + +[server0] +server0.piacere.com ansible_host={{ instance_server0_ip }} diff --git a/client.yml b/stage2/main.yml similarity index 90% rename from client.yml rename to stage2/main.yml index 156a398..fa3ba5a 100644 --- a/client.yml +++ b/stage2/main.yml @@ -4,7 +4,7 @@ tasks: - name: Install necessary packages apt: - name: python3-pip + name: nginx state: latest update_cache: yes - name: copy html -- GitLab