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

Error: expected "access_token" to not be an empty string when project provider is removed #112

Closed
2 of 3 tasks
hsiddiqui84 opened this issue Apr 2, 2024 · 5 comments
Closed
2 of 3 tasks
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@hsiddiqui84
Copy link

Describe the bug

Artifactory Cloud version: 7.78.1
Terraform version: 1.3.6
Project provider version: 1.5.2

Upon removing the project provider, terraform plan fails with the following error:

Error: Invalid provider configuration

Provider "registry.terraform.io/jfrog/project" requires explicit
configuration. Add a provider block to the root module and configure the
provider's required arguments as described in the provider documentation.

Error: expected "access_token" to not be an empty string, got 

  with provider["registry.terraform.io/jfrog/project"],
  on <empty> line 0:
  (source code not available)

Requirements for and issue

  • A fully functioning terraform snippet that can be copy&pasted (no outside files or ENV vars unless that's part of the issue)
  • Your version of artifactory (you can curl it at $host/artifactory/api/system/version
  • Your version of terraform

Expected behavior
The project provider can be removed without any errors.

This is similar to the issue for the artifactory provider: jfrog/terraform-provider-artifactory#425

@hsiddiqui84 hsiddiqui84 added the bug Something isn't working label Apr 2, 2024
@alexhung
Copy link
Member

alexhung commented Apr 2, 2024

@hsiddiqui84 Please provide an example of your HCL. This error suggests you still have a resource/data source that reference the project provider but your no longer have the provider "project" block in your HCL.

@alexhung alexhung added the question Further information is requested label Apr 2, 2024
@hsiddiqui84
Copy link
Author

I was getting the following error:

Error: 
404 GET https://xxxx/access/api/v1/projects/projectxxx
{
  "errors" : [ {
    "code" : "NOT_FOUND",
    "message" : "Could not find project with key `projectxxx`"
  } ]
}

so I removed the project provider:

provider "project" {
  url          = "https://${var.artifactory_hostname}/artifactory"
  access_token = var.access_token
}

But I still had it declared as part of the required_providers block:

project = {
      source  = "registry.terraform.io/jfrog/project"
      version = "1.4.0"
    }

I went ahead and removed the above as well after which I got the original error reported in this issue:

Error: expected "access_token" to not be an empty string, got 

  with provider["registry.terraform.io/jfrog/project"],
  on <empty> line 0:
  (source code not available)

I had to manually remove the projects from the state file to be able to successfully apply subsequent changes:

terragrunt state rm "module.project[\"projectxxx\"].project.this"

@alexhung
Copy link
Member

alexhung commented Apr 3, 2024

@hsiddiqui84 Your comment suggests that the project is removed out-of-band, i.e. not using terraform destroy --target "module.project[\"projectxxx\"].project.this".

I try to reproduce this by first creating a project:

alexh@alexh-mac terraform-provider-project % terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # project.myproject will be created
  + resource "project" "myproject" {
      + block_deployments_on_limit      = false
      + description                     = "My Project"
      + display_name                    = "My Project"
      + email_notification              = true
      + id                              = (known after apply)
      + key                             = "myproj"
      + max_storage_in_gibibytes        = 10
      + use_project_group_resource      = true
      + use_project_repository_resource = true
      + use_project_role_resource       = true
      + use_project_user_resource       = true

      + admin_privileges {
          + index_resources  = true
          + manage_members   = true
          + manage_resources = true
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

project.myproject: Creating...
project.myproject: Creation complete after 0s [id=myproj]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Then without changing the configuration, I delete the project in Artifactory web UI. Then run terraform plan which reports correctly that it wants to recreate the project resource:

alexh@alexh-mac terraform-provider-project % terraform plan
project.myproject: Refreshing state... [id=myproj]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # project.myproject will be created
  + resource "project" "myproject" {
      + block_deployments_on_limit      = false
      + description                     = "My Project"
      + display_name                    = "My Project"
      + email_notification              = true
      + id                              = (known after apply)
      + key                             = "myproj"
      + max_storage_in_gibibytes        = 10
      + use_project_group_resource      = true
      + use_project_repository_resource = true
      + use_project_role_resource       = true
      + use_project_user_resource       = true

      + admin_privileges {
          + index_resources  = true
          + manage_members   = true
          + manage_resources = true
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Without applying the change, I remove resource "project" "myproject" from the configuration and run terraform plan again:

alexh@alexh-mac terraform-provider-project % terraform plan
project.myproject: Refreshing state... [id=myproj]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Again TF & the provider is behaving correctly with no error.

I then remove the provider "project" block and run terraform plan. Again no error.

After running terraform apply, the project resource is removed from the TF state.

@alexhung
Copy link
Member

alexhung commented Apr 3, 2024

@hsiddiqui84 In your comment, you have the project provider version 1.4.0

project = {
  source  = "registry.terraform.io/jfrog/project"
  version = "1.4.0"
}

I suspect that is how you are getting that 404 error from the provider/API. Please upgrade to 1.5.2 and let me know if this issue still exists.

@hsiddiqui84
Copy link
Author

Your understanding is correct. The functionality to add / modify projects on the edge nodes is no longer available so the projects were manually removed by the PE team. The existing remote repos needed to be detached from the existing projects before deleting them.

We no longer use te project provider for edge nodes so we are good for now.

@alexhung alexhung closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants