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

Project: Remove project from state if tf project creation plan fails #1150

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

danaelhe
Copy link
Member

@danaelhe danaelhe commented Apr 29, 2024

Addresses #1143

Fixes following scenario:

  1. User creates plan with a new project and adds unacceptable resources (i.e. vpc) to project
  2. Terraform plan fails, project is still created but not added to terraform state
  3. User fixes plan by removing unacceptable resources
  4. User re-applies plan, plan fails with project with same name already exists error because project was never added to terraform state, so terraform thinks it doesn't exist, though the project does exist in DO.

This fix will delete a project if the adding resources to project request fails, therefore being more aligned with the terraform state.

Terraform plan to reproduce:

resource "digitalocean_droplet" "web" {
  name   = "web-01"
  size   = "s-1vcpu-1gb"
  image  = "ubuntu-22-04-x64"
  region = "nyc3"
}

resource "digitalocean_vpc" "test" {
    name        = "test"
    region      = "nyc3"
    ip_range    = "10.8.0.0/16"
}

resource "digitalocean_project" "test3" {
  name = "test3"
  resources = [
    digitalocean_vpc.test.urn,
    digitalocean_droplet.web.urn
  ]
}

@danaelhe danaelhe requested a review from a team April 29, 2024 21:10
@danaelhe danaelhe merged commit 1c8f5bf into main Apr 30, 2024
3 checks passed
@danaelhe danaelhe deleted the project/fix_tf_state branch April 30, 2024 14:44
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.

None yet

2 participants