Skip to content

Commit

Permalink
Move patch into resources.go
Browse files Browse the repository at this point in the history
This is an alternative strategy to restore an old field, and does not require a patch in
the upstream provider. Instead, we create the field in resources.go and make sure that if
a user sets it, we move it to `restEndpoint` (which the provider still has as valid).
  • Loading branch information
iwahbe committed Aug 25, 2023
1 parent 446fce3 commit c39ddf0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 167 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1ccb7127739cf3a3a6dbe124f1937cd4b4fcdbe1 Mon Sep 17 00:00:00 2001
From 84980b38abac2616149d8218d59b61687a580fb9 Mon Sep 17 00:00:00 2001
From: Ian Wahbe <[email protected]>
Date: Thu, 9 Mar 2023 18:22:25 +0100
Subject: [PATCH 2/2] Insert shim
Subject: [PATCH] Insert shim

---
shim/shim.go | 10 ++++++++++
Expand All @@ -25,5 +25,5 @@ index 0000000..ac43027
+ return provider.New(version, customUserAgent)()
+}
--
2.39.2 (Apple Git-143)
2.41.0

Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,6 @@
"encryptionKey": "encryption_key"
},
"confluentcloud:index/getKafkaTopic:getKafkaTopic": {
"httpEndpoint": "http_endpoint",
"kafkaCluster": "kafka_cluster",
"partitionsCount": "partitions_count",
"restEndpoint": "rest_endpoint",
Expand Down
18 changes: 3 additions & 15 deletions provider/cmd/pulumi-resource-confluentcloud/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5044,8 +5044,7 @@
},
"httpEndpoint": {
"type": "string",
"description": "The HTTP endpoint of the Kafka cluster (e.g., `https://pkc-00000.us-central1.gcp.confluent.cloud:443`).\n",
"deprecationMessage": "This parameter has been deprecated in favour of Rest Endpoint"
"deprecationMessage": "This property has been deprecated. Please use \"restEndpoint\" instead."
},
"kafkaCluster": {
"$ref": "#/types/confluentcloud:index/KafkaTopicKafkaCluster:KafkaTopicKafkaCluster"
Expand Down Expand Up @@ -5083,8 +5082,7 @@
},
"httpEndpoint": {
"type": "string",
"description": "The HTTP endpoint of the Kafka cluster (e.g., `https://pkc-00000.us-central1.gcp.confluent.cloud:443`).\n",
"deprecationMessage": "This parameter has been deprecated in favour of Rest Endpoint"
"deprecationMessage": "This property has been deprecated. Please use \"restEndpoint\" instead."
},
"kafkaCluster": {
"$ref": "#/types/confluentcloud:index/KafkaTopicKafkaCluster:KafkaTopicKafkaCluster",
Expand Down Expand Up @@ -5125,8 +5123,7 @@
},
"httpEndpoint": {
"type": "string",
"description": "The HTTP endpoint of the Kafka cluster (e.g., `https://pkc-00000.us-central1.gcp.confluent.cloud:443`).\n",
"deprecationMessage": "This parameter has been deprecated in favour of Rest Endpoint"
"deprecationMessage": "This property has been deprecated. Please use \"restEndpoint\" instead."
},
"kafkaCluster": {
"$ref": "#/types/confluentcloud:index/KafkaTopicKafkaCluster:KafkaTopicKafkaCluster",
Expand Down Expand Up @@ -7951,10 +7948,6 @@
"$ref": "#/types/confluentcloud:index/getKafkaTopicCredentials:getKafkaTopicCredentials",
"secret": true
},
"httpEndpoint": {
"type": "string",
"deprecationMessage": "This parameter has been deprecated in favour of Rest Endpoint"
},
"kafkaCluster": {
"$ref": "#/types/confluentcloud:index/getKafkaTopicKafkaCluster:getKafkaTopicKafkaCluster"
},
Expand Down Expand Up @@ -7987,10 +7980,6 @@
"$ref": "#/types/confluentcloud:index/getKafkaTopicCredentials:getKafkaTopicCredentials",
"secret": true
},
"httpEndpoint": {
"type": "string",
"deprecationMessage": "This parameter has been deprecated in favour of Rest Endpoint"
},
"id": {
"type": "string",
"description": "The provider-assigned unique ID for this managed resource.\n"
Expand All @@ -8012,7 +8001,6 @@
"type": "object",
"required": [
"config",
"httpEndpoint",
"partitionsCount",
"restEndpoint",
"topicName",
Expand Down
2 changes: 1 addition & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace (

require (
github.com/confluentinc/terraform-provider-confluent v1.32.0
github.com/pulumi/pulumi-terraform-bridge/v3 v3.55.0
github.com/pulumi/pulumi-terraform-bridge/v3 v3.57.0
github.com/pulumi/pulumi/sdk/v3 v3.76.1
)

Expand Down
4 changes: 2 additions & 2 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2193,8 +2193,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/pulumi/pulumi-java/pkg v0.9.4 h1:gIQZmlUI1o9ye8CL2XFqtmAX6Lwr9uj/+HzjboiSmK4=
github.com/pulumi/pulumi-java/pkg v0.9.4/go.mod h1:c6rSw/+q4O0IImgJ9axxoC6QesbPYWBaG5gimbHouUQ=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1 h1:SCg1gjfY9N4yn8U8peIUYATifjoDABkyR7H9lmefsfc=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.55.0 h1:A33Ji/QSCYy2Jk5+1BzA5vFmK7Rvq6XFo8jS69QahVo=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.55.0/go.mod h1:ykaml8e6XS/yI9JOcNZ+6gLirs6EWTB0FmjbT+JyEdU=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.57.0 h1:munOxi56glme47MT8/wI29o9wrRBJrEQuwjAgm1zviI=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.57.0/go.mod h1:ykaml8e6XS/yI9JOcNZ+6gLirs6EWTB0FmjbT+JyEdU=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.4 h1:rIzMmtcVpPX8ynaz6/nW5AHNY63DiNfCohqmxWvMpM4=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.4/go.mod h1:Kt8RIZWa/N8rW3+0g6NrqCBmF3o+HuIhFaZpssEkG6w=
github.com/pulumi/pulumi-yaml v1.1.1 h1:8pyBNIU8+ym0wYpjhsCqN+cutygfK1XbhY2YEeNfyXY=
Expand Down
62 changes: 55 additions & 7 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ package confluentcloud
import (
"fmt"
// embed is used to store bridge-metadata.json in the compiled binary
"context"
_ "embed"
"path/filepath"

"github.com/confluentinc/terraform-provider-confluent/shim"
"github.com/pulumi/pulumi-confluentcloud/provider/pkg/version"
tfschema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/x"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"github.com/confluentinc/terraform-provider-confluent/shim"
"github.com/pulumi/pulumi-confluentcloud/provider/pkg/version"
)

// all of the token components used below.
Expand Down Expand Up @@ -90,11 +94,55 @@ func Provider() tfbridge.ProviderInfo {
}},
"confluent_kafka_cluster_config": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "KafkaClusterConfig")},
"confluent_kafka_mirror_topic": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "KafkaMirrorTopic")},
"confluent_kafka_topic": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "KafkaTopic")},
"confluent_network": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "Network")},
"confluent_peering": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "Peering")},
"confluent_private_link_access": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "PrivateLinkAccess")},
"confluent_role_binding": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "RoleBinding")},
"confluent_kafka_topic": {
Tok: tfbridge.MakeResource(mainPkg, mainMod, "KafkaTopic"),
PreCheckCallback: func(
ctx context.Context, config resource.PropertyMap, _ resource.PropertyMap,
) (resource.PropertyMap, error) {
const (
httpEndpoint = "httpEndpoint"
restEndpoint = "restEndpoint"
)
endpoint, ok := config[httpEndpoint]
if !ok {
// The optional key is not present, so we can return the config as is.
return config, nil
}

// The user has set both httpEndpoint and restEndpoint. These are semantically
// the same, so it is forbidden to set both.
if _, ok := config[restEndpoint]; ok {
return config, fmt.Errorf(`Cannot specify both "httpEndpoint" and "restEndpoint"` +
`, please set only "restEndpoint"`)
}

tfbridge.GetLogger(ctx).Warn(`"httpEndpoint" is deprecated, use "restEndpoint" instead.`)

delete(config, httpEndpoint)
config[restEndpoint] = endpoint

return config, nil
},
Fields: map[string]*tfbridge.SchemaInfo{
"http_endpoint": func() *tfbridge.SchemaInfo {
p.ResourcesMap().Get("confluent_kafka_topic").Schema().
Set("http_endpoint", shimv2.NewSchema(&tfschema.Schema{
Type: tfschema.TypeString,
Optional: true,
Computed: true,
}))
return &tfbridge.SchemaInfo{
Name: "httpEndpoint",
DeprecationMessage: "This property has been deprecated. " +
`Please use "restEndpoint" instead.`,
}
}(),
},
},
"confluent_network": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "Network")},
"confluent_peering": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "Peering")},
"confluent_private_link_access": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "PrivateLinkAccess")},
"confluent_role_binding": {Tok: tfbridge.MakeResource(mainPkg, mainMod, "RoleBinding")},
"confluent_service_account": {
Tok: tfbridge.MakeResource(mainPkg, mainMod, "ServiceAccount"),
Fields: map[string]*tfbridge.SchemaInfo{
Expand Down

0 comments on commit c39ddf0

Please sign in to comment.