diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index b05d57a8..9a877ef7 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -1,4 +1,5 @@ // Copyright 2016-2020, Pulumi Corporation. All rights reserved. +//go:build nodejs || all // +build nodejs all package examples @@ -19,6 +20,15 @@ func TestNetworkTs(t *testing.T) { integration.ProgramTest(t, &test) } +func TestServerTs(t *testing.T) { + test := getJSBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: path.Join(getCwd(t), "server", "ts"), + }) + + integration.ProgramTest(t, &test) +} + func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions { base := getBaseOptions(t) baseJS := base.With(integration.ProgramTestOptions{ diff --git a/examples/regress_170_test.go b/examples/regress_170_test.go deleted file mode 100644 index 5ac28466..00000000 --- a/examples/regress_170_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2016-2018, 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 examples - -import ( - "context" - "testing" - - "github.com/stretchr/testify/require" - - provider "github.com/pulumi/pulumi-hcloud/provider" - "github.com/pulumi/pulumi-hcloud/provider/pkg/version" - pf "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge" - testutils "github.com/pulumi/pulumi-terraform-bridge/testing/x" - pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" -) - -func TestRegress170(t *testing.T) { - diff := `{ - "method": "/pulumirpc.ResourceProvider/Diff", - "request": { - "id": "29747477", - "urn": "urn:pulumi:dev::ts::hcloud:index/server:Server::server", - "olds": { - "__meta": "{\"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0\":{\"create\":5400000000000}}", - "allowDeprecatedImages": false, - "backupWindow": "", - "backups": false, - "datacenter": "hel1-dc2", - "deleteProtection": false, - "firewallIds": [], - "id": "29747477", - "ignoreRemoteFirewallIds": false, - "image": "ubuntu-22.04", - "ipv4Address": "95.216.195.228", - "ipv6Address": "2a01:4f9:c011:9f50::1", - "ipv6Network": "2a01:4f9:c011:9f50::/64", - "keepDisk": false, - "labels": {}, - "location": "hel1", - "name": "server-7ed8ea4", - "networks": [ - { - "aliasIps": [], - "ip": "10.0.1.2", - "macAddress": "86:00:00:3b:a3:ed", - "networkId": 2612654 - } - ], - "publicNets": [], - "rebuildProtection": false, - "serverType": "cx11", - "sshKeys": [], - "status": "running" - }, - "news": { - "__defaults": [ - "allowDeprecatedImages", - "backups", - "deleteProtection", - "ignoreRemoteFirewallIds", - "keepDisk", - "name", - "rebuildProtection" - ], - "allowDeprecatedImages": false, - "backups": false, - "deleteProtection": false, - "ignoreRemoteFirewallIds": false, - "image": "ubuntu-22.04", - "keepDisk": false, - "name": "server-7ed8ea4", - "networks": [ - { - "__defaults": [], - "networkId": 2612654 - } - ], - "rebuildProtection": false, - "serverType": "cx11" - } - }, - "response": { - "stables": "*", - "changes": "DIFF_NONE", - "hasDetailedDiff": true - }, - "metadata": { - "kind": "resource", - "mode": "client", - "name": "hcloud" - } -}` - - testutils.Replay(t, providerServer(t), diff) -} - -func providerServer(t *testing.T) pulumirpc.ResourceProviderServer { - ctx := context.Background() - - version.Version = "0.0.1" - info := provider.Provider() - info.Version = version.Version - - server, err := pf.MakeMuxedServer(ctx, "hcloud", info, []byte("{}"))(nil) - require.NoError(t, err) - - return server -} diff --git a/examples/server/ts/.gitignore b/examples/server/ts/.gitignore new file mode 100644 index 00000000..c6958891 --- /dev/null +++ b/examples/server/ts/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ diff --git a/examples/server/ts/Pulumi.yaml b/examples/server/ts/Pulumi.yaml new file mode 100644 index 00000000..d1b3775c --- /dev/null +++ b/examples/server/ts/Pulumi.yaml @@ -0,0 +1,3 @@ +name: server-ts +runtime: nodejs +description: A minimal TypeScript Pulumi program diff --git a/examples/server/ts/index.ts b/examples/server/ts/index.ts new file mode 100644 index 00000000..b82b5a41 --- /dev/null +++ b/examples/server/ts/index.ts @@ -0,0 +1,18 @@ +import * as hcloud from "@pulumi/hcloud"; + +const network = new hcloud.Network("network", { + ipRange: "10.0.1.0/24", +}); + +const subnet = new hcloud.NetworkSubnet("subnet", { + networkId: network.id.apply(Number), + ipRange: "10.0.1.0/24", + networkZone: "eu-central", + type: "cloud", +}); + +new hcloud.Server("server", { + serverType: "cx11", + image: "ubuntu-22.04", + networks: [{ networkId: network.id.apply(Number) }], +}, {dependsOn: subnet}); diff --git a/examples/server/ts/package.json b/examples/server/ts/package.json new file mode 100644 index 00000000..2207ea07 --- /dev/null +++ b/examples/server/ts/package.json @@ -0,0 +1,12 @@ +{ + "name": "server-ts", + "devDependencies": { + "@types/node": "^10.0.0" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0" + }, + "peerDependencies": { + "@pulumi/hcloud": "dev" + } +} diff --git a/examples/server/ts/tsconfig.json b/examples/server/ts/tsconfig.json new file mode 100644 index 00000000..ab65afa6 --- /dev/null +++ b/examples/server/ts/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts" + ] +} diff --git a/provider/resources.go b/provider/resources.go index 38f7ae33..b1f6f941 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -27,6 +27,7 @@ import ( "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" tks "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens" 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-hcloud/provider/pkg/version" ) @@ -65,6 +66,33 @@ func Provider() tfbridge.ProviderInfo { }, }, }, + "hcloud_server": { + // Work around + // https://github.com/hetznercloud/terraform-provider-hcloud/issues/650 + // by applying the fix described in + // https://github.com/hetznercloud/terraform-provider-hcloud/issues/650#issuecomment-1497160625. + PreCheckCallback: func( + ctx context.Context, config resource.PropertyMap, meta resource.PropertyMap, + ) (resource.PropertyMap, error) { + networksProp, ok := config["networks"] + if !ok || !networksProp.IsArray() { + return config, nil + } + networks := networksProp.ArrayValue() + for _, networkProp := range networks { + if !networkProp.IsObject() { + continue + } + const aliasIps = "aliasIps" + network := networkProp.ObjectValue() + if _, ok := network[aliasIps]; !ok { + tfbridge.GetLogger(ctx).Debug("Fixing up for https://github.com/hetznercloud/terraform-provider-hcloud/issues/650") + network[aliasIps] = resource.NewProperty([]resource.PropertyValue{}) + } + } + return config, nil + }, + }, }, JavaScript: &tfbridge.JavaScriptInfo{ // List any npm dependencies and their versions