deploymenttheory / terraform-provider-jamfpro

Jamf Pro Terraform Provider/Plugin written with the TF Provider SDK v2. Written in go
Mozilla Public License 2.0
26 stars 9 forks source link

Importing Smart Computer Groups adds computer in smart group into state #145

Closed smithjw closed 5 months ago

smithjw commented 5 months ago

Interesting issues here. If I import a smart group into my state, that import will also end up including the computers {} block of every device that is currently in that Smart Group leading to errors when trying to plan/apply changes.

  1. Create simple group resource group.tf

    resource "jamfpro_computer_group" "device_compliance_applicable_devices" {
    name     = "Device Compliance Status - Applicable Devices"
    is_smart = true
    computers {}
    criteria {
    name        = "Model"
    priority    = 1
    search_type = "like"
    value       = "Mac"
    }
    }
  2. import existing group into state terraform import jamfpro_computer_group.device_compliance_applicable_devices GROUP_ID

  3. Run plan with targeting terraform plan -target=jamfpro_computer_group.device_compliance_applicable_devices

Error: 'computers' field is not allowed when 'is_smart' is true
│ 
│   with jamfpro_computer_group.device_compliance_applicable_devices,
│   on computer_groups-device_compliance.tf line 1, in resource "jamfpro_computer_group" "device_compliance_applicable_devices":
│    1: resource "jamfpro_computer_group" "device_compliance_applicable_devices" {
  1. Inspecting state shows the following terraform state show jamfpro_computer_group.device_compliance_applicable_devices
# jamfpro_computer_group.device_compliance_applicable_devices:
resource "jamfpro_computer_group" "device_compliance_applicable_devices" {
    id       = "16"
    is_smart = true
    name     = "Device Compliance Status - Applicable Devices"

    computers {
        alt_mac_address = "*******"
        id              = 2
        mac_address     = "*******"
        name            = "Admin’s Virtual Machine"
        serial_number   = "*******"
    }

    criteria {
        and_or        = "and"
        closing_paren = false
        name          = "Model"
        opening_paren = false
        priority      = 0
        search_type   = "like"
        value         = "Mac"
    }

    site {
        id   = -1
        name = "None"
    }
}
ShocOne commented 5 months ago

Merged PR #146 from yourself with the fix