Skip to content

Commit

Permalink
Fix updating tags on aws_launch_template (#3687)
Browse files Browse the repository at this point in the history
Fixes #1504

Due to discrepancies between TF and Pulumi Bridged provider life cycle,
editing tags on a Launch Template resource caused failure in pulumi-aws.
This is now fixed by opting in this resource to the PlanResourceChange
behavior that tracks TF lifecycle more closely.
  • Loading branch information
t0yv0 authored Mar 23, 2024
1 parent 7116956 commit 670b38d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
32 changes: 32 additions & 0 deletions provider/provider_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
)

Expand All @@ -30,6 +32,36 @@ func TestRegress3196(t *testing.T) {
})
}

func TestRegress1504(t *testing.T) {
if testing.Short() {
t.Skipf("Skipping test in -short mode because it needs cloud credentials")
return
}
test := getPythonBaseOptions(t).
With(integration.ProgramTestOptions{
// Not ideal, need investigation:
ExpectRefreshChanges: true,
Dir: filepath.Join("test-programs", "regress-1504", "init"),
EditDirs: []integration.EditDir{
{
Dir: filepath.Join("test-programs", "regress-1504", "step-1"),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assert.Equal(t, float64(1), stack.Outputs["launch_template_latest_version"])
},
Additive: true,
},
{
Dir: filepath.Join("test-programs", "regress-1504", "step-2"),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assert.Equal(t, float64(2), stack.Outputs["launch_template_latest_version"])
},
Additive: true,
},
},
})
integration.ProgramTest(t, &test)
}

func getPythonBaseOptions(t *testing.T) integration.ProgramTestOptions {
t.Helper()
envRegion := getEnvRegion(t)
Expand Down
4 changes: 3 additions & 1 deletion provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
shimv2.WithDiffStrategy(shimv2.PlanState),
shimv2.WithPlanResourceChange(func(s string) bool {
switch s {
case "aws_ssm_document", "aws_wafv2_web_acl":
case "aws_ssm_document",
"aws_wafv2_web_acl",
"aws_launch_template":
return true
default:
return false
Expand Down
10 changes: 10 additions & 0 deletions provider/test-programs/regress-1504/init/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: repro-1504
runtime:
name: python
options:
virtualenv: venv
description: Reproduce pulumi-aws issue 1504
config:
pulumi:tags:
value:
pulumi:template: aws-python
13 changes: 13 additions & 0 deletions provider/test-programs/regress-1504/init/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pulumi
import pulumi_aws as aws

ec2_launch_template = aws.ec2.LaunchTemplate(
"my_launch_template",
image_id="ami-0c55b159cbfafe1f0",
instance_type="t2.micro",
key_name='key1',
tags={"Name": 'tag1'},
update_default_version=True)

pulumi.export("launch_template_id", ec2_launch_template.id)
pulumi.export("launch_template_latest_version", ec2_launch_template.latest_version)
1 change: 1 addition & 0 deletions provider/test-programs/regress-1504/init/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pulumi>=3.0.0,<4.0.0
13 changes: 13 additions & 0 deletions provider/test-programs/regress-1504/step-1/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pulumi
import pulumi_aws as aws

ec2_launch_template = aws.ec2.LaunchTemplate(
"my_launch_template",
image_id="ami-0c55b159cbfafe1f0",
instance_type="t2.micro",
key_name='key1',
tags={"Name": 'tag2'},
update_default_version=True)

pulumi.export("launch_template_id", ec2_launch_template.id)
pulumi.export("launch_template_latest_version", ec2_launch_template.latest_version)
13 changes: 13 additions & 0 deletions provider/test-programs/regress-1504/step-2/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pulumi
import pulumi_aws as aws

ec2_launch_template = aws.ec2.LaunchTemplate(
"my_launch_template",
image_id="ami-0c55b159cbfafe1f0",
instance_type="t2.micro",
key_name='key2',
tags={"Name": 'tag2'},
update_default_version=True)

pulumi.export("launch_template_id", ec2_launch_template.id)
pulumi.export("launch_template_latest_version", ec2_launch_template.latest_version)

0 comments on commit 670b38d

Please sign in to comment.