atlassian / terraform-provider-artifactory

Terraform provider to manage Artifactory
Apache License 2.0
89 stars 42 forks source link

Descriptions and internal notes don't get removed when changed to empty/null/undefined #72

Open kubiak95 opened 4 years ago

kubiak95 commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.21 terraform-provider-artifactory 2.0.0-alpha1

Affected Resource(s)

Terraform Configuration Files

provider "artifactory" {
  url = var.auth_url
  api_key = var.auth_api_key
}

resource "artifactory_local_repository" "local_repository" {
  key = "test-repo"
  package_type = "pypi"
}

resource "artifactory_remote_repository" "remote_repository" {
  key = "test-remote-repo"
  url = "https://files.pythonhosted.org"
  package_type = "pypi"
  repo_layout_ref = "maven-2-default"
}

resource "artifactory_virtual_repository" "virtual_repository" {
  key = "test-virtual-repo"
  repositories = [ "test-remote-repo", "test-repo" ]
  package_type = "pypi"
}

resource "artifactory_group" "group" {
  name = "test-group"
}

Debug Output

https://gist.github.com/kubiak95/1757694835c8cd2b71544351d4b99861

Expected Behavior

Based on the excerpt from terraform-plan output

# artifactory_group.group will be updated in-place
~ resource "artifactory_group" "group" {
      admin_privileges = false
      auto_join        = false
    - description      = "Group test description" -> null
      id               = "test-group"
      name             = "test-group"
      realm            = "internal"
  }

This test group's description should be removed after running terrafrom-apply

Actual Behavior

Upon running terraform-apply, terraform shows that it's going to remove the description e.g.

- description = "Group test description" -> null

And it confirms the changes afterwards:

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

However running terraform-plan again afterwards reveals that descriptions remain unchanged:

- description = "Group test description" -> null

Steps to Reproduce

  1. Have an Artifactory group or a (local|remote|virutal) repository, state of which you track in Terraform. It also must have a non-empty description or internal note.
  2. In your terraform config for these groups/repositories, remove the description. description = null, description = "" or not having description in the configuration should do it.
  3. run terraform-plan and look at pending changes to the description field, should be a deletion e.g. - description = "Group test description" -> null.
  4. run terraform-apply to confirm.
  5. run terraform-plan again and see that description has not changed.
NootN00t commented 4 years ago

I have noticed similar behaviour with smart NuGet repos and the feed_context_path attribute.

Terraform will detect that it should be set to an empty string (to support the smart repo behavior), sets it on apply. When running plan again it is not persisted and it defaults back to api/v2 which breaks the smart repo behavior.

Setting it manually via the UI persists the setting as a workaround.