From 8a50e4d2744edffff65879539b192158ecc29fff Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Fri, 21 Feb 2020 21:09:28 +0100 Subject: [PATCH] project started --- .gitignore | 1 + deploy.yaml | 18 ++++++++++ group_vars/ovh_vms/terraform.yaml | 3 ++ .../terraform-info.json | 1 + inventory | 9 +++++ terraform/controller.testing.thengo.net.tf | 31 +++++++++++++++++ terraform/etcd.tf | 7 ++++ terraform/ovh.tf | 33 +++++++++++++++++++ terraform/versions.tf | 4 +++ 9 files changed, 107 insertions(+) create mode 100644 .gitignore create mode 100644 deploy.yaml create mode 100644 group_vars/ovh_vms/terraform.yaml create mode 100755 host_vars/controller.testing.thengo.net/terraform-info.json create mode 100644 inventory create mode 100644 terraform/controller.testing.thengo.net.tf create mode 100644 terraform/etcd.tf create mode 100644 terraform/ovh.tf create mode 100644 terraform/versions.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1679617 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +terraform/.terraform diff --git a/deploy.yaml b/deploy.yaml new file mode 100644 index 0000000..111ba63 --- /dev/null +++ b/deploy.yaml @@ -0,0 +1,18 @@ +--- + +- hosts: ovh_vms + remote_user: root + gather_facts: false + roles: + - role: terraform-vm + +- hosts: localhost + tasks: + - debug: + msg: |- + to apply terraform updates run: + cd "{{playbook_dir}}/terraform" + terraform apply + + # - terraform: + # project_path: "{{playbook_dir}}/terraform" diff --git a/group_vars/ovh_vms/terraform.yaml b/group_vars/ovh_vms/terraform.yaml new file mode 100644 index 0000000..46bf348 --- /dev/null +++ b/group_vars/ovh_vms/terraform.yaml @@ -0,0 +1,3 @@ +ansible_host: "{{terraform_vm.access_ip_v4}}" +openstack_region: GRA7 +openstack_flavor: s1-2 diff --git a/host_vars/controller.testing.thengo.net/terraform-info.json b/host_vars/controller.testing.thengo.net/terraform-info.json new file mode 100755 index 0000000..2960843 --- /dev/null +++ b/host_vars/controller.testing.thengo.net/terraform-info.json @@ -0,0 +1 @@ +{"terraform_vm":{"access_ip_v4":"54.37.77.37","access_ip_v6":"[2001:41d0:701:1000::ad9]","admin_pass":null,"all_metadata":{},"all_tags":[],"availability_zone":"nova","block_device":[],"config_drive":null,"flavor_id":"d31419c1-8e1e-48c2-8a4c-28190650c817","flavor_name":"s1-2","floating_ip":null,"force_delete":false,"id":"cf23e031-b299-477b-af6a-989826c4c9aa","image_id":"6a27a33f-9cb9-4c65-b99c-bb904dfb43aa","image_name":"Debian 10","key_pair":"terraform-default","metadata":null,"name":"controller.testing.thengo.net","network":[{"access_network":false,"fixed_ip_v4":"54.37.77.37","fixed_ip_v6":"[2001:41d0:701:1000::ad9]","floating_ip":"","mac":"fa:16:3e:84:3d:f1","name":"Ext-Net","port":"","uuid":"ed0ab0c6-93ee-44f8-870b-d103065b1b34"}],"personality":[],"power_state":"active","region":"DE1","scheduler_hints":[],"security_groups":["default"],"stop_before_destroy":false,"tags":null,"timeouts":null,"user_data":"3670b43deeb2d5936a31f7eb5c20593fd64c7a0e","vendor_options":[],"volume":[]}} \ No newline at end of file diff --git a/inventory b/inventory new file mode 100644 index 0000000..58b5a18 --- /dev/null +++ b/inventory @@ -0,0 +1,9 @@ +[ovh_vms] +controller.testing.thengo.net openstack_region=DE1 +#ns.testing.thengo.net openstack_region=DE1 + +[controllers] +controller.testing.thengo.net + +[nameservers] +ns.testing.thengo.net diff --git a/terraform/controller.testing.thengo.net.tf b/terraform/controller.testing.thengo.net.tf new file mode 100644 index 0000000..cbbc571 --- /dev/null +++ b/terraform/controller.testing.thengo.net.tf @@ -0,0 +1,31 @@ +resource "openstack_compute_instance_v2" "controller--testing--thengo--net" { + name = "controller.testing.thengo.net" + + region = "DE1" + + flavor_name = "s1-2" + + key_pair = "terraform-default" + user_data = "#cloud-config\ndisable_root: false" + + image_name = "Debian 10" + + network { + name = "Ext-Net" + } + + lifecycle { + ignore_changes = [ + key_pair, + user_data + ] + } +} + +resource "local_file" "controller--testing--thengo--net-info" { + content = jsonencode({ + "terraform_vm": openstack_compute_instance_v2.controller--testing--thengo--net + }) + filename = "../host_vars/controller.testing.thengo.net/terraform-info.json" +} + diff --git a/terraform/etcd.tf b/terraform/etcd.tf new file mode 100644 index 0000000..6ee9ecb --- /dev/null +++ b/terraform/etcd.tf @@ -0,0 +1,7 @@ +terraform { + backend "etcdv3" { + endpoints = ["localhost:2379"] + lock = true + prefix = "testing/terraform-state/" + } +} diff --git a/terraform/ovh.tf b/terraform/ovh.tf new file mode 100644 index 0000000..eeac42e --- /dev/null +++ b/terraform/ovh.tf @@ -0,0 +1,33 @@ +provider "ovh" { + endpoint = "ovh-eu" +} + +resource "ovh_cloud_user" "user" { + project_id = "2044653399df4877a72b77333c25557e" + description = "terraform user" +} + +provider "openstack" { + auth_url = "https://auth.cloud.ovh.net/v3" + + user_name = ovh_cloud_user.user.username + password = ovh_cloud_user.user.password + + tenant_id = ovh_cloud_user.user.project_id +} + +variable "ovh_regions" { + type = list(string) + default = [ + "DE1", + "GRA7", + "SBG5", + ] +} + +resource "openstack_compute_keypair_v2" "default" { + name = "terraform-default" + region = each.value + public_key = file("~/.ssh/id_rsa.pub") + for_each = toset(var.ovh_regions) +} diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}