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

Inconsistent behaviour: re-run "terraform apply" doesn't re-create deleted project #809

Open
james-ni opened this issue Dec 8, 2023 · 3 comments

Comments

@james-ni
Copy link

james-ni commented Dec 8, 2023

Terraform Version

1.5.6

Harness Provider Version

0.29.2

Affected Resource(s)

Only harness_platform_project is affected.

Other resource types like harness_platform_service, harness_platform_variable are behaving as expected.

Terraform Configuration Files

terraform {
  required_providers {
    harness = {
      source = harness/harness
    }
  }
}

provider "harness" {
  endpoint      = "https://app.harness.io/gateway"
  account_id  = "xxxxxxx"
}

resource "harness_platform_project" "project" {
  identifier     = "james123"
  name           = "james
  description = "james"
  org_id         = "org1"
}

Expected Behavior

When:

  1. terraform init
  2. terraform apply --auto-approve (this will create the project)
  3. manually delete project from Harness UI
  4. terraform apply --auto-approve

I'm expecting step 4 (re-run terraform apply) will create the project.

Actual Behavior

step 4terraform apply failed, with error message "404 Not Found"

This behaviour is inconsistent with other Harness resources like service, variable...

@james-ni james-ni changed the title re-run "terraform apply" doesn't re-create deleted project Inconsistent behaviour: re-run "terraform apply" doesn't re-create deleted project Dec 8, 2023
@james-ni
Copy link
Author

james-ni commented Dec 8, 2023

Service request was raised to

https://support.harness.io/hc/en-us/request/54887

@james-ni
Copy link
Author

james-ni commented Dec 8, 2023

Possible root cause

Harness GET project behaves differently from other GET xxx APIs (e.g. service, variable...)

  • GET project returns payload {"code": "ENTITY_NOT_FOUND"}, when a given project id doesn't exist
  • GET service (or any other resources) returns payload {"code": "RESOURCE_NOT_FOUND_EXCEPTION"}, when a given service id doesn't exist

The error handling code below only handles {"code": "RESOURCE_NOT_FOUND_EXCEPTION"}, not {"code": "ENTITY_NOT_FOUND"}. That's why it failed to re-create project and error out.

if erro.Code() == nextgen.ErrorCodes.ResourceNotFound {
d.SetId("")
d.MarkNewResource()
return nil

Actually there is another exception

  • GET resource_group API returns payload {"code": "RESOURCE_NOT_FOUND"}, when a given resource group id doesn't exist.

@james-ni
Copy link
Author

james-ni commented Dec 8, 2023

Proposed Change

  • option 1: add {"code": "ENTITY_NOT_FOUND"} to the if condition, like
      if erro.Code() == nextgen.ErrorCodes.ResourceNotFound || erro.Code() == "ENTITY_NOT_FOUND" {
      	d.SetId("")
      	d.MarkNewResource()
      	return nil
      }
  • option 2: modify the GET project API, so that if returns {"code": "RESOURCE_NOT_FOUND_EXCEPTION"} when given project id doesn't exist

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 a pull request may close this issue.

1 participant