hashicorp / terraform-provider-ad

Active Directory provider for HashiCorp Terraform (experimental)
https://registry.terraform.io/providers/hashicorp/ad/latest
Mozilla Public License 2.0
138 stars 72 forks source link

ad_group_membership removes all members of a group when destroying resource #176

Open v-esteves opened 1 year ago

v-esteves commented 1 year ago

Terraform Version and Provider Version

Terraform v1.3.8 on windows_386

Windows Version

Windows Server 2022 Datacenter Azure Edition

Affected Resource(s)

ad_group_membership

Terraform Configuration Files

terraform {
  required_providers {
    ad = {
      source = "hashicorp/ad"
      version = "0.4.4"
    }
    azurerm = {
      source = "hashicorp/azurerm"
      version = ">= 3.25.0"
    }
  }
}

provider "ad" {
  winrm_hostname = ""
  winrm_username = ""
  winrm_password = ""
}

provider azurerm {
  features {}
}

variable "groups"  {
    type = list(object({
        group = string
  }))
}

data "ad_group" "ad_group" {
    count = length(var.groups)
    group_id = var.groups[count.index].group
}

resource "ad_group_membership" "ad_group_member" {
    for_each = {for i, v in data.ad_group.ad_group:  i => v}
    group_id = each.value.id
    group_members = [ "4dec9478-2511-4640-8102-3a456a404643" ]
}

Expected Behavior

Terraform apply executes correctly and the user is added to an existing list of groups. Terraform destroy removes the user from the groups.

Actual Behavior

Terraform destroy removes ALL users from the groups, not only the added user.

Steps to Reproduce

  1. 'terraform apply -destroy'

Community Note

bryanfarmer commented 10 months ago

Any movement on this issue? We have many shared groups that servers are added to for SCCM, Certificate auto-enrollment, etc. Removing all members would be extremely impacting.