这是indexloc提供的服务,不要输入任何密码
Skip to content

Consider and use the protection bypass for automation secret from the plan #295

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DavidS-ovm
Copy link

@DavidS-ovm DavidS-ovm commented Mar 28, 2025

This fixes #294.

Before this change, the vercel_project resource did not pass on changes
to the protection_bypass_for_automation_secret attribute on to the API.

This commit contains the following changes:

  • client/project_protection_bypass_for_automation_update.go: Change the anonymous struct member to accurately reflect what is marshalled
  • projectResource.Create(): always save the user-provided secret in the state, even if it is empty. This is required so that the update logic below doesn't try to reset the secret when it is generated by the vercel API.
  • projectResource.Update(): correctly handle the different update scenarios

Limitations

This change stops API-generated secrets to be returned into the state. This
will break existing setups that rely on this undocumented fact.

}
currentSecret := state.ProtectionBypassForAutomationSecret.ValueString()
plannedSecret := plan.ProtectionBypassForAutomationSecret.ValueString()
if state.ProtectionBypassForAutomation != plan.ProtectionBypassForAutomation && currentSecret != plannedSecret {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if state.ProtectionBypassForAutomation != plan.ProtectionBypassForAutomation && currentSecret != plannedSecret {
if state.ProtectionBypassForAutomation != plan.ProtectionBypassForAutomation || currentSecret != plannedSecret {

should this be an or? I don't think this actually accomplishes rotating the secret unless protection_bypass_for_automation also changes state.

Copy link
Author

Choose a reason for hiding this comment

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

🤦 Yes, you're absolutely right. Which also implies that this needs to be split up, deleting the secret when it exists but plan.ProtectionBypassForAutomation is false.

Copy link
Member

Choose a reason for hiding this comment

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

seems like that should be a validation that fails the plan instead of handling at the rpc boundary

… plan

This fixes vercel#294.

Before this change, the vercel_project resource did not pass on changes
to the protection_bypass_for_automation_secret attribute on to the API.

This commit contains the following changes:
* `client/project_protection_bypass_for_automation_update.go`: Change the anonymous struct member to accurately reflect what is marshalled
* `projectResource.Create()`: always save the user-provided secret in the state, even if it is empty. This is required so that the update logic below doesn't try to reset the secret when it is generated by the vercel API.
* `projectResource.Update()`: correctly handle the different update scenarios


## Limitations

This change stops API-generated secrets to be returned into the state. This
will break existing setups that rely on this undocumented fact.
@DavidS-ovm DavidS-ovm force-pushed the UpdateProtectionBypassForAutomation branch from cc4f951 to f99122c Compare April 10, 2025 10:11
@DavidS-ovm
Copy link
Author

Hi,

I've updated this now to handle all the update scenarios and address two other minor things I've noticed along the way.

I'm still not certain if this is fully correct:

  1. this breaks backwards compatibility for some users
  2. I do not understand how terraform state tracking works in the provider, so the update code paths might need more work to store the planned secret in the state

I'll need help with that.

Copy link
Collaborator

@kitfoster kitfoster left a comment

Choose a reason for hiding this comment

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

@DavidS-ovm thanks so much for raising this PR, and the wonderful issue, super clear 💅

I have tested this change, and noticed there are still a few tweaks needed. I raised a draft PR #305, you can take the changes from there and add them to this PR if that is easiest.

Note, to test this locally, these are the steps:

  1. run task build from the root of the repo
  2. create a main.tf in the root of the repo:
    terraform {
      required_providers {
        vercel = {
          source  = "vercel/vercel"
        }
      }
    }
    
    provider "vercel" {
      api_token = "<your team token>"
      team = "<your team slug>"
    }
    
    resource "vercel_project" "<team name>" {
      name                             = "<team name>"
      protection_bypass_for_automation = true
      protection_bypass_for_automation_secret = "12345678912345678912345678912347"
    }
    
  3. run terraform apply from the root of the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProtectionBypassForAutomationSecret Update only happens when ProtectionBypassForAutomation is toggled
4 participants