I’ve written some simple terraform code to assist with creating group membership for active directory groups. This is an on-prem deployment of Active Directory and we are using the hashicorp/ad provider.
Expected Behavior
When apply is run, the code will be checked against the state file and add, change or destroy objects determined, and actioned, accordingly. In addition, if the code matches the state file, it will report as such with no prompt to confirm an action.
Actual Behavior
Each time the apply is run, group membership is changed. When I add a member to the group, all existing members are removed and the new member added. If I make no changes to membership, all members are removed and, if I apply again without change, all members are added.
Has anyone else experienced this behavior?
Can anyone explain this behavior, is something in my code causing this?
terraform {
required_version = ">= 0.14.0"
required_providers {
ad = {
source = "hashicorp/ad"
version = "0.4.4"
}
}
}
provider "ad" {
winrm_hostname = "hostname"
winrm_username = "username"
winrm_password = "password"
}
variable group_memberships {
type = map(object({
user_list = list(string)
group_list = list(string)
computer_list = list(string)
}))
}
group_memberships = {
AppAccessGroup = {
user_list = [
"roger.ramjet",
"wylie.coyote"]
group_list = [
"ReadOnlyUsers",
"TemporaryUsers"]
computer_list = [
"computer01$",
"computer02$"]
}
}
resource ad_group_membership "gm" {
for_each = var.group_memberships
group_id = each.key
group_members = concat(each.value.user_list, each.value.group_list, each.value.computer_list)
}