From 5c4b79f6bd9d1d2dda7d5f4997678f90002bd0d2 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Mon, 4 Feb 2019 00:36:12 +0300 Subject: [PATCH 01/11] add hostname for scalet --- resource_scalet.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/resource_scalet.go b/resource_scalet.go index 9bc7b2f..a55af92 100644 --- a/resource_scalet.go +++ b/resource_scalet.go @@ -18,12 +18,17 @@ func resourceScalet() *schema.Resource { Delete: resourceScaletDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "hostname": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "name": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, }, - "make_from": &schema.Schema{ + "meake_from": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, @@ -55,6 +60,7 @@ func resourceScalet() *schema.Resource { func resourceScaletCreate(d *schema.ResourceData, m interface{}) error { client := m.(*vscale.WebClient) + hostname := d.Get("hostname").(string) name := d.Get("name").(string) from := d.Get("make_from").(string) plan := d.Get("rplan").(string) @@ -89,7 +95,7 @@ func resourceScaletCreate(d *schema.ResourceData, m interface{}) error { } } - scalet, _, err := client.Scalet.CreateWithoutPassword(from, plan, name, location, true, keyIDS, true) + scalet, _, err := client.Scalet.CreateWithoutPassword(hostname, from, plan, name, location, true, keyIDS, true) if err != nil { return errors.Wrap(err, "creating scalet failed") } From 6b5bbdaaa59f36972375cb5e2b0ed39b5bea2d25 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Mon, 4 Feb 2019 12:26:19 +0300 Subject: [PATCH 02/11] change import source --- resource_scalet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource_scalet.go b/resource_scalet.go index a55af92..86be28a 100644 --- a/resource_scalet.go +++ b/resource_scalet.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/pkg/errors" - vscale "github.com/vscale/go-vscale" + vscale "github.com/vganyn/go-vscale" ) func resourceScalet() *schema.Resource { From 4453a38130c48f3620619b52a4c8dd2e3fa1a5f9 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Mon, 4 Feb 2019 14:33:42 +0300 Subject: [PATCH 03/11] Update README.md --- README.md | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3472ce3..2d35d26 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,15 @@ Requirements Building The Provider --------------------- -Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provider-$PROVIDER_NAME` - -```sh -$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers -$ git clone git@github.com:terraform-providers/terraform-provider-$PROVIDER_NAME -``` - -Enter the provider directory and build the provider - -```sh -$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-$PROVIDER_NAME -$ make build -``` +* export PROVIDER_NAME=vscale +* mkdir -p $GOPATH/src/github.com/terraform-providers +* cd $GOPATH/src/github.com/terraform-providers +* git clone https://github.com/burkostya/terraform-provider-vscale +* cd $GOPATH/src/github.com/terraform-providers/terraform-provider-$PROVIDER_NAME +* go get +* go build +* mkdir -p ~/.terraform.d/plugins/ +* mv $GOPATH/bin/terraform-provider-$PROVIDER_NAME ~/.terraform.d/plugins/ Using the provider ---------------------- From a816a0358cb7a63ac5f757034b027a3e4f029d51 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Mon, 4 Feb 2019 14:34:27 +0300 Subject: [PATCH 04/11] Update README.md --- README.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/README.md b/README.md index 2d35d26..7fad2bd 100644 --- a/README.md +++ b/README.md @@ -30,31 +30,3 @@ Using the provider ---------------------- See the [DigitalOcean Provider documentation](https://www.terraform.io/docs/providers/do/index.html) to get started using the DigitalOcean provider. - -Developing the Provider ---------------------------- - -If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.8+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. - -To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. - -```sh -$ make build -... -$ $GOPATH/bin/terraform-provider-$PROVIDER_NAME -... -``` - -In order to test the provider, you can simply run `make test`. - -```sh -$ make test -``` - -In order to run the full suite of Acceptance tests, run `make testacc`. - -*Note:* Acceptance tests create real resources, and often cost money to run. - -```sh -$ make testacc -``` From 371ff25a1b736161dbee4cfa0f04473937bc7d46 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Wed, 6 Feb 2019 22:17:23 +0300 Subject: [PATCH 05/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7fad2bd..343acd0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Building The Provider * export PROVIDER_NAME=vscale * mkdir -p $GOPATH/src/github.com/terraform-providers * cd $GOPATH/src/github.com/terraform-providers -* git clone https://github.com/burkostya/terraform-provider-vscale +* git clone https://github.com/vganyn/terraform-provider-vscale * cd $GOPATH/src/github.com/terraform-providers/terraform-provider-$PROVIDER_NAME * go get * go build From 68fb3b396ed62437311981fd1fca904c1d0bd351 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Wed, 6 Feb 2019 22:21:20 +0300 Subject: [PATCH 06/11] Update resource_scalet.go --- resource_scalet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource_scalet.go b/resource_scalet.go index 86be28a..038b9f9 100644 --- a/resource_scalet.go +++ b/resource_scalet.go @@ -28,7 +28,7 @@ func resourceScalet() *schema.Resource { Required: true, ForceNew: true, }, - "meake_from": &schema.Schema{ + "make_from": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, From e3176a94acc3281b3b87d2a306c66664b67bf65e Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Thu, 7 Feb 2019 00:37:25 +0300 Subject: [PATCH 07/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 343acd0..7c1455e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Building The Provider * go get * go build * mkdir -p ~/.terraform.d/plugins/ -* mv $GOPATH/bin/terraform-provider-$PROVIDER_NAME ~/.terraform.d/plugins/ +* mv terraform-provider-$PROVIDER_NAME ~/.terraform.d/plugins/ Using the provider ---------------------- From 227021258790c202132b249b99b3e9e265c62ee1 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Sun, 10 Feb 2019 00:32:32 +0300 Subject: [PATCH 08/11] fix invalid dependencies --- provider.go | 2 +- resource_domain.go | 2 +- resource_record.go | 2 +- resource_ssh_key.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/provider.go b/provider.go index 1d9c73a..85cdcf3 100644 --- a/provider.go +++ b/provider.go @@ -2,7 +2,7 @@ package main import ( "github.com/hashicorp/terraform/helper/schema" - vscale "github.com/vscale/go-vscale" + vscale "github.com/vganyn/go-vscale" ) // Provider returns a schema.Provider for VScale. diff --git a/resource_domain.go b/resource_domain.go index 4bcca4d..8a37b23 100644 --- a/resource_domain.go +++ b/resource_domain.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/pkg/errors" - vscale "github.com/vscale/go-vscale" + vscale "github.com/vganyn/go-vscale" ) func resourceDomain() *schema.Resource { diff --git a/resource_record.go b/resource_record.go index 02139c4..3e800f4 100644 --- a/resource_record.go +++ b/resource_record.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/pkg/errors" - vscale "github.com/vscale/go-vscale" + vscale "github.com/vganyn/go-vscale" ) func resourceRecord() *schema.Resource { diff --git a/resource_ssh_key.go b/resource_ssh_key.go index 6092373..812e813 100644 --- a/resource_ssh_key.go +++ b/resource_ssh_key.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/pkg/errors" - vscale "github.com/vscale/go-vscale" + vscale "github.com/vganyn/go-vscale" ) func resourceSSHKey() *schema.Resource { From bab97d7ef21cbd0a5c60f49f9e71759e06a5cc38 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Sun, 10 Feb 2019 01:04:02 +0300 Subject: [PATCH 09/11] add example --- example/main.tf | 42 ++++++++++++++++++++++++++++++++++++++++++ example/outputs.tf | 7 +++++++ example/variable.tf | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 example/main.tf create mode 100755 example/outputs.tf create mode 100755 example/variable.tf diff --git a/example/main.tf b/example/main.tf new file mode 100755 index 0000000..ca59a07 --- /dev/null +++ b/example/main.tf @@ -0,0 +1,42 @@ +provider "vscale" { + # You need to set this in your .bashrc + # export VSCALE_API_TOKEN="Your API TOKEN" + # +} + +# Create a new SSH key +resource "vscale_ssh_key" "user1" { + name = "user1 key" + key = "ssh rsa ..." +} + +# Create a new scalet +resource "vscale_scalet" "test" { + count = "${length(var.devs)}" + ssh_keys = ["${vscale_ssh_key.user1.id}"] + hostname = "${var.devs[count.index]}" + make_from = "${var.vscale_centos_7}" + location = "${var.vscale_msk}" + rplan = "${var.vscale_rplan["s"]}" + name = "${var.devs[count.index]}" + + provisioner "remote-exec" { + inline = [ + "sudo yum update", + "hostnamectl set-hostname ${var.devs[count.index]}" + ] + connection { + type = "ssh" + user = "root" + private_key = "${file("~/.ssh/id_rsa")}" + } + } +} + +# Write credentials to file +resource "null_resource" "devstxt" { + count = "${length(var.devs)}" + provisioner "local-exec" { + command = "echo ${var.devs[count.index]} ${vscale_scalet.test.*.public_address[count.index]}) >> ./devs.txt" + } +} diff --git a/example/outputs.tf b/example/outputs.tf new file mode 100755 index 0000000..04889ab --- /dev/null +++ b/example/outputs.tf @@ -0,0 +1,7 @@ +output "Public ip" { + value = "${vscale_scalet.test.*.public_address}" +} + +output "Name" { + value = "${vscale_scalet.test.*.name}" +} diff --git a/example/variable.tf b/example/variable.tf new file mode 100755 index 0000000..bf31f67 --- /dev/null +++ b/example/variable.tf @@ -0,0 +1,38 @@ +# #### + +# Default region + +variable "vscale_msk" { + description = "vscale MSK data" + default = "msk0" +} + +# Default Os + +variable "vscale_centos_7" { + description = "centos" + default = "centos_7_64_001_master" +} + +# plans + +variable "vscale_rplan" { + type = "map" + default = { + "s" = "small" + "m" = "medium" + "l" = "large" + "xl" = "huge" + "xxl" = "monster" + } +} + +# dns record prefix + +variable "devs" { + + type = "list" + + default = ["dev1.vganin", "dev2.vganin"] + +} From 5b103b15d37e2e4fdbdd91d18b29c271e98cba03 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Sun, 10 Feb 2019 01:14:23 +0300 Subject: [PATCH 10/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c1455e..cd96501 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,4 @@ Building The Provider Using the provider ---------------------- -See the [DigitalOcean Provider documentation](https://www.terraform.io/docs/providers/do/index.html) to get started using the DigitalOcean provider. +See [example](https://github.com/vganyn/terraform-provider-vscale/tree/master/example) to create scalets from list defined in devs variable. From 098486551b9fcb736e8c1800268c247db6237e78 Mon Sep 17 00:00:00 2001 From: Viktor Ganin Date: Sun, 10 Feb 2019 01:24:21 +0300 Subject: [PATCH 11/11] Update variable.tf --- example/variable.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/variable.tf b/example/variable.tf index bf31f67..0b40185 100755 --- a/example/variable.tf +++ b/example/variable.tf @@ -33,6 +33,6 @@ variable "devs" { type = "list" - default = ["dev1.vganin", "dev2.vganin"] + default = ["dev1", "dev2"] }