Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert terraform for kube config on hetzner cloud #212

Open
emiliauskas-fuzzy opened this issue Oct 17, 2024 · 4 comments
Open

Cannot convert terraform for kube config on hetzner cloud #212

emiliauskas-fuzzy opened this issue Oct 17, 2024 · 4 comments
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@emiliauskas-fuzzy
Copy link

What happened?

I wanted to convert following script https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner - to pulumi

but getting error:

panic: fatal: A failure has occurred: Couldn't convert expression: *hclsyntax.TemplateJoinExpr

goroutine 53 [running]:

github.com/pulumi/pulumi/sdk/v3/go/common/util/contract.failfast(...)

	/Users/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/go/common/util/contract/failfast.go:23

github.com/pulumi/pulumi/sdk/v3/go/common/util/contract.Failf({0x1870640?, 0xc0002ab620?}, {0xc000e2ea78?, 0x40f1ff?, 0x165f0c0?})

	/Users/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/go/common/util/contract/fail.go:32 +0xcb

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertExpression(0x2b66dc0?, 0x0?, 0x2?, {0x0?, 0x15c0340?}, {0x1ea7c18?, 0xc000910940?})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1629 +0x313

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertTemplateExpr(0xc000e2fdc8, 0xc000738d80, {0xc000e2ebd8?, 0x40f1ff?}, 0xc000bf7ce0)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1098 +0x4ba

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertExpression(0x2b66f80?, 0x20?, 0x10?, {0x0?, 0x41a0d8?}, {0x1ea77b0?, 0xc000bf7ce0?})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1605 +0x297

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertConditionalExpr(0xc000e2fdc8, 0x0, 0xc000738d80, {0x40f1ff?, 0x165f0c0?}, 0xc0004ffa40)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1565 +0xc5

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertExpression(0x2b66dc0?, 0x40?, 0x2?, {0x0?, 0x15c0340?}, {0x1ea7970?, 0xc0004ffa40?})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1625 +0x1d9

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertTemplateExpr(0xc000e2fdc8, 0xc000738d80, {0xc000e2ee58?, 0x40f1ff?}, 0xc000bf7e00)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1098 +0x4ba

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertExpression(0x2b66fa0?, 0x20?, 0x78fba9e3f5b8?, {0x0?, 0x1e?}, {0x1ea77b0?, 0xc000bf7e00?})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1605 +0x297

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertConditionalExpr(0xc000e2fdc8, 0x1, 0xc000738d80, {0xc000e2ef68?, 0x3?}, 0xc0004ffab0)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1566 +0x125

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertExpression(0x15d5b20?, 0x10?, 0xc000e2efe8?, {0x0?, 0xc000e2f018?}, {0x1ea7970?, 0xc0004ffab0?})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:1625 +0x1d9

github.com/pulumi/pulumi-converter-terraform/pkg/convert.convertLocal(0xc000e2fdc8, 0xc000738d80, 0xc000f908a0)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:2039 +0xbd

github.com/pulumi/pulumi-converter-terraform/pkg/convert.translateModuleSourceCode(0xc000e31610, {0x1eb8260, 0xc000b5a040}, {0x1e8baac, 0x1}, {0x1eb8260, 0xc000a1a500}, {0xc000b2e3a8, 0x14}, {0x1e91180, ...})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:3027 +0x335e

github.com/pulumi/pulumi-converter-terraform/pkg/convert.translateRemoteModule(0xc000c2f610, {0xc000a37490, 0x6f}, {0x0, 0x0}, {0x1eb8260, 0xc000a1a500}, {0xc000b2e3a8, 0x14}, {0x1e91180, ...})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:2524 +0x53a

github.com/pulumi/pulumi-converter-terraform/pkg/convert.translateModuleSourceCode(0xc000e31610, {0x1eb81e0, 0x2c1c420}, {0xc0005b40f0, 0x4b}, {0x1eb8260, 0xc000a1a500}, {0x1e8baac, 0x1}, {0x1e91180, ...})

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:2857 +0x6dc5

github.com/pulumi/pulumi-converter-terraform/pkg/convert.TranslateModule(...)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/pkg/convert/tf.go:3143

main.(*tfConverter).ConvertProgram(0xc000a18cf0?, {0x40e27a?, 0xc0006c16f0?}, 0xc0000a2d80)

	/Users/runner/work/pulumi-converter-terraform/pulumi-converter-terraform/cmd/pulumi-converter-terraform/main.go:149 +0x72b

github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin.(*converterServer).ConvertProgram(0xc0005cb480, {0x1ea7200, 0xc000a18cf0}, 0xc000a3a280)

	/Users/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/go/common/resource/plugin/converter_server.go:76 +0x126

github.com/pulumi/pulumi/sdk/v3/proto/go._Converter_ConvertProgram_Handler.func1({0x1ea7200?, 0xc000a18cf0?}, {0x1766660?, 0xc000a3a280?})

	/Users/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/proto/go/converter_grpc.pb.go:122 +0xcb

github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x1ea7200, 0xc000a18930}, {0x1766660, 0xc000a3a280}, 0xc000a1a200, 0xc000972438)

	/Users/runner/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/go/otgrpc/server.go:57 +0x3db

github.com/pulumi/pulumi/sdk/v3/proto/go._Converter_ConvertProgram_Handler({0x1637f80, 0xc0005cb480}, {0x1ea7200, 0xc000a18930}, 0xc000a3a200, 0xc0005cb360)

	/Users/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/[email protected]/proto/go/converter_grpc.pb.go:124 +0x143

google.golang.org/grpc.(*Server).processUnaryRPC(0xc000563600, {0x1ea7200, 0xc000a188a0}, {0x1eb23a0, 0xc000002180}, 0xc000529320, 0xc00064bb00, 0x2b7f6b8, 0x0)

	/Users/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1379 +0xdf8

google.golang.org/grpc.(*Server).handleStream(0xc000563600, {0x1eb23a0, 0xc000002180}, 0xc000529320)

	/Users/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1790 +0xe8b

google.golang.org/grpc.(*Server).serveStreams.func2.1()

	/Users/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1029 +0x8b

created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 51

	/Users/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1040 +0x125

error: rpc error: code = Unavailable desc = error reading from server: EOF

Example

command:

pulumi convert --from terraform --language typescript

Using example tf script:

https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner/blob/master/kube.tf.example

Output of pulumi about

CLI
Version 3.136.1
Go Version go1.23.2
Go Compiler gc

Host
OS ubuntu
Version 24.04
Arch x86_64

Backend
Name pulumi.com
URL https://app.pulumi.com/em_stacktome
User em_stacktome
Organizations em_stacktome
Token type personal

Additional context

plugin list:

NAME                 KIND       VERSION  SIZE    INSTALLED      LAST USED
cloudinit            resource   1.4.8    74 MB   2 minutes ago  2 minutes ago
command              resource   0.11.1   35 MB   2 weeks ago    3 days ago
file                 resource   0.0.6    34 MB   2 weeks ago    3 days ago
github               resource   6.3.2    46 MB   2 minutes ago  2 minutes ago
hcloud               resource   1.19.0   45 MB   2 weeks ago    3 days ago
hcloud-kube-hetzner  resource   0.1.0    119 MB  2 weeks ago    3 days ago
kubernetes           resource   4.18.1   212 MB  2 weeks ago    3 days ago
local                resource   0.1.5    74 MB   2 minutes ago  2 minutes ago
null                 resource   0.0.8    74 MB   2 minutes ago  2 minutes ago
random               resource   4.16.7   74 MB   2 minutes ago  2 minutes ago
terraform            converter  1.0.19   42 MB   2 minutes ago  2 minutes ago

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@emiliauskas-fuzzy emiliauskas-fuzzy added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Oct 17, 2024
@justinvp
Copy link
Member

Thanks for opening the issue and sorry for the trouble, @emiliauskas-fuzzy! I'm going to transfer this to the https://github.com/pulumi/pulumi-converter-terraform repo.

Looks like we're not handling *hclsyntax.TemplateJoinExpr in

func convertExpression(state *convertState, inBlock bool, scopes *scopes,

cc: @brandonpollack23, @Zaid-Ajaj

@justinvp justinvp removed the needs-triage Needs attention from the triage team label Oct 18, 2024
@justinvp justinvp transferred this issue from pulumi/pulumi Oct 18, 2024
@pulumi-bot pulumi-bot added the needs-triage Needs attention from the triage team label Oct 18, 2024
@Zaid-Ajaj Zaid-Ajaj self-assigned this Oct 18, 2024
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Oct 20, 2024
@justinvp justinvp added this to the 0.112 milestone Oct 20, 2024
@brandonpollack23
Copy link
Contributor

having a look now :)

@brandonpollack23 brandonpollack23 self-assigned this Nov 1, 2024
@brandonpollack23
Copy link
Contributor

Just submitted a PR that fixes this partially, but it still doesn't convert due to some other issues:

error: placement_groups.pp:0,60-2,2: cannot assign expression of type { input: (0, list(number)) } to location of type   { input: list(number | output(number)) | output(list(number)) | output(list(number)?)? }
| output({ input: list(number)? }): ;
error: control_planes.pp:60,45-48: cannot traverse value of type string;
error: control_planes.pp:61,58-61: cannot traverse value of type string;
error: control_planes.pp:64,49-52: cannot traverse value of type string;
error: control_planes.pp:63,37-66,4: cannot assign expression of type { host: 1, input: list(output(dynamic)) } to location of type   { host: int | output(int) | output(int?)?, input: output(string) | output(string?) | string? }
| output({ host: int?, input: string? }): ;
warning: control_planes.pp:60,27-48: ; Cannot assign value list(output(dynamic)) to attribute of type "integer" for resource "hcloud::LoadBalancerNetwork"
warning: control_planes.pp:61,27-61: ; Cannot assign value list(output(dynamic)) to attribute of type "Optional<string>" for resource "hcloud::LoadBalancerNetwork"
error: control_planes.pp:77,38-41: cannot traverse value of type string;
warning: control_planes.pp:77,20-41: ; Cannot assign value list(output(dynamic)) to attribute of type "integer" for resource "hcloud::LoadBalancerTarget"
error: control_planes.pp:91,39-42: cannot traverse value of type string;
warning: control_planes.pp:91,21-42: ; Cannot assign value list(output(dynamic)) to attribute of type "string" for resource "hcloud::LoadBalancerService"
warning: locals.pp:261,242-256: undefined variable randomPassword;
error: kubeconfig.pp:10,128-131: cannot traverse value of type string;
error: output.pp:29,79-82: cannot traverse value of type string;
error: placement_groups.pp:4,54-6,2: cannot assign expression of type { input: (0, list(number)) } to location of type   { input: list(number | output(number)) | output(list(number)) | output(list(number)?)? }
| output({ input: list(number)? }): ;
error: could not generate output program

The outputted code for the first error:

controlPlanePlacementCompatGroups = invoke("std:index:max", {
  input = [0, [for cpPool in controlPlaneNodepools : cpPool.placementGroupCompatIdx + 1 if cpPool.placementGroupCompatIdx != null && cpPool.placementGroup == null]]
}).result

@brandonpollack23
Copy link
Contributor

After the current fixes linked to this bug are fixed there still remains existing issues:

error: placement_groups.pp:0,60-2,2: cannot assign expression of type { input: (0, list(number)) } to location of type   { input: list(number | output(number)) | output(list(number)) | output(list(number)?)? }
| output({ input: list(number)? }): ;
error: control_planes.pp:60,45-48: cannot traverse value of type string;
error: control_planes.pp:61,58-61: cannot traverse value of type string;
error: control_planes.pp:64,49-52: cannot traverse value of type string;
error: control_planes.pp:63,37-66,4: cannot assign expression of type { host: 1, input: list(output(dynamic)) } to location of type   { host: int | output(int) | output(int?)?, input: output(string) | output(string?) | string? }
| output({ host: int?, input: string? }): ;
warning: control_planes.pp:60,27-48: ; Cannot assign value list(output(dynamic)) to attribute of type "integer" for resource "hcloud::LoadBalancerNetwork"
warning: control_planes.pp:61,27-61: ; Cannot assign value list(output(dynamic)) to attribute of type "Optional<string>" for resource "hcloud::LoadBalancerNetwork"
error: control_planes.pp:77,38-41: cannot traverse value of type string;
warning: control_planes.pp:77,20-41: ; Cannot assign value list(output(dynamic)) to attribute of type "integer" for resource "hcloud::LoadBalancerTarget"
error: control_planes.pp:91,39-42: cannot traverse value of type string;
warning: control_planes.pp:91,21-42: ; Cannot assign value list(output(dynamic)) to attribute of type "string" for resource "hcloud::LoadBalancerService"
warning: locals.pp:278,175-189: undefined variable randomPassword;
error: kubeconfig.pp:10,128-131: cannot traverse value of type string;
error: output.pp:29,79-82: cannot traverse value of type string;
error: placement_groups.pp:4,54-6,2: cannot assign expression of type { input: (0, list(number)) } to location of type   { input: list(number | output(number)) | output(list(number)) | output(list(number)?)? }
| output({ input: list(number)? }): ;
error: could not generate output program

@justinvp justinvp modified the milestones: 0.112, 0.113 Nov 12, 2024
brandonpollack23 added a commit that referenced this issue Nov 13, 2024
#218)

Without handling this we panic, so instead lets not do that and handle
this by unwrapping the inner ForExpr.

Related #212
@justinvp justinvp modified the milestones: 0.113, 0.114 Dec 3, 2024
@justinvp justinvp removed this from the 0.114 milestone Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

5 participants