Merge pull request #5785 from ack/clc-patches

CLC update: tests and alias
This commit is contained in:
albert 2016-03-22 12:39:20 -07:00
commit fdc105ac4d
9 changed files with 98 additions and 122 deletions

36
Godeps/Godeps.json generated
View File

@ -152,48 +152,48 @@
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/aa",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/alert",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/api",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/dc",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/group",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/lb",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/server",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/CenturyLinkCloud/clc-sdk/status",
"Comment": "0.0.2-19-gbe16cca",
"Rev": "be16cca3fa780c77916e52370a9c89cc53bcf73a"
"Comment": "0.0.2-20-gd546567",
"Rev": "d546567abc945ad52d1906fc6c7caa8f903e7445"
},
{
"ImportPath": "github.com/DreamItGetIT/statuscake",

View File

@ -30,6 +30,12 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("CLC_PASSWORD", nil),
Description: "Your CLC password",
},
"account": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CLC_ACCOUNT", ""),
Description: "Account alias override",
},
},
ResourcesMap: map[string]*schema.Resource{
@ -53,6 +59,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, fmt.Errorf("Failed to create CLC config with provided details: %v", err)
}
config.UserAgent = fmt.Sprintf("terraform-clc terraform/%s", terraform.Version)
// user requested alias override or sub-account
if al := d.Get("account").(string); al != "" {
config.Alias = al
}
client := clc.New(config)
if err := client.Authenticate(); err != nil {

View File

@ -109,6 +109,7 @@ func resourceCLCLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) err
update.Status = d.Get("status").(string)
}
if update.Name != "" || update.Description != "" || update.Status != "" {
update.Name = d.Get("name").(string) // required on every PUT
err := client.LB.Update(dc, id, update)
if err != nil {
return fmt.Errorf("Failed updating load balancer under %v/%v: %v", dc, id, err)

View File

@ -29,6 +29,15 @@ func TestAccLBPoolBasic(t *testing.T) {
resource.TestCheckResourceAttr("clc_load_balancer_pool.acc_test_pool", "port", "80"),
),
},
resource.TestStep{
Config: testAccCheckLBPConfigUpdates,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBPExists("clc_load_balancer_pool.acc_test_pool", &pool),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lbp", "description", "description modified"),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lbp", "status", "disabled"),
resource.TestCheckResourceAttr("clc_load_balancer_pool.acc_test_pool", "nodes.0.privatePort", "8080"),
),
},
},
})
}
@ -85,7 +94,7 @@ resource "clc_group" "acc_test_lbp_group" {
# need a server here because we need to reference an ip owned by this account
resource "clc_server" "acc_test_lbp_server" {
name_template = "node"
description = "load balanced in ${clc_load_balancer.acc_test_lbp.id}"
description = "load balanced"
source_server_id = "UBUNTU-14-64-TEMPLATE"
type = "standard"
group_id = "${clc_group.acc_test_lbp_group.id}"
@ -101,6 +110,7 @@ resource "clc_load_balancer" "acc_test_lbp" {
name = "acc_test_lb"
description = "load balancer test"
status = "enabled"
depends_on = ["clc_server.acc_test_lbp_server"]
}
resource "clc_load_balancer_pool" "acc_test_pool" {
@ -113,5 +123,51 @@ resource "clc_load_balancer_pool" "acc_test_pool" {
ipAddress = "${clc_server.acc_test_lbp_server.private_ip_address}"
privatePort = 80
}
depends_on = ["clc_server.acc_test_lbp_server"]
}
`
const testAccCheckLBPConfigUpdates = `
variable "dc" { default = "IL1" }
resource "clc_group" "acc_test_lbp_group" {
location_id = "${var.dc}"
name = "acc_test_lbp_group"
parent = "Default Group"
}
# need a server here because we need to reference an ip owned by this account
resource "clc_server" "acc_test_lbp_server" {
name_template = "node"
description = "load balanced"
source_server_id = "UBUNTU-14-64-TEMPLATE"
type = "standard"
group_id = "${clc_group.acc_test_lbp_group.id}"
cpu = 1
memory_mb = 1024
password = "Green123$"
power_state = "started"
}
resource "clc_load_balancer" "acc_test_lbp" {
data_center = "${var.dc}"
name = "acc_test_lb"
description = "description modified"
status = "disabled"
depends_on = ["clc_server.acc_test_lbp_server"]
}
resource "clc_load_balancer_pool" "acc_test_pool" {
port = 80
data_center = "${var.dc}"
load_balancer = "${clc_load_balancer.acc_test_lbp.id}"
nodes
{
status = "enabled"
ipAddress = "${clc_server.acc_test_lbp_server.private_ip_address}"
privatePort = 8080
}
depends_on = ["clc_server.acc_test_lbp_server"]
}
`

View File

@ -1,101 +1,3 @@
package clc
import (
"fmt"
"testing"
clc "github.com/CenturyLinkCloud/clc-sdk"
lb "github.com/CenturyLinkCloud/clc-sdk/lb"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
// things to test:
// updates name/desc
// toggles status
// created w/o pool
func TestAccLoadBalancerBasic(t *testing.T) {
var resp lb.LoadBalancer
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckLBConfigBasic,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBExists("clc_load_balancer.acc_test_lb", &resp),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "name", "acc_test_lb"),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "data_center", testAccDC),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "status", "enabled"),
),
},
// update simple attrs
resource.TestStep{
Config: testAccCheckLBConfigNameDesc,
Check: resource.ComposeTestCheckFunc(
testAccCheckLBExists("clc_load_balancer.acc_test_lb", &resp),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "name", "foobar"),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "description", "foobar"),
resource.TestCheckResourceAttr("clc_load_balancer.acc_test_lb", "status", "disabled"),
),
},
},
})
}
func testAccCheckLBDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*clc.Client)
for _, rs := range s.RootModule().Resources {
if rs.Type != "clc_load_balancer" {
continue
}
if _, err := client.LB.Get(testAccDC, rs.Primary.ID); err == nil {
return fmt.Errorf("LB still exists")
}
}
return nil
}
func testAccCheckLBExists(n string, resp *lb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
client := testAccProvider.Meta().(*clc.Client)
l, err := client.LB.Get(testAccDC, rs.Primary.ID)
if err != nil {
return err
}
if l.ID != rs.Primary.ID {
return fmt.Errorf("LB not found")
}
*resp = *l
return nil
}
}
const testAccCheckLBConfigBasic = `
variable "dc" { default = "IL1" }
resource "clc_load_balancer" "acc_test_lb" {
data_center = "${var.dc}"
name = "acc_test_lb"
description = "load balancer test"
status = "enabled"
}`
const testAccCheckLBConfigNameDesc = `
variable "dc" { default = "IL1" }
resource "clc_load_balancer" "acc_test_lb" {
data_center = "${var.dc}"
name = "foobar"
description = "foobar"
status = "disabled"
}`
// clc_load_balancer covered by clc_load_balancer_pool tests: resource_clc_load_balancer_pool_test.go

View File

@ -78,7 +78,7 @@ func (c *Client) Auth() error {
}
err = c.Do(req, &c.Token)
if err == nil {
if err == nil && c.config.Alias == "" {
// set Alias from returned token
c.config.Alias = c.Token.Alias
}

View File

@ -25,7 +25,7 @@ For additional documentation, see the [CLC Developer Center](https://www.ctl.io/
provider "clc" {
username = "${var.clc_username}"
password = "${var.clc_password}"
account = "${var.clc_account}"
account = "${var.clc_account}" # optional
}
# Create a server
@ -55,5 +55,5 @@ The following arguments are supported:
* `clc_password` - (Required) This is the CLC account password. It must be provided, but
it can also be sourced from the `CLC_PASSWORD` environment variable.
* `clc_account` - (Required) This is the CLC account alias. It must be provided, but
it can also be sourced from the `CLC_ACCOUNT` environment variable.
* `clc_account` - (Optional) Override CLC account alias. Also taken from the `CLC_ACCOUNT`
environment variable if provided.

View File

@ -29,6 +29,12 @@ resource "clc_load_balancer_pool" "pool" {
ipAddress = "${clc_server.node.0.private_ip_address}"
privatePort = 3000
}
nodes
{
status = "enabled"
ipAddress = "${clc_server.node.1.private_ip_address}"
privatePort = 3000
}
}
output "pool" {

View File

@ -67,6 +67,7 @@ The following arguments are supported:
One of "standard", "premium"
* `additional_disks` - (Optional) See [Disks](#disks) below for details.
* `custom_fields` - (Optional) See [CustomFields](#custom_fields) below for details.
* `metadata` - (Optional) Misc state storage for non-CLC metadata.