-
Notifications
You must be signed in to change notification settings - Fork 70
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
ad_group_membership removes group memberships every other run #94
Comments
Hi @Nothing4You, thanks for taking the time to report this issue . This bug has to do with the fact that you're allowed to define any kind of identifier for a group member (GUID, DN, SAM) but we only store its GUID in the state. I will need to think about what's the best way to address this. In the mean time as a workaround you could use the GUIDs of each group member. Resources and datasources for AD objects such as computers, users, and groups return their GUID by calling the For example your initial code could look like this:
|
@koikonom , I'm seeing some strange behavior with this. The |
another method I used to get around this problem is below. I allows you to just feed in a list of usernames, I have thought about wrapping this in a module too. The group membership stay consistent across runs. # Create a variable to hold usernames
variable "users" {
type = list
default = ["user_name_1","user_name_2"]
}
# Get Group id
data "ad_group" "service_group" {
group_id = "CN=TestGroup,OU=TestOU,DC=ad,DC=mydomain,DC=tld"
}
# loop through users and get there data
data "ad_user" "user_data" {
for_each = toset(var.users)
user_id = each.value
}
# create a local that holds all of the id's
locals {
add_users = toset([for k, v in data.ad_user.user_data : v.id])
}
# use that list of ID's to add members to a group
resource "ad_group_membership" "app_group_members" {
group_id = data.ad_group.service_group_app.id
group_members = local.add_users
}
output "user_id" {
value = toset([for k, bd in data.ad_user.user_data : bd.id])
} |
Happy to share it if anybody needs it, but my personal solution was to write a python script that runs just before any Terraform command. It's ugly in nature, but it queries Active Directory over LDAP and downloads a list of users and their GUIDS. I import that back into Terraform as a .json file. |
Curious... why not just use @koikonom's recommendation to push all group members (i.e. users/sub-groups) through a data source to get the GUID and reference that data source in the |
I personnally tested @koikonom's solution and unlike what you said about a strange behavior with the .id , it worked for me. Although in my case I used the data on ad_computer |
Terraform Version and Provider Version
Windows Version
Windows 10 against Windows Server Core 2019
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
Once the group member list has the desired state it should not be modified in subsequent runs.
Actual Behavior
Users are removed from the group every other run.
Steps to Reproduce
This can probably be reproduced with any group member identifier that is accepted by
ad_group_membership
that is not matching theobjectGUID
.As per docs this can be
terraform apply
terraform apply
Community Note
The text was updated successfully, but these errors were encountered: