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

Terraform plan forces replacement of imported harbor_robot_account resource #447

Closed
nafaa-tayachi opened this issue Jun 20, 2024 · 6 comments · Fixed by #448
Closed

Terraform plan forces replacement of imported harbor_robot_account resource #447

nafaa-tayachi opened this issue Jun 20, 2024 · 6 comments · Fixed by #448
Labels
bug Something isn't working

Comments

@nafaa-tayachi
Copy link

Describe the bug

When I run terraform plan after importing a robot account resource, the plan shows it will force replace the resource.

Snippet from the terraform plan output:

  # harbor_robot_account.robot["robot$cyborg-18"] must be replaced
-/+ resource "harbor_robot_account" "robot" {
      ~ full_name   = "robot$cyborg-18" -> (known after apply)
      ~ id          = "/robots/9" -> (known after apply)
      + name        = "robot$cyborg-18" # forces replacement
      ~ robot_id    = "9" -> (known after apply)
      + secret      = (sensitive value)
        # (4 unchanged attributes hidden)
...

To Reproduce

  • import robot account resource
  • run terraform plan

Expected behavior
No force replacement on the imported robot account resource.

Additional context
I am not sure but I think the cause is that the name argument is missing in the function resourceRobotAccountRead

  • Provider Version v3.10.11
  • Terraform Version v1.6.4
  • Harbor Version v2.10.0-6abb4eab
@flbla flbla added the bug Something isn't working label Jun 21, 2024
flbla added a commit that referenced this issue Jun 21, 2024
@flbla
Copy link
Contributor

flbla commented Jun 21, 2024

hello,
thank you for the bug report
i did a fix, it will be in the next release of the provider

@flbla flbla closed this as completed Jun 21, 2024
flbla added a commit that referenced this issue Jun 21, 2024
flbla added a commit that referenced this issue Jun 21, 2024
flbla added a commit that referenced this issue Jun 21, 2024
@flbla
Copy link
Contributor

flbla commented Jun 21, 2024

it will be in the v3.10.12 (build in progress)

@nafaa-tayachi
Copy link
Author

Hi @flbla - thanks for the quick fix!

I tried using the latest provider version v3.10.12 but the terraform plan still shows force replacement of the resource.

In case this helps you investigating, I am trying to import a system level robot account.

@flbla
Copy link
Contributor

flbla commented Jun 24, 2024

Hi @nafaa-tayachi ,
I did the same test with the latest build (v3.10.12) :

terraform init :

- Installing goharbor/harbor v3.10.12...
- Installed goharbor/harbor v3.10.12 (unauthenticated)

I created a system robot account through the GUI :
image
image

Then I created this tf code :

resource "harbor_robot_account" "name" {
  name = "test"
  description = "test"
  level = "system"

  permissions {
    access {
      action = "pull"
      resource = "repository"
    }
    access {
      action = "push"
      resource = "repository"
    }
    kind = "project"
    namespace = "library"
  }
  
}

I imported it :

terraform import harbor_robot_account.name /robots/5
harbor_robot_account.name: Importing from ID "/robots/5"...
harbor_robot_account.name: Import prepared!
  Prepared harbor_robot_account for import
harbor_robot_account.name: Refreshing state... [id=/robots/5]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

and when I try to apply it, it do not replace it, just update it :

  # harbor_robot_account.name will be updated in-place
  ~ resource "harbor_robot_account" "name" {
      + description = "test"
      ~ duration    = 30 -> -1
        id          = "/robots/5"
        name        = "test"
        # (4 unchanged attributes hidden)

      - permissions {
          - kind      = "system" -> null
          - namespace = "/" -> null

          - access {
              - action   = "list" -> null
              - resource = "audit-log" -> null
                # (1 unchanged attribute hidden)
            }
        }
      + permissions {
          + kind      = "project"
          + namespace = "library"

          + access {
              + action   = "pull"
              + effect   = "allow"
              + resource = "repository"
            }
          + access {
              + action   = "push"
              + effect   = "allow"
              + resource = "repository"
            }
        }
    }

@flbla
Copy link
Contributor

flbla commented Jun 24, 2024

after the upgrade to v3.10.12, did you try remove it from the state and re-import it ?
@nafaa-tayachi

@nafaa-tayachi
Copy link
Author

my bad .. it is working now
thanks again @flbla !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants