pulumi / pulumi-terraform-bridge

A library allowing Terraform providers to be bridged into Pulumi.
Apache License 2.0
200 stars 43 forks source link

Invalid property path when the path contains special characters #2669

Open blampe opened 4 days ago

blampe commented 4 days ago

What happened?

We seem to generate an invalid property path when it contains dots:

options.["com.docker.network.driver.overlay.vxlanid_list"]:kind:DELETE_REPLACE ... property path '["com.docker.network.driver.overlay.vxlanid_list"]' contains a '.' followed by a '['; this is not strictly legal

The correct syntax is options["com.docker.network.driver.overlay.vxlanid_list"].

The relevant field type is

"options": {
    "type": "object",
    "additionalProperties": {
        "type": "string"
    },
    "description": "Only available with bridge networks. See [bridge options docs](https://docs.docker.com/engine/reference/commandline/network_create/#bridge-driver-options) for more details.\n"
},

I'm guessing this has something to do with the one untested line in diff.go:

elementPath = fmt.Sprintf(`%s.["%s"]`, path, strings.ReplaceAll(string(k), `"`, `\"`))

Example

https://github.com/pulumi/pulumi-docker/issues/1284 provides a repro. Run docker swarm init beforehand.

{
  "name": "p-docker-1284",
  "main": "index.ts",
  "devDependencies": {
    "@types/node": "^18",
    "typescript": "^5.0.0"
  },
  "dependencies": {
    "@pulumi/pulumi": "^3.113.0",
    "@pulumi/docker": "^4"
  }
}
import * as docker from "@pulumi/docker";

new docker.Network("network", {
  name: "p-docker-1284",
  driver: "overlay",
  options: { encrypted: "true" },
});
I1125 10:46:35.954337    3221 provider_plugin.go:1009] Provider[docker, 0x1400208a780].Diff(urn:pulumi:dev::p-docker-1284::docker:index/network:Network::network,xmmck7rxhzj4rnib2qsi8423y) success: changes=2 #replaces=[options] #stables=[attachable checkDuplicate driver ingress internal ipamConfigs ipamDriver ipamOptions ipv6 labels name] delbefrepl=true, diffs=#[options], detaileddiff=map[options:kind:UPDATE options.["com.docker.network.driver.overlay.vxlanid_list"]:kind:DELETE_REPLACE]
I1125 10:46:35.954350    3221 properties_path.go:85] property path '["com.docker.network.driver.overlay.vxlanid_list"]' contains a '.' followed by a '['; this is not strictly legal

Output of pulumi about

CLI
Version      3.140.0
Go Version   go1.23.3
Go Compiler  gc

Plugins
KIND      NAME    VERSION
resource  docker  4.5.7
language  nodejs  3.140.0-dev.0

Host
OS       darwin
Version  14.6.1
Arch     arm64

This project is written in nodejs: executable='/opt/homebrew/bin/node' version='v22.6.0'

Current Stack: organization/p-docker-1284/dev

TYPE                          URN
pulumi:pulumi:Stack           urn:pulumi:dev::p-docker-1284::pulumi:pulumi:Stack::p-docker-1284-dev
pulumi:providers:docker       urn:pulumi:dev::p-docker-1284::pulumi:providers:docker::default_4_5_7
docker:index/network:Network  urn:pulumi:dev::p-docker-1284::docker:index/network:Network::network

Found no pending operations associated with dev

Backend
Name           Bryces-Work-MacBook-Pro.local
URL            file:///Users/bryce/src/test/p-docker-1284/
User           bryce
Organizations
Token type     personal

Dependencies:
NAME            VERSION
typescript      5.7.2
@pulumi/docker  4.5.7
@pulumi/pulumi  3.141.0
@types/node     18.19.65

Additional context

No response

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).

VenelinMartinov commented 4 days ago

Thanks for reporting and for pointing us to the problematic code. I've added tests which repro the issue in https://github.com/pulumi/pulumi-terraform-bridge/pull/2671. Will investigate a solution.

VenelinMartinov commented 4 days ago

The untested line isn't the only problem it looks like. After fixing it locally the provider still fails to return a valid detailed diff