Changes to handle autogeneration. (#1087)

* Add Set method to TerraformResourceData and ResourceDataMock

* Add Id() and SetId() to ResourceDataMock and TerraformResourceData

* Keep only name when reading region or zone field to handle api that returns self_link
This commit is contained in:
Vincent Roseberry 2018-02-15 15:32:31 -08:00 committed by GitHub
parent 7477c7482c
commit 4b1fdee504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View File

@ -38,6 +38,9 @@ func Convert(item, out interface{}) error {
type TerraformResourceData interface {
HasChange(string) bool
GetOk(string) (interface{}, bool)
Set(string, interface{}) error
SetId(string)
Id() string
}
// Compare the fields set in schema against a list of features and their versions to determine

View File

@ -206,6 +206,7 @@ func TestComputeApiVersion(t *testing.T) {
type ResourceDataMock struct {
FieldsInSchema map[string]interface{}
FieldsWithHasChange []string
id string
}
func (d *ResourceDataMock) HasChange(key string) bool {
@ -228,3 +229,16 @@ func (d *ResourceDataMock) GetOk(key string) (interface{}, bool) {
return nil, false
}
func (d *ResourceDataMock) Set(key string, value interface{}) error {
d.FieldsInSchema[key] = value
return nil
}
func (d *ResourceDataMock) SetId(v string) {
d.id = v
}
func (d *ResourceDataMock) Id() string {
return d.id
}

View File

@ -318,7 +318,7 @@ func parseRegionalFieldValue(resourceType, fieldValue, projectSchemaField, regio
// - region extracted from the provider-level zone
func getRegionFromSchema(regionSchemaField, zoneSchemaField string, d TerraformResourceData, config *Config) (string, error) {
if v, ok := d.GetOk(regionSchemaField); ok && regionSchemaField != "" {
return v.(string), nil
return GetResourceNameFromSelfLink(v.(string)), nil
}
if v, ok := d.GetOk(zoneSchemaField); ok && zoneSchemaField != "" {
return getRegionFromZone(v.(string)), nil

View File

@ -45,7 +45,7 @@ func getZone(d TerraformResourceData, config *Config) (string, error) {
}
return "", fmt.Errorf("Cannot determine zone: set in this resource, or set provider-level zone.")
}
return res.(string), nil
return GetResourceNameFromSelfLink(res.(string)), nil
}
func getRegionFromInstanceState(is *terraform.InstanceState, config *Config) (string, error) {