drakkan / terraform-provider-sftpgo

Terraform provider for SFTPGo
Apache License 2.0
25 stars 7 forks source link

Creation of a group with a list of virtual folders provides error: Provider produced inconsistent result after apply #12

Open bankinobi opened 4 months ago

bankinobi commented 4 months ago

Hi!

When i'm trying to create group with multiple virtual folders inside i got an error:

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to sftpgo_group.group["MyGroup"], provider "provider[\"registry.terraform.io/drakkan/sftpgo\"]" produced an unexpected new value: .virtual_folders[0].virtual_path: was cty.StringVal("/MyGroup"), but now
│ cty.StringVal("/MyGroup-new").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to sftpgo_group.group["MyGroup"], provider "provider[\"registry.terraform.io/drakkan/sftpgo\"]" produced an unexpected new value: .virtual_folders[0].name: was cty.StringVal("MyGroup"), but now cty.StringVal("MyGroup-new").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to sftpgo_group.group["MyGroup"], provider "provider[\"registry.terraform.io/drakkan/sftpgo\"]" produced an unexpected new value: .virtual_folders[1].name: was cty.StringVal("MyGroup-new"), but now cty.StringVal("MyGroup").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to sftpgo_group.group["MyGroup"], provider "provider[\"registry.terraform.io/drakkan/sftpgo\"]" produced an unexpected new value: .virtual_folders[1].virtual_path: was cty.StringVal("/MyGroup-new"), but now
│ cty.StringVal("/MyGroup").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Provider version: 0.0.12

My resource:

resource "sftpgo_group" "group" {
  for_each        = { for group in local.groups : group.name => group }
  name            = each.value.name
  virtual_folders = each.value.virtual_folder
  depends_on      = [sftpgo_folder.folder]
}

Locals:

  groups = [for group in var.groups : {
    name = group.name
    virtual_folder = [for group_folder in group.virtual_folders : {
      name         = group_folder.name
      virtual_path = group_folder.virtual_path
      quota_files  = -1
      quota_size   = -1
    }]
  }]

State entry after apply

terraform state show 'sftpgo_group.group["MyGroup"]'                            
# sftpgo_group.group["MyGroup"]: (tainted)
resource "sftpgo_group" "group" {
    created_at      = 1720940997721
    id              = "MyGroup"
    name            = "MyGroup"
    updated_at      = 1720940997721
    user_settings   = {
        filesystem = {
            provider = 0
        }
        filters    = {}
    }
    virtual_folders = [
        {
            filesystem        = {
                osconfig = {
                    read_buffer_size  = 10
                    write_buffer_size = 10
                }
                provider = 0
            }
            last_quota_update = 0
            mapped_path       = "/srv/sftpgo/data/folder-1/MyGroup-new"
            name              = "MyGroup-new"
            quota_files       = -1
            quota_size        = -1
            used_quota_files  = 0
            used_quota_size   = 0
            virtual_path      = "/MyGroup-new"
        },
        {
            filesystem        = {
                osconfig = {
                    read_buffer_size  = 10
                    write_buffer_size = 10
                }
                provider = 0
            }
            last_quota_update = 0
            mapped_path       = "/srv/sftpgo/data/folder-2/MyGroup"
            name              = "MyGroup"
            quota_files       = -1
            quota_size        = -1
            used_quota_files  = 0
            used_quota_size   = 0
            virtual_path      = "/MyGroup"
        },
    ]
}
bankinobi commented 4 months ago

Got the same behaviour on previous 0.0.11 provider version Works as expected when there is only one virtual folder in a group

bankinobi commented 4 months ago

Also, if you'll try to change the order and types of groups for existing user state, it will produce the same error

Error: Provider produced inconsistent result after apply
...
yroffin commented 2 months ago

hi,

it could be a sort problem, i've an issue like this on groups with sftpgo_user if update my groups to be alpha sorted ... and it seem to correct the problem

i assume during plan list is not sorted by name, and when apply output is sorted

i hope it can help :)

Error: Provider produced inconsistent result after apply

with list ["svc_accounts","ocean-rw"]

When applying changes to sftpgo_user.talend_service_account[0], provider
"provider[\"registry.terraform.io/drakkan/sftpgo\"]" produced an unexpected
new value: .groups[0].name: was cty.StringVal("svc_accounts"), but now
cty.StringVal("ocean-rw").

with list ["ocean-rw", "svc_accounts"] no apply problem