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

add hostname parameter for scalet and example #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 10 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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.
42 changes: 42 additions & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions example/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "Public ip" {
value = "${vscale_scalet.test.*.public_address}"
}

output "Name" {
value = "${vscale_scalet.test.*.name}"
}
38 changes: 38 additions & 0 deletions example/variable.tf
Original file line number Diff line number Diff line change
@@ -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"]

}
2 changes: 1 addition & 1 deletion provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion resource_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions resource_scalet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion resource_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down