Changes based on review including default values in schema and inlining object properties.

This commit is contained in:
Riley Karson 2017-06-26 13:33:05 -07:00 committed by Riley Karson
parent 53b91630f5
commit 2c2615317b
4 changed files with 45 additions and 29 deletions

View File

@ -90,18 +90,18 @@ func (c *Config) loadAndValidate() error {
// Initiate an http.Client. The following GET request will be
// authorized and authenticated on the behalf of
// your service account.
client = conf.Client(oauth2.NoContext)
client = conf.Client(context.Background())
tokenSource = conf.TokenSource(context.Background())
} else {
log.Printf("[INFO] Authenticating using DefaultClient")
err := error(nil)
client, err = google.DefaultClient(oauth2.NoContext, clientScopes...)
client, err = google.DefaultClient(context.Background(), clientScopes...)
if err != nil {
return err
}
tokenSource, err = google.DefaultTokenSource(oauth2.NoContext, clientScopes...)
tokenSource, err = google.DefaultTokenSource(context.Background(), clientScopes...)
if err != nil {
return err
}

View File

@ -37,17 +37,18 @@ func resourceBigtableInstance() *schema.Resource {
},
"num_nodes": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
// 30 is the maximum number of nodes without a quota increase.
ValidateFunc: validation.IntBetween(3, 30),
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 3,
ValidateFunc: IntAtLeast(3),
},
"storage_type": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
Default: "SSD",
ValidateFunc: validation.StringInSlice([]string{"SSD", "HDD"}, false),
},
@ -81,10 +82,6 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er
displayName = name
}
clusterId := d.Get("cluster_id").(string)
numNodes := int32(d.Get("num_nodes").(int))
zone := d.Get("zone").(string)
var storageType bigtable.StorageType
switch value := d.Get("storage_type"); value {
case "HDD":
@ -96,10 +93,10 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er
instanceConf := &bigtable.InstanceConf{
InstanceId: name,
DisplayName: displayName.(string),
ClusterId: clusterId,
NumNodes: numNodes,
ClusterId: d.Get("cluster_id").(string),
NumNodes: int32(d.Get("num_nodes").(int)),
StorageType: storageType,
Zone: zone,
Zone: d.Get("zone").(string),
}
c, err := config.clientFactoryBigtable.NewInstanceAdminClient(project)
@ -135,13 +132,13 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro
defer c.Close()
name := d.Id()
instances, err := c.Instances(ctx)
if err != nil {
return fmt.Errorf("Error retrieving instances. %s", err)
}
var instanceInfo *bigtable.InstanceInfo
name := d.Id()
found := false
for _, i := range instances {
if i.Name == name {
@ -186,3 +183,22 @@ func resourceBigtableInstanceDestroy(d *schema.ResourceData, meta interface{}) e
return nil
}
// IntAtLeast returns a SchemaValidateFunc which tests if the provided value
// is of type int and is above min (inclusive)
func IntAtLeast(min int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(int)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be int", k))
return
}
if v < min {
es = append(es, fmt.Errorf("expected %s to be at least %d, got %d", k, min, v))
return
}
return
}
}

View File

@ -108,11 +108,11 @@ func testAccBigtableInstanceExists(n string) resource.TestCheckFunc {
func testAccBigtableInstance(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
name = "%s"
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
`, instanceName, instanceName)
}

View File

@ -17,10 +17,10 @@ Creates a Google Bigtable instance. For more information see
```hcl
resource "google_bigtable_instance" "instance" {
name = "tf-instance"
cluster_id = "tf-instance-cluster"
zone = "us-central1-b"
num_nodes = 3
name = "tf-instance"
cluster_id = "tf-instance-cluster"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
```
@ -33,11 +33,11 @@ The following arguments are supported:
* `cluster_id` - (Required) The name of the Bigtable instance's cluster.
* `zone` - (Required) The zone to create the Bigtable instance in. Note: Many zones do not support Bigtable instances.
* `zone` - (Required) The zone to create the Bigtable instance in. Zones that support Bigtable instances are noted on the [Cloud Locations page](https://cloud.google.com/about/locations/).
* `num_nodes` - (Required) The number of nodes in your Bigtable instance. Minimum of 3.
* `num_nodes` - (Required) The number of nodes in your Bigtable instance. Minimum of `3`. Defaults to `3`.
* `storage_type` - (Required) The storage type to use. One of `"SSD"` or `"HDD"`.
* `storage_type` - (Required) The storage type to use. One of `"SSD"` or `"HDD"`. Defaults to `SSD`.
* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.