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

aws:ec2:LaunchTemplate update_default_version Fails on AWS Provider #1504

Closed
farvour opened this issue May 20, 2021 · 12 comments · Fixed by #3687
Closed

aws:ec2:LaunchTemplate update_default_version Fails on AWS Provider #1504

farvour opened this issue May 20, 2021 · 12 comments · Fixed by #3687
Assignees
Labels
bug/diff kind/bug related to Pulumi generating wrong diffs on preview or up. customer/feedback Feedback from customers customer/lighthouse Lighthouse customer bugs kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@farvour
Copy link

farvour commented May 20, 2021

I upgraded the AWS provider from 3.23 to the latest 4.5.1 recently to do a Pulumi 3.x upgrade. Noticed some code that sets update_default_version on this provider fails now when doing a pulumi update on the existing resources.

Expected behavior

No changes should have been seen by the provider and updateDefaultVersion should continue to function as desired.

Current behavior

  aws:ec2:LaunchTemplate (ci-general):
    error: 1 error occurred:
    	* updating urn:pulumi:ci::aws-eks-py::aws:ec2/launchTemplate:LaunchTemplate::ci-general: 1 error occurred:
    	* error modifying Launch Template (lt-<REDACTED>): InvalidParameterValue: Invalid launch template version: either '$Default', '$Latest', or a numeric version are allowed.

also, it doesn't even show up in the list of diffSet, so something tells me the provider is misbehaving internally here.

     pulumi:pulumi:Stack        aws-eks-py-ci   **failed**              1 error
 ~   ├─ aws:ec2:LaunchTemplate  ci-kiam-server  **updating failed**     [diff: -tagsAll~tags]; 1 error
 ~   └─ aws:ec2:LaunchTemplate  ci-general      **updating failed**     [diff: -tagsAll~tags]; 1 error

Steps to reproduce

We are using the Python dialect. Create a pulumi_aws.ec2.LaunchTemplate resource and set the update_default_version attribute to True.

Context (Environment)

Existing resource was present and may or may not affect the outcome of the result. This was a LaunchTemplate whose versioning updating was working just fine prior to upgrading the pulumi-aws provider to 4.5.1 and pulumi to 3.2.1.

This seems like a really old Terraform issue to be honest, that somehow resurfaced itself (regression?) in the newer AWS provider. hashicorp/terraform-provider-aws#4655

Affected feature

N/A

@farvour farvour added the kind/bug Some behavior is incorrect or out of spec label May 20, 2021
@farvour
Copy link
Author

farvour commented May 20, 2021

The workaround right now is to just pull the update_default_version field so it's False. Not ideal, but our AutoScaleGroups use $$Latest so it doesn't break anything, just makes the resource inconsistent in the UI for other users who want to examine the current default version of a LaunchTemplate.

@lukehoban lukehoban added kind/bug Some behavior is incorrect or out of spec and removed kind/bug Some behavior is incorrect or out of spec labels May 27, 2021
@emiliza emiliza added the impact/regression Something that used to work, but is now broken label Jun 4, 2021
@leezen leezen added this to the 0.58 milestone Jun 8, 2021
@lukehoban lukehoban modified the milestones: 0.58, 0.59 Jul 6, 2021
@stack72 stack72 removed their assignment Jul 23, 2021
@stack72 stack72 removed this from the 0.59 milestone Jul 23, 2021
@Sodki
Copy link

Sodki commented Oct 5, 2021

@farvour is this still an issue to you? I'm using update_default_version=True with the latest Pulumi and it's working.

@stack72 stack72 added the resolution/no-repro This issue wasn't able to be reproduced label Jun 7, 2022
@stack72
Copy link
Contributor

stack72 commented Jun 7, 2022

Going to close this out - there's been no response here so it seems all is working?

@stack72 stack72 closed this as completed Jun 7, 2022
@farvour
Copy link
Author

farvour commented Apr 11, 2023

So,... this feels like it came back again:

      ~ pulumi:providers:aws: (update)
        [id=c0481110-ffc5-47c0-94da-ded7f28d552f]
        [urn=urn:pulumi:orgname.us-gov-west-1.networking::aws-orgname-networking-general::pulumi:providers:aws::us-gov-networking]
      ~ version                  : "5.32.0" => "5.33.0"
    aws:ec2:LaunchTemplate (ec2-ubuntu-22.04-general):
    error: 1 error occurred:
    	* updating urn:pulumi:orgname.us-gov-west-1.networking::aws-orgname-networking-general::aws:ec2/launchTemplate:LaunchTemplate::ec2-ubuntu-22.04-general: 1 error occurred:
    	* updating EC2 Launch Template (lt-0b97625fbfdb72e01): InvalidParameterValue: Invalid launch template version: either '$Default', '$Latest', or a numeric version are allowed.
    	status code: 400, request id: 6c9e1be4-acad-4da9-a591-af92db353476```

@lacaSG
Copy link

lacaSG commented Nov 21, 2023

I'm getting this when I'm trying to add a tag to an otherwise unchanged launch template. If I update a property of the template, it works fine. using update_default_version=True

@murbot
Copy link

murbot commented Jan 26, 2024

I'm getting this when I'm trying to add a tag to an otherwise unchanged launch template. If I update a property of the template, it works fine. using update_default_version=True

Just ran into the exact same scenario.

@lukehoban lukehoban added awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). and removed impact/regression Something that used to work, but is now broken resolution/no-repro This issue wasn't able to be reproduced labels Jan 27, 2024
@lukehoban
Copy link
Member

I believe this is the same issue tracked in hashicorp/terraform-provider-aws#34867 upstream. Will reopen here as tracking that issue being fixed and adopted into this provider.

@lukehoban lukehoban reopened this Jan 27, 2024
@t0yv0 t0yv0 self-assigned this Mar 21, 2024
@t0yv0 t0yv0 added this to the 0.102 milestone Mar 21, 2024
@t0yv0
Copy link
Member

t0yv0 commented Mar 22, 2024

I can reproduce on latest Pulumi with the following:

import pulumi
import pulumi_aws as aws

config = pulumi.Config()
key_name = config.require("key_name")
tag_name = config.require("tag_name")

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

# Export the ID of the launch template
pulumi.export("launch_template_id", ec2_launch_template.id)
pulumi.export("launch_template_latest_version", ec2_launch_template.latest_version)
#!/usr/bin/env bash

set -euo pipefail

pulumi destroy --yes

# Initial configuration
pulumi config set tag_name tag1
pulumi config set key_name key1
pulumi up --skip-preview --yes

# Change only tag
pulumi config set tag_name tag2
pulumi config set key_name key1
pulumi preview --diff
PULUMI_DEBUG_GRPC="$PWD/repro.json" pulumi up --skip-preview --yes   # version not changing

Observing that the issue happens for programs that specify update_default_version=True during changes that only affect
tags and nothing else. If I do not specify update_default_version=True, or if I change only the key_name, then the
program behaves as expected:

  • latest_version is incremented for every change to key_name
  • latest_version is not incremented for every change to tag_name (but only works with update_default_version=True)

Debugging the failure leads to this line:

https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/ec2_launch_template.go#L1132

ModifyLaunchTemplateWithContext fails because DefaultVersion incorrectly interpreted a Computed latestVersion as 0.

(dlv) print d.diff.Attributes["latest_version"]
*github.com/hashicorp/terraform-plugin-sdk/v2/terraform.ResourceAttrDiff {
        Old: "1",
        New: "0",
        NewComputed: true,
        NewRemoved: false,
        NewExtra: interface {} nil,
        RequiresNew: false,
        Sensitive: false,
        Type: 0,}

I suspect that the diff customizer is something that sets it to computed, verifying this.
https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/ec2_launch_template.go#L963

@t0yv0
Copy link
Member

t0yv0 commented Mar 22, 2024

Curiously, this particular repro does not reproduce once WithPlanResourceChange is applied to the aws_launch_template
resource. This is because this flag removes the impedance mismatch that existed prior, where Terraform does not run the
diff customizers again on Update the second time, it only runs them once as part of preparing the PlanResourceChange
plan. This could be our fix here, verifying.

If this theory is correct though, this repro would not reproduce on the similar program written in TF, and the fix would
not be fixing any manifestations of the issue present in the upstream provider. If something reproduces in TF we could
instead workaround by patching to amend the failing code to pay attention to Computed values and treat them specially.

t0yv0 added a commit that referenced this issue Mar 22, 2024
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.
@t0yv0
Copy link
Member

t0yv0 commented Mar 22, 2024

Curiously, this particular repro does not reproduce once WithPlanResourceChange is applied to the aws_launch_template
resource. This is because this flag removes the impedance mismatch that existed prior, where Terraform does not run the
diff customizers again on Update the second time, it only runs them once as part of preparing the PlanResourceChange
plan. This could be our fix here, verifying.

If this theory is correct though, this repro would not reproduce on the similar program written in TF, and the fix would
not be fixing any manifestations of the issue present in the upstream provider. If something reproduces in TF we could
instead workaround by patching to amend the failing code to pay attention to Computed values and treat them specially.

@t0yv0
Copy link
Member

t0yv0 commented Mar 22, 2024

I have confirmed that this issue does not currently reproduce in Terraform. To double check I also tried tags under
tags_specifications, but it all seems to work as expected. I read the upstream issue that still open in TF but it was a
little unclear on the repro steps.

Suggest moving forward here with this change that fixes the problem with updating tags:

#3687

The root cause is that CustomizeDiff methods should not be run on Update, but are, cause this to fail under Pulumi.

Tracking broader PlanResourceChange rollout in pulumi/pulumi-terraform-bridge#1785

@t0yv0 t0yv0 added customer/feedback Feedback from customers customer/lighthouse Lighthouse customer bugs and removed awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). labels Mar 22, 2024
@t0yv0
Copy link
Member

t0yv0 commented Mar 22, 2024

This is now releasing and automation should close this and make a new release. Please let us know if this fix works, and reopen if there's any further issues in this area. Appreciate your patience!

@t0yv0 t0yv0 added the bug/diff kind/bug related to Pulumi generating wrong diffs on preview or up. label Mar 22, 2024
t0yv0 added a commit that referenced this issue Mar 23, 2024
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.
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/diff kind/bug related to Pulumi generating wrong diffs on preview or up. customer/feedback Feedback from customers customer/lighthouse Lighthouse customer bugs kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants