-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DiffStrategy=PlanState handling of unknowns (#1189)
This change is aimed at fixing pulumi/pulumi-hcloud#175 This provider is early in adopting a feature-flagged change in #866 and uncovered an issue. Due to technicalities this project is linking code from TF plugins and TF CLI proper. The codebases do not agree on the dependency "github.com/hashicorp/go-cty/cty" vs "github.com/zclconf/go-cty/cty/json", necessitating adapter code. There is a bug being fixed here in the adapter code that converts cty.Value objects across these two packages. --------- Co-authored-by: Ian Wahbe <[email protected]>
- Loading branch information
Showing
3 changed files
with
443 additions
and
52 deletions.
There are no files selected for viewing
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,123 @@ | ||
// Copyright 2016-2023, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
testutils "github.com/pulumi/pulumi-terraform-bridge/testing/x" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" | ||
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" | ||
) | ||
|
||
func TestRegressHCloud175(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
subnetResource := func() *schema.Resource { | ||
return &schema.Resource{ | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"network_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"network_zone": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"ip_range": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"gateway": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"vswitch_id": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
tfProvider := &schema.Provider{ | ||
Schema: map[string]*schema.Schema{}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"hcloud_subnet": subnetResource(), | ||
}, | ||
} | ||
|
||
p := shimv2.NewProvider(tfProvider, shimv2.WithDiffStrategy(shimv2.PlanState)) | ||
|
||
info := tfbridge.ProviderInfo{ | ||
P: p, | ||
Name: "hcloud", | ||
Description: "etc", | ||
Keywords: []string{"pulumi", "hcloud"}, | ||
License: "Apache-2.0", | ||
Version: "0.0.1", | ||
Resources: map[string]*tfbridge.ResourceInfo{ | ||
"hcloud_subnet": {Tok: "hcloud:index/networkSubnet:NetworkSubnet"}, | ||
}, | ||
} | ||
|
||
server := tfbridge.NewProvider(ctx, | ||
nil, /* hostClient */ | ||
"hcloud", /* module */ | ||
"", /* version */ | ||
p, /* tf */ | ||
info, /* info */ | ||
[]byte{}, /* pulumiSchema */ | ||
) | ||
|
||
testCase := ` | ||
{ | ||
"method": "/pulumirpc.ResourceProvider/Create", | ||
"request": { | ||
"urn": "urn:pulumi:dev::repro-175::hcloud:index/networkSubnet:NetworkSubnet::subnet", | ||
"properties": { | ||
"__defaults": [], | ||
"ipRange": "10.0.1.0/24", | ||
"networkId": "04da6b54-80e4-46f7-96ec-b56ff0331ba9", | ||
"networkZone": "eu-central", | ||
"type": "cloud" | ||
}, | ||
"preview": true | ||
}, | ||
"response": { | ||
"properties": { | ||
"id": "*", | ||
"ipRange": "10.0.1.0/24", | ||
"networkZone": "eu-central", | ||
"type": "cloud" | ||
} | ||
} | ||
}` | ||
testutils.Replay(t, server, testCase) | ||
} |
Oops, something went wrong.