diff --git a/README.md b/README.md index 3472ce3..cd96501 100644 --- a/README.md +++ b/README.md @@ -16,49 +16,17 @@ 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/vganyn/terraform-provider-vscale +* cd $GOPATH/src/github.com/terraform-providers/terraform-provider-$PROVIDER_NAME +* go get +* go build +* mkdir -p ~/.terraform.d/plugins/ +* mv terraform-provider-$PROVIDER_NAME ~/.terraform.d/plugins/ 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 -``` +See [example](https://github.com/vganyn/terraform-provider-vscale/tree/master/example) to create scalets from list defined in devs variable. 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..0b40185 --- /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", "dev2"] + +} 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_scalet.go b/resource_scalet.go index 9bc7b2f..038b9f9 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 { @@ -18,7 +18,12 @@ 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, @@ -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") } 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 {