Skip to content
Snippets Groups Projects
Commit d356e2fb authored by Diaz de Arcaya Serrano, Josu's avatar Diaz de Arcaya Serrano, Josu
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
locals {
cloud_type = "aws"
instance_type = "t2.micro"
ami = "ami-0ca5c3bd5a268e7db"
instance_cost = "0.75"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
}
provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_key_pair" "deployer" {
key_name = "deployer-key"
public_key = "${file("~/.ssh/id_rsa.pub")}"
}
resource "aws_instance" "server0" {
ami = local.ami
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"
}
}
---
- hosts: all
become: yes
tasks:
- name: Install necessary packages
apt:
name: python3-pip
state: latest
update_cache: yes
- name: copy html
copy:
src: index.html
dest: /var/www/html/index.html
...
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple HTML document</title>
</head>
<body>
<p>Hello IEM!<p>
</body>
</html>
#!/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
output "instance_server0_ip" {
description = "Public IP address of the EC2 instance"
value = aws_instance.server0.public_ip
}
output "instance_id" {
description = "ID of the EC2 instance"
value = aws_instance.server0.id
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment