diff --git a/README.md b/README.md index 8b2293bf339c0694de6a18b0968a90f476723e53..36b22b508a5bde841d8e342f8c951badb1bf11b7 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 32a766f1fe5c07b6d8fbc2b25ac128d9914ee310..e4939f5413f9924e8813ee6bed8c54d07e37938e 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 d4f8960dee1fe2c31a3af5e64a0a80f761458879..0000000000000000000000000000000000000000 --- a/hosts.tmpl +++ /dev/null @@ -1,2 +0,0 @@ -[VM] -${ip} diff --git a/main.tf b/main.tf index aea0241082a336952b9c74c4dcb6e2b9625887c3..4ffc91dc7933fab37d8714f6510da9e8915e217c 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 cabc7469353ffb5af201e09f8ba4ed8e652ccdeb..0000000000000000000000000000000000000000 --- 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 26c965c566a7169fe64ddf0decb3c4f34722243e..bace2bbb30d735048a1542aea28917e71f3fde91 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" }