Skip to content

Commit

Permalink
Split tgc converters
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 committed Oct 1, 2024
1 parent 02d6c97 commit 0fae600
Show file tree
Hide file tree
Showing 51 changed files with 225 additions and 224 deletions.
153 changes: 77 additions & 76 deletions mmv1/provider/terraform_tgc.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions mmv1/third_party/tgc/cai/string_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cai

func ConvertInterfaceToStringArray(values []interface{}) []string {
stringArray := make([]string, len(values))
for i, v := range values {
stringArray[i] = v.(string)
}
return stringArray
}
4 changes: 2 additions & 2 deletions mmv1/third_party/tgc/firebase_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GetFirebaseProjectCaiObject(d tpgresource.TerraformResourceData, config *tr

func GetFirebaseProjectApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})

nameProp, err := expandFirebaseProjectName(d.Get("name"), d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,4 +102,4 @@ func expandFirebaseProjectProjectId(v interface{}, d tpgresource.TerraformResour

func expandFirebaseProjectName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
}
89 changes: 46 additions & 43 deletions mmv1/third_party/tgc/resource_converters.go.tmpl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package apikeys

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const ApikeysKeyAssetType string = "apikeys.googleapis.com/Key"

func resourceConverterApikeysKey() cai.ResourceConverter {
func ResourceConverterApikeysKey() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ApikeysKeyAssetType,
Convert: GetApikeysKeyCaiObject,
Expand Down Expand Up @@ -125,7 +125,7 @@ func expandApikeysKeyDeleteTime(v interface{}, d tpgresource.TerraformResourceDa
}

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

l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
Expand Down Expand Up @@ -203,7 +203,6 @@ func expandApikeysKeySha1Fingerprint(v interface{}, d tpgresource.TerraformResou
return v, nil
}


func expandApikeysKeyApiTargets(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -235,10 +234,9 @@ func expandApikeysKeyService(v interface{}, d tpgresource.TerraformResourceData,
}

func expandApikeysKeyMethods(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return convertInterfaceToStringArray(v.([]interface{})), nil
return cai.ConvertInterfaceToStringArray(v.([]interface{})), nil
}


func expandApikeysKeyDEtag(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package appengine

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const AppEngineApplicationAssetType string = "appengine.googleapis.com/Application"

func resourceConverterAppEngineApplication() cai.ResourceConverter {
func ResourceConverterAppEngineApplication() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: AppEngineApplicationAssetType,
Convert: GetAppEngineApplicationCaiObject,
Expand Down Expand Up @@ -55,15 +55,13 @@ func GetAppEngineApplicationApiObject(d tpgresource.TerraformResourceData, confi
obj["location_id"] = locationIdProp
}


return obj, nil
}

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


func expandAppEngineApplicationLocationId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package appengine

import (
"reflect"
Expand All @@ -12,7 +12,7 @@ import (

const AppEngineVersionAssetType string = "appengine.googleapis.com/Version"

func resourceAppEngineStandardAppVersion() cai.ResourceConverter {
func ResourceAppEngineStandardAppVersion() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: AppEngineVersionAssetType,
Convert: GetAppEngineVersionCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const BigQueryTableAssetType string = "bigquery.googleapis.com/Table"

func resourceConverterBigQueryTable() cai.ResourceConverter {
func ResourceConverterBigQueryTable() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: BigQueryTableAssetType,
Convert: GetBigQueryTableCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigtable

import (
"reflect"
Expand All @@ -8,7 +8,7 @@ import (
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func resourceConverterBigtableCluster() cai.ResourceConverter {
func ResourceConverterBigtableCluster() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: "bigtableadmin.googleapis.com/Cluster",
Convert: GetBigtableClusterCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigtable

import (
"reflect"
Expand All @@ -8,7 +8,7 @@ import (
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func resourceConverterBigtableInstance() cai.ResourceConverter {
func ResourceConverterBigtableInstance() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: "bigtableadmin.googleapis.com/Instance",
Convert: GetBigtableInstanceCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package cloudfunctions

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const CloudFunctionsCloudFunctionAssetType string = "cloudfunctions.googleapis.com/CloudFunction"

func resourceConverterCloudFunctionsCloudFunction() cai.ResourceConverter {
func ResourceConverterCloudFunctionsCloudFunction() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: CloudFunctionsCloudFunctionAssetType,
Convert: GetCloudFunctionsCloudFunctionCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package cloudfunctions

import (
"reflect"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package composer

import (
"reflect"
Expand All @@ -11,7 +11,7 @@ import (

const ComposerEnvironmentAssetType string = "composer.googleapis.com/Environment"

func resourceConverterComposerEnvironment() cai.ResourceConverter {
func ResourceConverterComposerEnvironment() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ComposerEnvironmentAssetType,
Convert: GetComposerEnvironmentCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package compute

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const commitmentAssetType string = "compute.googleapis.com/Commitment"

func resourceConverterCommitment() cai.ResourceConverter {
func ResourceConverterCommitment() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: commitmentAssetType,
Convert: GetCommitmentCaiObject,
Expand Down Expand Up @@ -152,14 +152,14 @@ func GetCommitmentApiObject(d tpgresource.TerraformResourceData, config *transpo
} else if v, ok := d.GetOkExists("start_timestamp"); !tpgresource.IsEmptyValue(reflect.ValueOf(statusMessageProp)) && (ok || !reflect.DeepEqual(v, statusMessageProp)) {
obj["startTimestamp"] = startTimestampProp
}

endTimestampProp, err := expandCommitmentEndTimestamp(d.Get("end_timestamp"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("end_timestamp"); !tpgresource.IsEmptyValue(reflect.ValueOf(endTimestampProp)) && (ok || !reflect.DeepEqual(v, endTimestampProp)) {
obj["endTimestamp"] = endTimestampProp
}

selfLinkProp, err := expandCommitmentSelfLink(d.Get("self_link"), d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -323,4 +323,4 @@ func expandCommitmentPlan(v interface{}, d tpgresource.TerraformResourceData, co

func expandCommitmentName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package compute

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const ComputeInstanceGroupAssetType string = "compute.googleapis.com/InstanceGroup"

func resourceConverterComputeInstanceGroup() cai.ResourceConverter {
func ResourceConverterComputeInstanceGroup() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ComputeInstanceGroupAssetType,
Convert: GetComputeInstanceGroupCaiObject,
Expand Down Expand Up @@ -80,7 +80,7 @@ func GetComputeInstanceGroupApiObject(d tpgresource.TerraformResourceData, confi
}
url = url + zoneProp.(string)

obj["zone"] = url
obj["zone"] = url
}
selfLinkProp, err := expandComputeInstanceGroupSelfLink(d.Get("self_link"), d, config)
if err != nil {
Expand Down Expand Up @@ -152,4 +152,4 @@ func expandComputeInstanceGroupRegion(v interface{}, d tpgresource.TerraformReso

func expandComputeInstanceGroupSubnetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package compute

import (
"reflect"
Expand All @@ -11,7 +11,7 @@ import (

const ComputeSecurityPolicyAssetType string = "compute.googleapis.com/SecurityPolicy"

func resourceConverterComputeSecurityPolicy() cai.ResourceConverter {
func ResourceConverterComputeSecurityPolicy() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ComputeSecurityPolicyAssetType,
Convert: GetComputeSecurityPolicyCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package compute

import (
"reflect"
Expand All @@ -11,7 +11,7 @@ import (

const ComputeTargetPoolAssetType string = "compute.googleapis.com/TargetPool"

func resourceConverterComputeTargetPool() cai.ResourceConverter {
func ResourceConverterComputeTargetPool() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ComputeTargetPoolAssetType,
Convert: GetComputeTargetPoolCaiObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// see https://github.com/GoogleCloudPlatform/magic-modules/pull/2485#issuecomment-545680059
// for the discussion.

package google
package container

import (
"fmt"
Expand All @@ -19,14 +19,14 @@ import (
const ContainerClusterAssetType string = "container.googleapis.com/Cluster"
const ContainerNodePoolAssetType string = "container.googleapis.com/NodePool"

func resourceConverterContainerCluster() cai.ResourceConverter {
func ResourceConverterContainerCluster() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ContainerClusterAssetType,
Convert: GetContainerClusterCaiObject,
}
}

func resourceConverterContainerNodePool() cai.ResourceConverter {
func ResourceConverterContainerNodePool() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: ContainerNodePoolAssetType,
Convert: GetContainerNodePoolCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package dataflow

import (
"reflect"
Expand All @@ -10,7 +10,7 @@ import (

const DataflowJobAssetType string = "dataflow.googleapis.com/Job"

func resourceDataflowJob() cai.ResourceConverter {
func ResourceDataflowJob() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: DataflowJobAssetType,
Convert: GetDataflowJobCaiObject,
Expand Down Expand Up @@ -302,4 +302,4 @@ func expandDataflowRuntimeUpdatableParams(v interface{}, d tpgresource.Terraform

func expandDataflowSatisfiesPzi(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package dataproc

import (
"reflect"
Expand All @@ -11,7 +11,7 @@ import (

const DataprocClusterAssetType string = "dataproc.googleapis.com/Cluster"

func resourceConverterDataprocCluster() cai.ResourceConverter {
func ResourceConverterDataprocCluster() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: DataprocClusterAssetType,
Convert: GetDataprocClusterCaiObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package kms

import (
"fmt"
Expand All @@ -10,15 +10,15 @@ import (
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func resourceConverterKmsCryptoKeyIamPolicy() cai.ResourceConverter {
func ResourceConverterKmsCryptoKeyIamPolicy() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: "cloudkms.googleapis.com/CryptoKey",
Convert: GetKmsCryptoKeyIamPolicyCaiObject,
MergeCreateUpdate: MergeKmsCryptoKeyIamPolicy,
}
}

func resourceConverterKmsCryptoKeyIamBinding() cai.ResourceConverter {
func ResourceConverterKmsCryptoKeyIamBinding() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: "cloudkms.googleapis.com/CryptoKey",
Convert: GetKmsCryptoKeyIamBindingCaiObject,
Expand All @@ -28,7 +28,7 @@ func resourceConverterKmsCryptoKeyIamBinding() cai.ResourceConverter {
}
}

func resourceConverterKmsCryptoKeyIamMember() cai.ResourceConverter {
func ResourceConverterKmsCryptoKeyIamMember() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: "cloudkms.googleapis.com/CryptoKey",
Convert: GetKmsCryptoKeyIamMemberCaiObject,
Expand Down
Loading

0 comments on commit 0fae600

Please sign in to comment.