-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate google_compute_firewall_policy_association resource from DCL …
…to MMv1 (#12466) (#3236) [upstream:613bdaee0c0243e40465a7b5497693b9720eeb85] Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
b502893
commit 681b545
Showing
3 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
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
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
94 changes: 94 additions & 0 deletions
94
...n2cai/converters/google/resources/services/compute/compute_firewall_policy_association.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,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 | ||
} |