Skip to content

Commit

Permalink
Allow updating of resource policies in compute_disk (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Sep 18, 2019
1 parent f93c9cd commit 3d7c4ba
Show file tree
Hide file tree
Showing 2 changed files with 428 additions and 0 deletions.
71 changes: 71 additions & 0 deletions google/compute_disk_resource_policy_attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 (
"fmt"
"reflect"
)

func GetComputeDiskResourcePolicyAttachmentCaiObject(d TerraformResourceData, config *Config) (Asset, error) {
name, err := assetName(d, config, "//compute.googleapis.com/projects/{{project}}/zones/{{zone}}/disks/{{disk}}")
if err != nil {
return Asset{}, err
}
if obj, err := GetComputeDiskResourcePolicyAttachmentApiObject(d, config); err == nil {
return Asset{
Name: name,
Type: "compute.googleapis.com/DiskResourcePolicyAttachment",
Resource: &AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
DiscoveryName: "DiskResourcePolicyAttachment",
Data: obj,
},
}, nil
} else {
return Asset{}, err
}
}

func GetComputeDiskResourcePolicyAttachmentApiObject(d TerraformResourceData, config *Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
nameProp, err := expandComputeDiskResourcePolicyAttachmentName(d.Get("name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}

return resourceComputeDiskResourcePolicyAttachmentEncoder(d, config, obj)
}

func resourceComputeDiskResourcePolicyAttachmentEncoder(d TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return nil, err
}

region := getRegionFromZone(d.Get("zone").(string))

obj["resourcePolicies"] = []interface{}{fmt.Sprintf("projects/%s/regions/%s/resourcePolicies/%s", project, region, obj["name"])}
delete(obj, "name")
return obj, nil
}

func expandComputeDiskResourcePolicyAttachmentName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Loading

0 comments on commit 3d7c4ba

Please sign in to comment.