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

Fix static get function for ssm.parameter with versioned or labeled IDs #4014

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,21 @@ func TestRdsGetEngineVersion(t *testing.T) {
engineVersion := res.Outputs["vs"]
require.NotEmpty(t, engineVersion.Value)
}

// Checks static get function for ssm.parameter that was broken for versioned IDs.
//
// See https://github.com/pulumi/pulumi-aws/issues/4011
func TestRegress4011(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: "regress-4011",
})

// Refresh is inherently showing diffs for the versioned IDs.
test.AllowEmptyPreviewChanges = true
test.AllowEmptyUpdateChanges = true

// Disable envRegion mangling
test.Config = nil
integration.ProgramTest(t, &test)
}
3 changes: 3 additions & 0 deletions examples/regress-4011/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: regress-4011
runtime: nodejs
description: Regress pulumi/pulumi-aws#4011
28 changes: 28 additions & 0 deletions examples/regress-4011/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2016-2024, 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.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const param = aws.ssm.getParameter({ name: 'regress-4011-test-secret' }).then(
() => aws.ssm.Parameter.get('regress-4011-test-secret', 'regress-4011-test-secret:1'),
() =>
new aws.ssm.Parameter('regress-4011-test-secret', {
name: 'regress-4011-test-secret',
type: 'SecureString',
value: "test",
})
);

export const secret = pulumi.output(param).arn;
16 changes: 16 additions & 0 deletions examples/regress-4011/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "regress-4011",
"version": "0.0.1",
"license": "Apache-2.0",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@pulumi/pulumi": "^3.0.0",
"@pulumi/aws": "^6.0.0"
},
"devDependencies": {
"@types/aws-sdk": "^2.7.0",
"@types/node": "^8.0.0"
}
}
18 changes: 18 additions & 0 deletions examples/regress-4011/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Florian Stadler <[email protected]>
Date: Mon, 3 Jun 2024 21:23:04 +0200
Subject: [PATCH] Fix static get function for ssm.parameter with versioned or
labled IDs

When the SSM resources where moved to the AWS SDK v2 the lookup of
SSM parameters with versions or labels got broken. This fixes that
again.

diff --git a/internal/service/ssm/parameter.go b/internal/service/ssm/parameter.go
index 5a24c9641a..09d7cfea45 100644
--- a/internal/service/ssm/parameter.go
+++ b/internal/service/ssm/parameter.go
@@ -259,7 +259,7 @@ func resourceParameterRead(ctx context.Context, d *schema.ResourceData, meta int
return sdkdiag.AppendErrorf(diags, "invalid configuration, cannot set type = %s and insecure_value", param.Type)
}

- detail, err := findParameterMetadataByName(ctx, conn, d.Id())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before moving to SDK v2 it used the name. That's why the regression was introduced

Copy link
Member

Choose a reason for hiding this comment

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

@flostadler that's very unfortunate. I'll add to our roadmap one more time the task of covering all patches with tests. It has to be done alas.

+ detail, err := findParameterMetadataByName(ctx, conn, *param.Name)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] SSM Parameter %s not found, removing from state", d.Id())
Loading