forked from GoogleCloudPlatform/terraform-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ability to create "non-custom" services (#6604)
* Support ability to create "non-custom" services Allow users to create various Service Monitoring services: App Engine, Cloud Run, etc. hashicorp/terraform-provider-google#11935 * Specify BasicService is immutable * Responding to review comments. * Add test; make service_id required * labels still need input: true; remove encoder * Correct typo * Ignore service fields in SLO import test * Correct test * Make id_format and import_format the same * Remove custom code * Correct test typo * service is actually input-only * Add resource test Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
c7e365b
commit ed603d0
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
converters/google/resources/monitoring_generic_service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import "reflect" | ||
|
||
const MonitoringGenericServiceAssetType string = "monitoring.googleapis.com/GenericService" | ||
|
||
func resourceConverterMonitoringGenericService() ResourceConverter { | ||
return ResourceConverter{ | ||
AssetType: MonitoringGenericServiceAssetType, | ||
Convert: GetMonitoringGenericServiceCaiObject, | ||
} | ||
} | ||
|
||
func GetMonitoringGenericServiceCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { | ||
name, err := assetName(d, config, "//monitoring.googleapis.com/projects/{{project}}/services/{{service_id}}") | ||
if err != nil { | ||
return []Asset{}, err | ||
} | ||
if obj, err := GetMonitoringGenericServiceApiObject(d, config); err == nil { | ||
return []Asset{{ | ||
Name: name, | ||
Type: MonitoringGenericServiceAssetType, | ||
Resource: &AssetResource{ | ||
Version: "v3", | ||
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/monitoring/v3/rest", | ||
DiscoveryName: "GenericService", | ||
Data: obj, | ||
}, | ||
}}, nil | ||
} else { | ||
return []Asset{}, err | ||
} | ||
} | ||
|
||
func GetMonitoringGenericServiceApiObject(d TerraformResourceData, config *Config) (map[string]interface{}, error) { | ||
obj := make(map[string]interface{}) | ||
displayNameProp, err := expandMonitoringGenericServiceDisplayName(d.Get("display_name"), d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { | ||
obj["displayName"] = displayNameProp | ||
} | ||
userLabelsProp, err := expandMonitoringGenericServiceUserLabels(d.Get("user_labels"), d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if v, ok := d.GetOkExists("user_labels"); ok || !reflect.DeepEqual(v, userLabelsProp) { | ||
obj["userLabels"] = userLabelsProp | ||
} | ||
basicServiceProp, err := expandMonitoringGenericServiceBasicService(d.Get("basic_service"), d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if v, ok := d.GetOkExists("basic_service"); !isEmptyValue(reflect.ValueOf(basicServiceProp)) && (ok || !reflect.DeepEqual(v, basicServiceProp)) { | ||
obj["basicService"] = basicServiceProp | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
func expandMonitoringGenericServiceDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandMonitoringGenericServiceUserLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) { | ||
if v == nil { | ||
return map[string]string{}, nil | ||
} | ||
m := make(map[string]string) | ||
for k, val := range v.(map[string]interface{}) { | ||
m[k] = val.(string) | ||
} | ||
return m, nil | ||
} | ||
|
||
func expandMonitoringGenericServiceBasicService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
l := v.([]interface{}) | ||
if len(l) == 0 || l[0] == nil { | ||
return nil, nil | ||
} | ||
raw := l[0] | ||
original := raw.(map[string]interface{}) | ||
transformed := make(map[string]interface{}) | ||
|
||
transformedServiceType, err := expandMonitoringGenericServiceBasicServiceServiceType(original["service_type"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedServiceType); val.IsValid() && !isEmptyValue(val) { | ||
transformed["serviceType"] = transformedServiceType | ||
} | ||
|
||
transformedServiceLabels, err := expandMonitoringGenericServiceBasicServiceServiceLabels(original["service_labels"], d, config) | ||
if err != nil { | ||
return nil, err | ||
} else if val := reflect.ValueOf(transformedServiceLabels); val.IsValid() && !isEmptyValue(val) { | ||
transformed["serviceLabels"] = transformedServiceLabels | ||
} | ||
|
||
return transformed, nil | ||
} | ||
|
||
func expandMonitoringGenericServiceBasicServiceServiceType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||
return v, nil | ||
} | ||
|
||
func expandMonitoringGenericServiceBasicServiceServiceLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) { | ||
if v == nil { | ||
return map[string]string{}, nil | ||
} | ||
m := make(map[string]string) | ||
for k, val := range v.(map[string]interface{}) { | ||
m[k] = val.(string) | ||
} | ||
return m, nil | ||
} |