Skip to content

Commit

Permalink
Fix static get function for ssm.parameter with versioned or labeled I…
Browse files Browse the repository at this point in the history
…Ds (#4014)

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

Fixes #4011
  • Loading branch information
flostadler authored Jun 4, 2024
1 parent 1638e1b commit b61bb34
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
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: filepath.Join(getCwd(t), "regress-4011"),
EditDirs: []integration.EditDir{{
Dir: filepath.Join(getCwd(t), "regress-4011", "step1"),
Additive: 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
24 changes: 24 additions & 0 deletions examples/regress-4011/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 = 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"
}
}
27 changes: 27 additions & 0 deletions examples/regress-4011/step1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 = new aws.ssm.Parameter('regress-4011-test-secret', {
name: 'regress-4011-test-secret',
type: 'SecureString',
value: "test",
});

const retrievedParam = aws.ssm.Parameter.get('retrieved-parameter', 'regress-4011-test-secret:1');

export const secret = pulumi.output(param).arn;
export const retrievedSecret = pulumi.output(retrievedParam).arn;
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())
+ 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())

0 comments on commit b61bb34

Please sign in to comment.