Merge pull request #586 from svanharmelen/f-update-google-provider
Fix acc tests and updated the provider schema to use a DefaultFunc
This commit is contained in:
commit
b7de15f8b9
|
@ -29,20 +29,6 @@ func (c *Config) loadAndValidate() error {
|
||||||
var account accountFile
|
var account accountFile
|
||||||
var secrets clientSecretsFile
|
var secrets clientSecretsFile
|
||||||
|
|
||||||
// TODO: validation that it isn't blank
|
|
||||||
if c.AccountFile == "" {
|
|
||||||
c.AccountFile = os.Getenv("GOOGLE_ACCOUNT_FILE")
|
|
||||||
}
|
|
||||||
if c.ClientSecretsFile == "" {
|
|
||||||
c.ClientSecretsFile = os.Getenv("GOOGLE_CLIENT_FILE")
|
|
||||||
}
|
|
||||||
if c.Project == "" {
|
|
||||||
c.Project = os.Getenv("GOOGLE_PROJECT")
|
|
||||||
}
|
|
||||||
if c.Region == "" {
|
|
||||||
c.Region = os.Getenv("GOOGLE_REGION")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := loadJSON(&account, c.AccountFile); err != nil {
|
if err := loadJSON(&account, c.AccountFile); err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Error loading account file '%s': %s",
|
"Error loading account file '%s': %s",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -10,23 +12,27 @@ func Provider() terraform.ResourceProvider {
|
||||||
return &schema.Provider{
|
return &schema.Provider{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"account_file": &schema.Schema{
|
"account_file": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
DefaultFunc: envDefaultFunc("GOOGLE_ACCOUNT_FILE"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"client_secrets_file": &schema.Schema{
|
"client_secrets_file": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
DefaultFunc: envDefaultFunc("GOOGLE_CLIENT_FILE"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
DefaultFunc: envDefaultFunc("GOOGLE_PROJECT"),
|
||||||
},
|
},
|
||||||
|
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
DefaultFunc: envDefaultFunc("GOOGLE_REGION"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -43,6 +49,16 @@ func Provider() terraform.ResourceProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
||||||
|
return func() (interface{}, error) {
|
||||||
|
if v := os.Getenv(k); v != "" {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
config := Config{
|
config := Config{
|
||||||
AccountFile: d.Get("account_file").(string),
|
AccountFile: d.Get("account_file").(string),
|
||||||
|
|
|
@ -40,4 +40,8 @@ func testAccPreCheck(t *testing.T) {
|
||||||
if v := os.Getenv("GOOGLE_PROJECT"); v == "" {
|
if v := os.Getenv("GOOGLE_PROJECT"); v == "" {
|
||||||
t.Fatal("GOOGLE_PROJECT must be set for acceptance tests")
|
t.Fatal("GOOGLE_PROJECT must be set for acceptance tests")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v := os.Getenv("GOOGLE_REGION"); v != "us-central1" {
|
||||||
|
t.Fatal("GOOGLE_REGION must be set to us-central1 for acceptance tests")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -514,10 +514,10 @@ func resourceInstanceTags(d *schema.ResourceData) *compute.Tags {
|
||||||
// Calculate the tags
|
// Calculate the tags
|
||||||
var tags *compute.Tags
|
var tags *compute.Tags
|
||||||
if v := d.Get("tags"); v != nil {
|
if v := d.Get("tags"); v != nil {
|
||||||
vs := v.(*schema.Set).List()
|
vs := v.(*schema.Set)
|
||||||
tags = new(compute.Tags)
|
tags = new(compute.Tags)
|
||||||
tags.Items = make([]string, len(vs))
|
tags.Items = make([]string, vs.Len())
|
||||||
for i, v := range v.(*schema.Set).List() {
|
for i, v := range vs.List() {
|
||||||
tags.Items[i] = v.(string)
|
tags.Items[i] = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,6 @@ func TestAccComputeInstance_IP(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//!NB requires that disk with name terraform-test-disk is present in gce,
|
|
||||||
//if created as dependency then it tries to remove it while it is still attached
|
|
||||||
//to instance and that fails with an error
|
|
||||||
func TestAccComputeInstance_disks(t *testing.T) {
|
func TestAccComputeInstance_disks(t *testing.T) {
|
||||||
var instance compute.Instance
|
var instance compute.Instance
|
||||||
|
|
||||||
|
@ -66,6 +63,8 @@ func TestAccComputeInstance_disks(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccComputeInstance_disks,
|
Config: testAccComputeInstance_disks,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists(
|
||||||
|
"google_compute_instance.foobar", &instance),
|
||||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
|
||||||
testAccCheckComputeInstanceDisk(&instance, "terraform-test-disk", false, false),
|
testAccCheckComputeInstanceDisk(&instance, "terraform-test-disk", false, false),
|
||||||
),
|
),
|
||||||
|
@ -287,6 +286,13 @@ resource "google_compute_instance" "foobar" {
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const testAccComputeInstance_disks = `
|
const testAccComputeInstance_disks = `
|
||||||
|
resource "google_compute_disk" "foobar" {
|
||||||
|
name = "terraform-test-disk"
|
||||||
|
size = 10
|
||||||
|
type = "pd-ssd"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
}
|
||||||
|
|
||||||
resource "google_compute_instance" "foobar" {
|
resource "google_compute_instance" "foobar" {
|
||||||
name = "terraform-test"
|
name = "terraform-test"
|
||||||
machine_type = "n1-standard-1"
|
machine_type = "n1-standard-1"
|
||||||
|
@ -297,9 +303,8 @@ resource "google_compute_instance" "foobar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
disk {
|
disk {
|
||||||
disk = "terraform-test-disk"
|
disk = "${google_compute_disk.foobar.name}"
|
||||||
auto_delete = false
|
auto_delete = false
|
||||||
type = "pd-ssd"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
network {
|
network {
|
||||||
|
|
Loading…
Reference in New Issue