Skip to content

Commit

Permalink
Migrate google_compute_firewall_policy_association resource from DCL …
Browse files Browse the repository at this point in the history
…to MMv1 (#12466) (#3236)

[upstream:613bdaee0c0243e40465a7b5497693b9720eeb85]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 18, 2024
1 parent b502893 commit 681b545
Show file tree
Hide file tree
Showing 3 changed files with 97 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.20.1
github.com/hashicorp/terraform-json v0.22.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218192634-ae34c9b67b6e
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218213445-808cc55ce173
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A=
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218192634-ae34c9b67b6e h1:pcftXQqZrhQQnfkv9fXT8HjD2eoi0MX53MqWUv36RBI=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218192634-ae34c9b67b6e/go.mod h1:+3tdRXgcI0aDAIH8vCVW2qAfcn7JiGlEv8RGuQJp6yY=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218213445-808cc55ce173 h1:Xv0/CLf3xKNCHwCVw5wHFvbFRQgXMdLSOZcwuYJ/JiY=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20241218213445-808cc55ce173/go.mod h1:+3tdRXgcI0aDAIH8vCVW2qAfcn7JiGlEv8RGuQJp6yY=
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,94 @@
// ----------------------------------------------------------------------------
//
// *** 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 compute

import (
"fmt"
"reflect"

"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"
)

const ComputeFirewallPolicyAssociationAssetType string = "compute.googleapis.com/FirewallPolicyAssociation"

func ResourceConverterComputeFirewallPolicyAssociation() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ComputeFirewallPolicyAssociationAssetType,
Convert: GetComputeFirewallPolicyAssociationCaiObject,
}
}

func GetComputeFirewallPolicyAssociationCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//compute.googleapis.com/locations/global/firewallPolicies/{{firewall_policy}}/getAssociation?name={{name}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetComputeFirewallPolicyAssociationApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: ComputeFirewallPolicyAssociationAssetType,
Resource: &cai.AssetResource{
Version: "beta",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/compute/beta/rest",
DiscoveryName: "FirewallPolicyAssociation",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetComputeFirewallPolicyAssociationApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
nameProp, err := expandComputeFirewallPolicyAssociationName(d.Get("name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
attachmentTargetProp, err := expandComputeFirewallPolicyAssociationAttachmentTarget(d.Get("attachment_target"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("attachment_target"); !tpgresource.IsEmptyValue(reflect.ValueOf(attachmentTargetProp)) && (ok || !reflect.DeepEqual(v, attachmentTargetProp)) {
obj["attachmentTarget"] = attachmentTargetProp
}
firewallPolicyProp, err := expandComputeFirewallPolicyAssociationFirewallPolicy(d.Get("firewall_policy"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("firewall_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(firewallPolicyProp)) && (ok || !reflect.DeepEqual(v, firewallPolicyProp)) {
obj["firewallPolicy"] = firewallPolicyProp
}

return obj, nil
}

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

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

func expandComputeFirewallPolicyAssociationFirewallPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
firewallPolicyId := tpgresource.GetResourceNameFromSelfLink(v.(string))
if err := d.Set("firewall_policy", firewallPolicyId); err != nil {
return nil, fmt.Errorf("Error setting firewall_policy: %s", err)
}
return firewallPolicyId, nil
}

0 comments on commit 681b545

Please sign in to comment.