goharbor / terraform-provider-harbor

A Terraform provider for Harbor. To configure and manage all aspects of your Harbor Container Registry with Terraform Infrastructure as Code.
https://registry.terraform.io/providers/goharbor/harbor
MIT License
116 stars 89 forks source link

Error getting system configuration unexpected end of JSON input when creating a robot account #464

Open hlourencomarques opened 1 month ago

hlourencomarques commented 1 month ago

Describe the bug Starting at version 3.10.12, I cannot create a very simple robot account in Harbor without any error. The robot account gets created but the Terraform apply command ends with the following error:

│ Error: error getting system configuration unexpected end of JSON input │ │ with harbor_robot_account.test2, │ on harbor.tf line 16, in resource "harbor_robot_account" "test": │ 16: resource "harbor_robot_account" "test" {

To Reproduce

  1. Create a configuration file, e.g. harbor.tf:

    resource "harbor_robot_account" "test" { name = "test" level = "project" permissions { kind = "project" namespace = "my-namespace" access { action = "read" resource = "repository" } } }

  2. Apply changes: terraform apply

  3. Confirm the application of changes:

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:

harbor_robot_account.test will be created

  • resource "harbor_robot_account" "test" {

    • disable = false

    • duration = -1

    • full_name = (known after apply)

    • id = (known after apply)

    • level = "project"

    • name = "test"

    • robot_id = (known after apply)

    • secret = (sensitive value)

    • permissions {

      • kind = "project"

      • namespace = "my-namespace"

      • access {

        • action = "read"
        • effect = "allow"
        • resource = "repository" } } }

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

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

Enter a value: yes

Expected behavior Change applied successfully.

Additional context This is working with the provider version 3.10.11 and older.

flbla commented 1 month ago

Hi @hlourencomarques, I tried the exact same code you provided and I have no issue with latests versions of the provider :

resource "harbor_robot_account" "test" {
  name  = "test"
  level = "project"
  permissions {
    kind      = "project"
    namespace = "my-namespace"
    access {
      action   = "read"
      resource = "repository"
    }
  }
}

harbor_robot_account.name: Creating...
harbor_robot_account.test: Creation complete after 0s [id=/robots/2]

Automated tests were also ran on Harbor 2.9 and Terraform 1.9 without any issues for these tags

Robots accounts tests

I think your issue due to this change : https://github.com/goharbor/terraform-provider-harbor/pull/448/files Do you use an admin account to create robot account ? If not, it's probably a lack of rights

hlourencomarques commented 1 month ago

Hello @flbla, Sorry for the delay; I was on vacation.
I'm using an account with only the Project Admin role, not the (Harbor) Admin role. This may be the root cause.
Thank you for preparing the PR to fix this issue. I hope it will be merged soon.