-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cai2Hcl: refactor of converter_map and split of utils.go (#9378)
* Add cai2hcl generated converters for 3 Compute resources. These are: BackendService, GlobalBackendService, ForwardingRule. This is the output of cai2hcl provider, commited as is without the generator Ruby code itself, as agreed with library owners. Reason: limited capacity of the supporting team to perform code reviews and the future need to port this solution to golang as a part of migration to go. As soon the staffing and/or migration is done, we will come back to implement the generated converters as originally planned. * Split current PR into 3 chunks: 1. Refactor of shared files (Uber Converter) 2. Add ForwardingRuleConverter (generated) 3. Add BackendServiceConverters (generated) + ability to match converters by name This commit removes part2 and part3, leaving only part1 in this branch. * Fix versions after merge conflict * Remove auto-generated code header from FR * Remove unused util function * Fix merge conflict resolution issue * Remove unnecessary result map normalization (will needed later with generated converters) * Simplify cai2hcl by reworking UberConverter's as a single ConverterMap. 1. Rename UberConverter to ConverterMap. 2. Remove ConverterMap's from each API folder and replace them with a single top-level ConverterMap * Simplify converters * Flatten converter_map.go and use strings as converter names instead of constants.
- Loading branch information
1 parent
28abc87
commit ddc054c
Showing
18 changed files
with
142 additions
and
196 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,42 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
tpg_provider "github.com/hashicorp/terraform-provider-google-beta/google-beta/provider" | ||
) | ||
|
||
func TestSubsetOfFieldsMapsToCtyValue(t *testing.T) { | ||
schema := createSchema("google_compute_forwarding_rule") | ||
|
||
outputMap := map[string]interface{}{ | ||
"name": "forwarding-rule-1", | ||
} | ||
|
||
val, err := MapToCtyValWithSchema(outputMap, schema) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, "forwarding-rule-1", val.GetAttr("name").AsString()) | ||
} | ||
|
||
func TestWrongFieldTypeBreaksConversion(t *testing.T) { | ||
resourceSchema := createSchema("google_compute_backend_service") | ||
outputMap := map[string]interface{}{ | ||
"name": "fr-1", | ||
"description": []string{"unknownValue"}, // string is required, not array. | ||
} | ||
|
||
val, err := MapToCtyValWithSchema(outputMap, resourceSchema) | ||
|
||
assert.True(t, val.IsNull()) | ||
assert.Contains(t, err.Error(), "string is required") | ||
} | ||
|
||
func createSchema(name string) map[string]*schema.Schema { | ||
provider := tpg_provider.Provider() | ||
|
||
return provider.ResourcesMap[name].Schema | ||
} |
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
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
11 changes: 4 additions & 7 deletions
11
mmv1/third_party/cai2hcl/services/compute/compute_forwarding_rule_test.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 |
---|---|---|
@@ -1,17 +1,14 @@ | ||
package compute | ||
package compute_test | ||
|
||
import ( | ||
"testing" | ||
|
||
cai2hclTesting "github.com/GoogleCloudPlatform/terraform-google-conversion/v5/cai2hcl/testing" | ||
cai2hcl_testing "github.com/GoogleCloudPlatform/terraform-google-conversion/v5/cai2hcl/testing" | ||
) | ||
|
||
func TestComputeForwardingRule(t *testing.T) { | ||
cai2hclTesting.AssertTestFiles( | ||
cai2hcl_testing.AssertTestFiles( | ||
t, | ||
ConverterNames, ConverterMap, | ||
"./testdata", | ||
[]string{ | ||
"full_compute_forwarding_rule", | ||
}) | ||
[]string{"compute_forwarding_rule"}) | ||
} |
Oops, something went wrong.