Skip to content

Commit

Permalink
Add new resource for Service Project for Apphub (#10048) (#2034)
Browse files Browse the repository at this point in the history
FIXES hashicorp/terraform-provider-google#17405

[upstream:ab2122202ab62d620cbbbc8928078b0782146994]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 9, 2024
1 parent e988ba5 commit f6651dc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/terraform-json v0.18.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240308220643-02cd818b0a15
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240309000314-98d493863f1d
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwU
github.com/hashicorp/terraform-plugin-mux v0.13.0 h1:79U401/3nd8CWwDGtTHc8F3miSCAS9XGtVarxSTDgwA=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 h1:Bl3e2ei2j/Z3Hc2HIS15Gal2KMKyLAZ2om1HCEvK6es=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240308220643-02cd818b0a15 h1:4vvSyMbYgdsJJFKIQb38a9g4fozSsoNVXAPZzQvgNu0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240308220643-02cd818b0a15/go.mod h1:xqktgz44XcXx24WFlm6lYZEri5YeyyFGL+qBamSShDc=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240309000314-98d493863f1d h1:Shy/AEGfW5/0NJhH9pfAK1ngiGAaX28ujOXUBlawgZ0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240309000314-98d493863f1d/go.mod h1:xqktgz44XcXx24WFlm6lYZEri5YeyyFGL+qBamSShDc=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// ----------------------------------------------------------------------------
//
// *** 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 apphub

import (
"reflect"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

// Suppress all diff for the field Service Project
func ServiceProjectDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool {
return true
}

const ApphubServiceProjectAttachmentAssetType string = "apphub.googleapis.com/ServiceProjectAttachment"

func ResourceConverterApphubServiceProjectAttachment() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ApphubServiceProjectAttachmentAssetType,
Convert: GetApphubServiceProjectAttachmentCaiObject,
}
}

func GetApphubServiceProjectAttachmentCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//apphub.googleapis.com/projects/{{project}}/locations/global/serviceProjectAttachments/{{service_project_attachment_id}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetApphubServiceProjectAttachmentApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: ApphubServiceProjectAttachmentAssetType,
Resource: &cai.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/apphub/v1/rest",
DiscoveryName: "ServiceProjectAttachment",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetApphubServiceProjectAttachmentApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
serviceProjectProp, err := expandApphubServiceProjectAttachmentServiceProject(d.Get("service_project"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("service_project"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceProjectProp)) && (ok || !reflect.DeepEqual(v, serviceProjectProp)) {
obj["serviceProject"] = serviceProjectProp
}

return obj, nil
}

func expandApphubServiceProjectAttachmentServiceProject(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {

service_project := "projects/" + d.Get("service_project_attachment_id").(string)

return service_project, nil
}

0 comments on commit f6651dc

Please sign in to comment.