mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
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:
parent
7477c7482c
commit
4b1fdee504
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user