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

Delete before replace sns topic #3268

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions provider/provider_go_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build !python && !yaml && !nodejs && !dotnet && !java
// +build !python,!yaml,!nodejs,!dotnet,!java

package provider

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestSnsTopicReplacement(t *testing.T) {
ptest := pulumiTest(t, filepath.Join("test-programs", "sns-topic-replacement"))
ptest.InstallStack("test")

topicName := randSeq(12)
ptest.SetConfig("topicName", topicName)

providerName := randSeq(12)
ptest.SetConfig("providerName", providerName)
ptest.Up()

// Change the name of the provider to check if topic replacement works.
providerName = randSeq(12)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the test actually know it got replaced? Is there some small assert we could add to make it more obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I've verified it from the logs but I'll also add an assert to make it more obvious

ptest.SetConfig("providerName", providerName)
ptest.Up()

resRef := ptest.Refresh()

require.Equal(t, 0, (*resRef.Summary.ResourceChanges)["replace"])
require.Equal(t, 0, (*resRef.Summary.ResourceChanges)["delete"])
}
30 changes: 30 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package provider

import (
"context"
"math/rand"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/pulumi/providertest"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/opttest"
pfbridge "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"

Expand Down Expand Up @@ -56,3 +60,29 @@ func getEnvRegion(t *testing.T) string {
}
return envRegion
}

func pulumiTest(t *testing.T, dir string) *pulumitest.PulumiTest {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without AWS creds")
return nil
}
cwd, err := os.Getwd()
if err != nil {
t.Error(err)
}
ptest := pulumitest.NewPulumiTest(t, dir,
opttest.LocalProviderPath("aws", filepath.Join(cwd, "..", "bin")),
)

return ptest
}

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
30 changes: 0 additions & 30 deletions provider/provider_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
package provider

import (
"math/rand"
"os"
"path/filepath"
"testing"

"github.com/pulumi/providertest"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -90,32 +86,6 @@ func TestSecretsManagerSecret(t *testing.T) {
test(t, filepath.Join("test-programs", "secretsmanager-secret"))
}

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

func pulumiTest(t *testing.T, dir string) *pulumitest.PulumiTest {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without AWS creds")
return nil
}
cwd, err := os.Getwd()
if err != nil {
t.Error(err)
}
ptest := pulumitest.NewPulumiTest(t, dir,
opttest.LocalProviderPath("aws", filepath.Join(cwd, "..", "bin")),
)

return ptest
}

func TestNonIdempotentSnsTopic(t *testing.T) {
ptest := pulumiTest(t, filepath.Join("test-programs", "non-idempotent-sns-topic"))

Expand Down
1 change: 1 addition & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,7 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
},
}),
},
DeleteBeforeReplace: true, // only a single topic with a given name can exist.
},
"aws_sns_topic_policy": {
Tok: awsResource(snsMod, "TopicPolicy"),
Expand Down
3 changes: 3 additions & 0 deletions provider/test-programs/sns-topic-replacement/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: sns-topic-replacement
runtime: go
description: A minimal AWS Go Pulumi program
93 changes: 93 additions & 0 deletions provider/test-programs/sns-topic-replacement/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module sns-topic-replacement

go 1.21

toolchain go1.21.3

require (
github.com/pulumi/pulumi-aws/sdk/v6 v6.17.0
github.com/pulumi/pulumi/sdk/v3 v3.100.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.24.2 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/djherbis/times v1.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl/v2 v2.17.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.6.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
)
Loading
Loading