From 82de7de1ef37b12cfa4973b9eab704b21b3f185e Mon Sep 17 00:00:00 2001
From: Johan Ruuskanen <johan.ruuskanen@control.lth.se>
Date: Fri, 27 Aug 2021 16:00:35 +0200
Subject: [PATCH] Update to terraform 0.15.1, and scripts to only deploy the VM

---
 README.md          | 29 +++++++++++++++--------------
 cluster.tfvars     |  2 +-
 hosts.tmpl         |  2 --
 main.tf            | 18 +++++++++++-------
 setup_instance.yml | 25 -------------------------
 variables.tf       |  7 ++-----
 6 files changed, 29 insertions(+), 54 deletions(-)
 delete mode 100644 hosts.tmpl
 delete mode 100644 setup_instance.yml

diff --git a/README.md b/README.md
index 8b2293b..36b22b5 100644
--- a/README.md
+++ b/README.md
@@ -1,25 +1,26 @@
+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
+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
diff --git a/cluster.tfvars b/cluster.tfvars
index 32a766f..e4939f5 100644
--- a/cluster.tfvars
+++ b/cluster.tfvars
@@ -11,4 +11,4 @@ keypair_name = "NAME-keypair"
 
 public_key_path = "~/.ssh/id_rsa.pub"
 
-cloudyml_name = "openstack"
+cloud_name = "openstack"
diff --git a/hosts.tmpl b/hosts.tmpl
deleted file mode 100644
index d4f8960..0000000
--- a/hosts.tmpl
+++ /dev/null
@@ -1,2 +0,0 @@
-[VM]
-${ip}
diff --git a/main.tf b/main.tf
index aea0241..4ffc91d 100644
--- a/main.tf
+++ b/main.tf
@@ -1,5 +1,14 @@
+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" {
@@ -74,9 +83,4 @@ resource "openstack_compute_floatingip_associate_v2" "associate_ip" {
 
 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"
-}
+}
\ No newline at end of file
diff --git a/setup_instance.yml b/setup_instance.yml
deleted file mode 100644
index cabc746..0000000
--- a/setup_instance.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-- 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
diff --git a/variables.tf b/variables.tf
index 26c965c..bace2bb 100644
--- a/variables.tf
+++ b/variables.tf
@@ -1,6 +1,3 @@
-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"
 }
-- 
GitLab