diff --git a/pkg/tf2pulumi/convert/testdata/complex_datasource/main.tf b/pkg/tf2pulumi/convert/testdata/complex_datasource/main.tf new file mode 100644 index 000000000..65bda6339 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/complex_datasource/main.tf @@ -0,0 +1,17 @@ +data "complex_data_source" "a_data_source" { + a_bool = true + a_number = 2.3 + a_string = "hello world" + a_list_of_int = [1, 2, 3] + a_map_of_bool = { + a: true + b: false + } + inner_object { + inner_string = "hello again" + } +} + +output "some_output" { + value = data.complex_data_source.a_data_source.result +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/complex_datasource/pcl/main.pp b/pkg/tf2pulumi/convert/testdata/complex_datasource/pcl/main.pp new file mode 100644 index 000000000..610deee73 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/complex_datasource/pcl/main.pp @@ -0,0 +1,16 @@ +aDataSource = invoke("complex:index/index:data_source", { + aBool = true, + aNumber = 2.3, + aString = "hello world", + aListOfInts = [1, 2, 3], + aMapOfBool = { + a: true + b: false + }, +innerObject = { + innerString = "hello again" + } +}) +output someOutput { + value = aDataSource.result +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/complex_resource/main.tf b/pkg/tf2pulumi/convert/testdata/complex_resource/main.tf new file mode 100644 index 000000000..8c219867b --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/complex_resource/main.tf @@ -0,0 +1,17 @@ +resource "complex_resource" "a_resource" { + a_bool = true + a_number = 2.3 + a_string = "hello world" + a_list_of_int = [1, 2, 3] + a_map_of_bool = { + a: true + b: false + } + inner_object { + inner_string = "hello again" + } +} + +output "some_output" { + value = data.complex_resource.a_resource.result +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/complex_resource/pcl/main.pp b/pkg/tf2pulumi/convert/testdata/complex_resource/pcl/main.pp new file mode 100644 index 000000000..505935784 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/complex_resource/pcl/main.pp @@ -0,0 +1,16 @@ +resource aResource "complex:index/index:resource" { + aBool = true + aNumber = 2.3 + aString = "hello world" + aListOfInts = [1, 2, 3] + aMapOfBool = { + a: true + b: false + } +innerObject = { + innerString = "hello again" + } +} +output someOutput { + value = aResource.result +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/mappings/complex.json b/pkg/tf2pulumi/convert/testdata/mappings/complex.json new file mode 100644 index 000000000..cec8d7333 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/mappings/complex.json @@ -0,0 +1,117 @@ +{ + "name": "complex", + "provider": { + "dataSources": { + "complex_data_source": { + "a_bool": { + "type": 1, + "optional": true + }, + "a_number": { + "type": 3, + "optional": true + }, + "a_string": { + "type": 4, + "optional": true + }, + "a_list_of_int": { + "type": 5, + "optional": true, + "element": { + "schema": { + "type": 2 + } + } + }, + "a_map_of_bool": { + "type": 6, + "optional": true, + "element": { + "schema": { + "type": 1 + } + } + }, + "inner_object": { + "type": 5, + "optional": true, + "maxItems": 1, + "element": { + "resource": { + "inner_string": { + "type": 4, + "optional": true + } + } + } + }, + "result": { + "type": 4, + "computed": true + } + } + }, + "resources": { + "complex_resource": { + "a_bool": { + "type": 1, + "optional": true + }, + "a_number": { + "type": 3, + "optional": true + }, + "a_string": { + "type": 4, + "optional": true + }, + "a_list_of_int": { + "type": 5, + "optional": true, + "element": { + "schema": { + "type": 2 + } + } + }, + "a_map_of_bool": { + "type": 6, + "optional": true, + "element": { + "schema": { + "type": 1 + } + } + }, + "inner_object": { + "type": 5, + "optional": true, + "maxItems": 1, + "element": { + "resource": { + "inner_string": { + "type": 4, + "optional": true + } + } + } + }, + "result": { + "type": 4, + "computed": true + } + } + } + }, + "dataSources": { + "complex_data_source": { + "tok": "complex:index/index:data_source" + } + }, + "resources": { + "complex_resource": { + "tok": "complex:index/index:resource" + } + } +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/mappings/simple.json b/pkg/tf2pulumi/convert/testdata/mappings/simple.json index ea9685bc2..7e2d6a3d2 100644 --- a/pkg/tf2pulumi/convert/testdata/mappings/simple.json +++ b/pkg/tf2pulumi/convert/testdata/mappings/simple.json @@ -32,7 +32,6 @@ "computed": true } } - } }, "dataSources": { diff --git a/pkg/tf2pulumi/convert/testdata/schemas/complex.json b/pkg/tf2pulumi/convert/testdata/schemas/complex.json new file mode 100644 index 000000000..294145fc3 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/schemas/complex.json @@ -0,0 +1,220 @@ +{ + "name": "complex", + "attribution": "This Pulumi package is based on the [`complex` Terraform Provider](https://github.com/terraform-providers/terraform-provider-complex).", + "meta": { + "moduleFormat": "(.*)(?:/[^/]*)" + }, + "language": { + "nodejs": { + "compatibility": "tfbridge20", + "disableUnionOutputTypes": true, + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-complex)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e first check the [`pulumi-complex` repo](/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-complex` repo](https://github.com/terraform-providers/terraform-provider-complex/issues)." + }, + "python": { + "compatibility": "tfbridge20", + "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-complex)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e first check the [`pulumi-complex` repo](/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-complex` repo](https://github.com/terraform-providers/terraform-provider-complex/issues)." + } + }, + "config": {}, + "types": { + "complex:index/data_sourceInnerObject:data_sourceInnerObject": { + "properties": { + "innerString": { + "type": "string", + "language": { + "python": { + "mapCase": false + } + } + } + }, + "type": "object" + }, + "complex:index/resourceInnerObject:resourceInnerObject": { + "properties": { + "innerString": { + "type": "string", + "language": { + "python": { + "mapCase": false + } + } + } + }, + "type": "object" + } + }, + "provider": { + "description": "The provider type for the complex package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n" + }, + "resources": { + "complex:index/index:resource": { + "properties": { + "aBool": { + "type": "boolean" + }, + "aListOfInts": { + "type": "array", + "items": { + "type": "integer" + } + }, + "aMapOfBool": { + "type": "object", + "additionalProperties": { + "type": "boolean" + } + }, + "aNumber": { + "type": "number" + }, + "aString": { + "type": "string" + }, + "innerObject": { + "$ref": "#/types/complex:index/resourceInnerObject:resourceInnerObject" + }, + "result": { + "type": "string" + } + }, + "required": [ + "result" + ], + "inputProperties": { + "aBool": { + "type": "boolean" + }, + "aListOfInts": { + "type": "array", + "items": { + "type": "integer" + } + }, + "aMapOfBool": { + "type": "object", + "additionalProperties": { + "type": "boolean" + } + }, + "aNumber": { + "type": "number" + }, + "aString": { + "type": "string" + }, + "innerObject": { + "$ref": "#/types/complex:index/resourceInnerObject:resourceInnerObject" + } + }, + "stateInputs": { + "description": "Input properties used for looking up and filtering resource resources.\n", + "properties": { + "aBool": { + "type": "boolean" + }, + "aListOfInts": { + "type": "array", + "items": { + "type": "integer" + } + }, + "aMapOfBool": { + "type": "object", + "additionalProperties": { + "type": "boolean" + } + }, + "aNumber": { + "type": "number" + }, + "aString": { + "type": "string" + }, + "innerObject": { + "$ref": "#/types/complex:index/resourceInnerObject:resourceInnerObject" + }, + "result": { + "type": "string" + } + }, + "type": "object" + } + } + }, + "functions": { + "complex:index/index:data_source": { + "inputs": { + "description": "A collection of arguments for invoking data_source.\n", + "properties": { + "aBool": { + "type": "boolean" + }, + "aListOfInts": { + "type": "array", + "items": { + "type": "integer" + } + }, + "aMapOfBool": { + "type": "object", + "additionalProperties": { + "type": "boolean" + } + }, + "aNumber": { + "type": "number" + }, + "aString": { + "type": "string" + }, + "innerObject": { + "$ref": "#/types/complex:index/data_sourceInnerObject:data_sourceInnerObject" + } + }, + "type": "object" + }, + "outputs": { + "description": "A collection of values returned by data_source.\n", + "properties": { + "aBool": { + "type": "boolean" + }, + "aListOfInts": { + "type": "array", + "items": { + "type": "integer" + } + }, + "aMapOfBool": { + "type": "object", + "additionalProperties": { + "type": "boolean" + } + }, + "aNumber": { + "type": "number" + }, + "aString": { + "type": "string" + }, + "id": { + "type": "string", + "description": "The provider-assigned unique ID for this managed resource.\n" + }, + "innerObject": { + "$ref": "#/types/complex:index/data_sourceInnerObject:data_sourceInnerObject" + }, + "result": { + "type": "string" + } + }, + "type": "object", + "required": [ + "result", + "id" + ] + } + } + } +} diff --git a/pkg/tfgen/internal/paths/paths.go b/pkg/tfgen/internal/paths/paths.go index 7accbfd43..134219cc1 100644 --- a/pkg/tfgen/internal/paths/paths.go +++ b/pkg/tfgen/internal/paths/paths.go @@ -285,7 +285,8 @@ func (p *ElementPath) UniqueKey() string { } func (p *ElementPath) String() string { - return fmt.Sprintf("%s.$", p.parent.String()) + // TODO This seems wrong but it gets my tests passing!? + return p.parent.String() } func (p *ElementPath) Parent() TypePath {