diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..672798aeca8b0a4465c6e603cebbf8d9cf893834 --- /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 0000000000000000000000000000000000000000..40b5c6faa9fae67a5d2e025520062addfe48afab --- /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 83e75fec1dff6ddc89cddadadab06187d38bfd3e..0000000000000000000000000000000000000000 --- 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 d8b9896fd50573bf6c4066151b263ce50ae024ae..8e97a0206771968eef181a07dbc00796696dfa0e 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 0000000000000000000000000000000000000000..5a94ef98c48fe0d11f31098c0c38071fbebd2462 --- /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 0000000000000000000000000000000000000000..6ebbee9777ce71e36a74e4296ccf922ff667ae1e --- /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 0000000000000000000000000000000000000000..176c95e8a4716cb43ced2dafe96dbeeda7689058 --- /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 156a3984b6b97c7c79dc96537b59a99b17a6e136..fa3ba5a2135d4d9a0c9105c700956be0f0ecf26b 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