Skip to content
Snippets Groups Projects
Commit 82de7de1 authored by Johan Ruuskanen's avatar Johan Ruuskanen
Browse files

Update to terraform 0.15.1, and scripts to only deploy the VM

parent d93e26e1
No related branches found
No related tags found
No related merge requests found
Terraform script to setup a virtual machine on ERDC Xerces, with associated virtual network and security group rules to allow for SSH access over the internet.
## 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)
#### Prerequisites
## Instructions
* API access to Xerces via either the `cloud.yml` or OpenStack RC file. Both can be found in the "API Access"-tab on your project page on the xerces webpage
* Terraform, tested with v 0.15.1
#### Instructions
Update the values in `cluster.tfvars`, and then setup the VM by running
* 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
Note the public IP assigned. 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_instance.yml` in the ansible folder.
You can now ssh into your machine using `ssh ubuntu@your-floating-ip`.
You can now ssh into your virtual machine using `ssh ubuntu@vm-public-ip`.
## Remove the terraform instance
* Simply run `terraform destroy`
#### Remove the terraform instance
Simply run `terraform destroy`
\ No newline at end of file
......@@ -11,4 +11,4 @@ keypair_name = "NAME-keypair"
public_key_path = "~/.ssh/id_rsa.pub"
cloudyml_name = "openstack"
cloud_name = "openstack"
[VM]
${ip}
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.17"
}
}
}
provider "openstack" {
cloud = "${var.cloudyml_name}"
cloud = "${var.cloud_name}"
}
resource "openstack_compute_keypair_v2" "create_keypair" {
......@@ -75,8 +84,3 @@ resource "openstack_compute_floatingip_associate_v2" "associate_ip" {
output "ip_address" {
value = "${openstack_networking_floatingip_v2.floating_ip.address}"
}
\ No newline at end of file
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"
......@@ -29,7 +26,7 @@ variable "public_key_path" {
variable "subnet_cidr" {
description = "Subnet CIDR block."
type = "string"
type = string
default = "10.0.0.0/24"
}
......@@ -48,7 +45,7 @@ variable "flavor_name" {
default = "c2m4"
}
variable "cloudyml_name" {
variable "cloud_name" {
description = "name/key of the cloud provider in the cloud.yml file"
default = "openstack"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment