Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to terraform 0.12.7 #13

Merged
merged 5 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM hashicorp/terraform:0.12.7

RUN apk add --no-cache putty bash zip
20 changes: 19 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This terraform script will create the following resources:

## Prerequisite

- terraform (`v0.11.14`)
- terraform (`v0.12.7`)
- [puttygen](https://www.puttygen.com/) (tested with Release 0.71)
- GCP Account
* Every student requires 10 vCPUs and 5 public IP addresses. You will run into your quotas very quickly. [Raise GCP quotas process](https://cloud.google.com/compute/quotas#requesting_additional_quota).
Expand All @@ -37,10 +37,28 @@ See [here](https://cloud.google.com/community/tutorials/managing-gcp-projects-wi

Now we can verify everything with the `plan` step: `terraform plan` if everything looks fine just apply the changes: `terraform apply`

### Run in Docker
hikhvar marked this conversation as resolved.
Show resolved Hide resolved

The provided dockerfile set up a system with all required software. To deploy the training environment run:
hikhvar marked this conversation as resolved.
Show resolved Hide resolved

```bash
docker build -t lfs458-prep
docker run -it -u "$(id -u):$(id -g)" --rm -v $(pwd):/wd -w /wd lfs458-prep init
docker run -it -u "$(id -u):$(id -g)" --rm -v $(pwd):/wd -w /wd lfs458-prep apply
```

hikhvar marked this conversation as resolved.
Show resolved Hide resolved
## Clean up

In order to clean up everything just run: `terraform destroy`

### Cleanup in Docker

In order to clean up everything using the docker setup, run:

```bash
docker run -it -u "$(id -u):$(id -g)" --rm -v $(pwd):/wd -w /wd lfs458-prep terraform destroy
```

### Save Homes

If you want to save the homes for your students, run the script `save_homes.sh`. This will copy all the contents of `/home/student` from the machines onto your machine. Then zip the files up and place them in `$(pwd)/homes`.
28 changes: 17 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
terraform {
required_version = "~>0.11.14"
required_version = "~>0.12.7"
}

provider "google" {
version = "~> v1.19.1"
credentials = "${file("account.json")}"
project = "${var.project}"
region = "${var.region}"
version = "~> v2.13.0"
credentials = file("account.json")
project = var.project
region = var.region
}

provider "null" {
Expand All @@ -16,31 +16,37 @@ provider "null" {
resource "google_compute_network" "vpc_network" {
name = "lfs458-network"
auto_create_subnetworks = "true"
timeouts {
create = "15m"
update = "15m"
delete = "15m"
}
}

resource "google_compute_firewall" "allow_all" {
name = "allow-all"
network = "${google_compute_network.vpc_network.name}"
network = google_compute_network.vpc_network.name

allow {
protocol = "all"
}
}

module student_workspace {
module "student_workspace" {
source = "./modules/student_workspace"
students = "${var.students}"
network = "${google_compute_network.vpc_network.name}"
machine_type = "${var.machine_type}"
students = var.students
network = google_compute_network.vpc_network.name
machine_type = var.machine_type
}

resource "null_resource" "cluster" {
triggers = {
ips = "${ module.student_workspace.ips_checksum}"
ips = "${module.student_workspace.ips_checksum}"
keys = "${module.student_workspace.keys_checksum}"
}

provisioner "local-exec" {
command = "./create_package.sh"
}
}

4 changes: 2 additions & 2 deletions modules/student_node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ resource "google_compute_instance" "node" {

metadata_startup_script = "apt-get update && apt-get install -y python && modprobe br_netfilter && echo '1' > /proc/sys/net/ipv4/ip_forward"

metadata {
metadata = {
ssh-keys = "student:${trimspace(var.public_ssh_keys[count.index])} student"
}

service_account {
scopes = []
}

labels {
labels = {
environment = "lfs458"
student = "${var.students[count.index]}"
}
Expand Down
4 changes: 2 additions & 2 deletions modules/student_workspace/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
provider "tls" {
version = "~> 1.1.0"
version = "~> 2.1.0"
}

provider "local" {
version = "~> 1.1.0"
version = "~> 1.3.0"
}

resource "tls_private_key" "ssh_key" {
Expand Down
17 changes: 9 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
variable region {
type = "string"
variable "region" {
type = string
}

variable project {
type = "string"
variable "project" {
type = string
}

variable machine_type {
type = "string"
variable "machine_type" {
type = string
}

variable students {
type = "list"
variable "students" {
type = list(string)
default = []
}