deploymenttheory / terraform-provider-jamfpro

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

Issue: configuration profiles #273

Closed ecanault closed 1 month ago

ecanault commented 1 month ago

It seems that there is a small bug with site management : when I add the following in my .tf file (obviously site ID 103 exists in my Jamf Pro server):

  site {
    id = 103
  }

Plan seems to be correct:

  # jamfpro_macos_configuration_profile.object["9A74F3FC-059A-4BFF-A611-DB3599EF51A0"] will be updated in-place
  ~ resource "jamfpro_macos_configuration_profile" "object" {
        id                  = "10"
        name                = "cp_disable_softwareupdate"
        # (6 unchanged attributes hidden)

      + site {
          + id = 103
        }

        # (2 unchanged blocks hidden)
    }

But the result of the apply is:

 Error: Plugin did not respond
│ 
│   with jamfpro_macos_configuration_profile.object["9A74F3FC-059A-4BFF-A611-DB3599EF51A0"],
│   on resource_jamfpro_macos_configuration_profile.tf line 1, in resource "jamfpro_macos_configuration_profile" "object":
│    1: resource "jamfpro_macos_configuration_profile" "object" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more
│ details.
╵

Stack trace from the terraform-provider-jamfpro_v0.0.57 plugin:

panic: interface conversion: interface {} is nil, not string

goroutine 82 [running]:
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/common/constructobject.ConstructSharedResourceSite(...)
        github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/common/constructobject/constructobject.go:16
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/macosconfigurationprofiles.constructJamfProMacOSConfigurationProfile(0x140002da280)
        github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/macosconfigurationprofiles/macosconfigurationprofiles_object.go:31 +0x8c0
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/macosconfigurationprofiles.ResourceJamfProMacOSConfigurationProfilesUpdate({0x105fb1728, 0x140006a84d0}, 0x140002da280, {0x105d50680, 0x140006aacd0?})
        github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/macosconfigurationprofiles/macosconfigurationprofiles_resource.go:342 +0x224
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x140004a5880, {0x105fb1680, 0x1400062e030}, 0x140002da280, {0x105d50680, 0x140006aacd0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:840 +0xe4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140004a5880, {0x105fb1680, 0x1400062e030}, 0x14000723930, 0x1400013a500, {0x105d50680, 0x140006aacd0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x670
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140003e2870, {0x105fb1680?, 0x1400031bef0?}, 0x1400015c1e0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xaa4
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140003de0a0, {0x105fb1680?, 0x140006803f0?}, 0x14000630000)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x2b4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x105f5d780, 0x140003de0a0}, {0x105fb1680, 0x140006803f0}, 0x1400071c000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001c7200, {0x105fb1680, 0x14000680360}, {0x105fb7760, 0x140002c8000}, 0x14000694120, 0x140004e4570, 0x106848638, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x140001c7200, {0x105fb7760, 0x140002c8000}, 0x14000694120)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0xb20
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 15
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c

Error: The terraform-provider-jamfpro_v0.0.57 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
ShocOne commented 1 month ago

hi there

try something like this

resource "jamfpro_macos_configuration_profile_plist" "jamfpro_macos_configuration_profile_001" {
  name              = "tf-localtest-contentcaching-plist-source:jamfpro-${var.version_number}"
  description       = "An example mobile device configuration profile."
  level             = "User"
  distribution_method = "Install Automatically" // "Make Available in Self Service", "Install Automatically"
  payloads          = file("${path.module}/support_files/macosconfigurationprofiles/jamf/content-caching.mobileconfig")
  user_removable    = false

  site {
    id = 1170
  }

  scope {
    all_computers = true
    all_jss_users      = true

  }
}

and let me know how you get on. i can successfully deploy with site enablement for the config profile with this

ecanault commented 1 month ago

Same result with this pretty close resource:

resource "jamfpro_macos_configuration_profile_plist" "jamfpro_macos_configuration_profile_001" {
  name                = "tf-localtest-contentcaching-plist-source:jamfpro-1"
  description         = "An example mobile device configuration profile."
  level               = "User"
  distribution_method = "Install Automatically" // "Make Available in Self Service", "Install Automatically"
  payloads            = file("./cp_disable_softwareupdate.mobileconfig")
  user_removable      = false

  site {
    id = 103
  }

  scope {
    all_computers = true
    all_jss_users = true

  }
}

Don't know if it helps, but here is also the relevant part of my main.tf:

terraform {
  required_providers {
    jamfpro = {
      source  = "deploymenttheory/jamfpro"
      version = "~> 0.0.57"
    }
}

provider "jamfpro" {
  instance_name                = var.JAMFPRO_INSTANCE_NAME
  username                     = var.JAMFPRO_USERNAME
  password                     = var.JAMFPRO_PASSWORD
  log_level                    = "none"
  log_output_format            = "console"
  log_console_separator        = " "
  hide_sensitive_data          = true
  max_retry_attempts           = 5
  enable_dynamic_rate_limiting = false
  max_concurrent_requests      = 5
  token_refresh_buffer_period  = 10
  total_retry_duration         = 30
  custom_timeout               = 30
  enable_cookie_jar            = true
  custom_cookies = {
    "jpro-ingress" = "1a5d50ff09889f0e"
  }
}

And the content of the .mobileconfig file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>PayloadContent</key>
        <array>
            <dict>
                <key>AllowPreReleaseInstallation</key>
                <false/>
                <key>AutomaticCheckEnabled</key>
                <false/>
                <key>AutomaticDownload</key>
                <false/>
                <key>AutomaticallyInstallAppUpdates</key>
                <false/>
                <key>AutomaticallyInstallMacOSUpdates</key>
                <false/>
                <key>CatalogURL</key>
                <string/>
                <key>ConfigDataInstall</key>
                <false/>
                <key>CriticalUpdateInstall</key>
                <false/>
                <key>PayloadDescription</key>
                <string/>
                <key>PayloadDisplayName</key>
                <string>Software Update</string>
                <key>PayloadEnabled</key>
                <true/>
                <key>PayloadIdentifier</key>
                <string>C69D345E-DAE2-4C71-B787-8E01430DFEEB</string>
                <key>PayloadOrganization</key>
                <string>Netopie</string>
                <key>PayloadType</key>
                <string>com.apple.SoftwareUpdate</string>
                <key>PayloadUUID</key>
                <string>C69D345E-DAE2-4C71-B787-8E01430DFEEB</string>
                <key>PayloadVersion</key>
                <integer>1</integer>
                <key>restrict-software-update-require-admin-to-install</key>
                <false/>
            </dict>
        </array>
        <key>PayloadDescription</key>
        <string/>
        <key>PayloadDisplayName</key>
        <string>cp_test_terraform</string>
        <key>PayloadEnabled</key>
        <true/>
        <key>PayloadIdentifier</key>
        <string>5ACE1F26-6A50-43A3-AA62-D585FE910227</string>
        <key>PayloadOrganization</key>
        <string>NETOPIE</string>
        <key>PayloadRemovalDisallowed</key>
        <true/>
        <key>PayloadScope</key>
        <string>User</string>
        <key>PayloadType</key>
        <string>Configuration</string>
        <key>PayloadUUID</key>
        <string>5ACE1F26-6A50-43A3-AA62-D585FE910227</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
    </dict>
</plist>
ShocOne commented 1 month ago

this worked for me using your payload

resource "jamfpro_macos_configuration_profile_plist" "jamfpro_macos_configuration_profile_002" {
  name                = "tf-localtest-cp_test_terraform-plist-source:jamfpro"
  description         = "An example mobile device configuration profile."
  level               = "User"
  distribution_method = "Install Automatically" // "Make Available in Self Service", "Install Automatically"
  payloads          = file("${path.module}/support_files/macosconfigurationprofiles/jamf/cp_test_terraform.mobileconfig")
  user_removable      = false

  site {
    id = 1170
  }

  scope {
    all_computers = true
    all_jss_users = true

  }
}

image

incidentally, the payload doesn't appear to be gui directly but i can update the plist in the .mobileconfig and that triggers state updates. struggling here to recreate your issue

ecanault commented 1 month ago

OK now in 0.0.58 with your example.

I still have issues with my own contents, but it's certainely on my side inside the code of my .tf file.

Thanks!