Commit 94f055c7 authored by Johan Ruuskanen's avatar Johan Ruuskanen
Browse files

Initial commit

parents
*terraform.tfstate*
*.terraform
## Prerequisites
* Login to Xerces using for example the cloud.yml or OpenStack RC file.
* ansible (tested with v 3.6.9)
* terraform (tested with v 0.12.8)
## Instructions
* Update the values in the cluster.tfvars
* Setup the cluster by running the following. Note the public floating IP assigned
```
terraform init
terraform apply -var-file=cluster.tfvars
```
* Add the SSH key to your ssh-agent by running
```
eval $(ssh-agent -s)
ssh-add /path/to/your/private/key
```
* Run `ansible-playbook -i inventory/hosts setup_vms.yml` in the ansible folder.
You can now ssh into your machine using `ssh ubuntu@your-floating-ip`.
## Remove the terraform instance
* Simply run `terraform destroy`
# Variables to change, list of all available variables are in variables.tf
network_name= "NAME-network"
router_name = "NAME-router"
instance_name = "NAME-instance"
keypair_name = "NAME-keypair"
public_key_path = "~/.ssh/id_rsa.pub"
cloudyml_name = "openstack"
[VM]
${ip}
provider "openstack" {
cloud = "${var.cloudyml_name}"
}
resource "openstack_compute_keypair_v2" "create_keypair" {
name = "${var.keypair_name}"
public_key = "${file(var.public_key_path)}"
}
resource "openstack_networking_network_v2" "network" {
name = "${var.network_name}"
}
resource "openstack_networking_subnet_v2" "subnet" {
network_id = "${openstack_networking_network_v2.network.id}"
cidr = "${var.subnet_cidr}"
ip_version = 4
}
resource "openstack_networking_router_v2" "router" {
name = "${var.router_name}"
external_network_id = "${var.external_net_id}"
}
resource "openstack_networking_router_interface_v2" "router_interface_1" {
router_id = "${openstack_networking_router_v2.router.id}"
subnet_id = "${openstack_networking_subnet_v2.subnet.id}"
}
resource "openstack_networking_secgroup_v2" "secgroup" {
name = "${var.instance_name}-secgroup_ssh"
description = "ssh"
}
resource "openstack_networking_secgroup_rule_v2" "ssh_rule" {
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}"
}
resource "openstack_networking_secgroup_rule_v2" "icmp_rule" {
direction = "ingress"
ethertype = "IPv4"
protocol = "icmp"
remote_ip_prefix = "0.0.0.0/0"
security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}"
}
resource "openstack_compute_instance_v2" "instance" {
name = "${var.instance_name}"
image_id = "${var.image_id}"
flavor_name = "${var.flavor_name}"
key_pair = "${openstack_compute_keypair_v2.create_keypair.name}"
security_groups = ["${openstack_networking_secgroup_v2.secgroup.name}"]
network {
uuid = "${openstack_networking_subnet_v2.subnet.network_id}"
}
}
resource "openstack_networking_floatingip_v2" "floating_ip" {
pool = "internet"
}
resource "openstack_compute_floatingip_associate_v2" "associate_ip" {
floating_ip = "${openstack_networking_floatingip_v2.floating_ip.address}"
instance_id = "${openstack_compute_instance_v2.instance.id}"
}
output "ip_address" {
value = "${openstack_networking_floatingip_v2.floating_ip.address}"
}
resource "local_file" "ansible_host_file" {
content = templatefile("${path.module}/hosts.tmpl", { ip = "${openstack_networking_floatingip_v2.floating_ip.address}" })
filename = "${path.module}/inventory/hosts"
}
- hosts: VM
remote_user: ubuntu
vars:
ansible_python_interpreter: /usr/bin/python3
tasks:
- name: Install apt packages
become: true
apt:
name: ['docker.io']
update_cache: yes
- name: Add docker group
become: true
group:
name: docker
state: present
- name: Update user to docker group
become: true
user:
name: ubuntu
group: docker
append: yes
variable "cluster_name" {
default = "example"
}
variable "network_name" {
description = "name of the internal network to use"
default = "NAME-network"
}
variable "router_name" {
description = "name of the external facing router"
default = "NAME-router"
}
variable "instance_name" {
description = "name of the gateway VM"
default = "NAME-instance"
}
variable "keypair_name" {
description = "name of keypair"
default = "NAME-keypair"
}
variable "public_key_path" {
description = "The path of the ssh pub key"
default = "~/.ssh/id_rsa.pub"
}
variable "subnet_cidr" {
description = "Subnet CIDR block."
type = "string"
default = "10.0.0.0/24"
}
variable "external_net_id" {
description = "external network ID"
default = "df26cc5b-b122-4506-b948-a213d2b0a7d8"
}
variable "image_id" {
description = "VM image ID"
default = "18a5fc04-39b0-49b8-ac52-3a572ed1d5c3"
}
variable "flavor_name" {
description = "VM flavor name"
default = "c2m4"
}
variable "cloudyml_name" {
description = "name/key of the cloud provider in the cloud.yml file"
default = "openstack"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment