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: jamfpro_policy broken? #271

Closed ecanault closed 3 days ago

ecanault commented 1 month ago

Policies are not working at all with me, even with the simpliest configuration as possible. Here is my sample .tf file, as simple as possible:

resource "jamfpro_policy" "test" {
  name    = "p_test_terraform"
  enabled = true
  payloads {
    maintenance {
      recon                       = true
      reset_name                  = false
      install_all_cached_packages = false
      byhost                      = false
      system_cache                = false
      user_cache                  = false
      verify                      = false
    }
  }
  scope {
    all_computers = true
  }
}

Here is the plan:

  # jamfpro_policy.test will be created
  + resource "jamfpro_policy" "test" {
      + enabled                       = true
      + frequency                     = "Once per computer"
      + id                            = (known after apply)
      + name                          = "p_test_terraform"
      + notify_on_each_failed_retry   = false
      + offline                       = false
      + package_distribution_point    = "default"
      + retry_attempts                = -1
      + retry_event                   = "none"
      + target_drive                  = "/"
      + trigger_checkin               = false
      + trigger_enrollment_complete   = false
      + trigger_login                 = false
      + trigger_network_state_changed = false
      + trigger_startup               = false

      + payloads {
          + maintenance {
              + byhost                      = false
              + heal                        = false
              + install_all_cached_packages = false
              + permissions                 = false
              + prebindings                 = false
              + recon                       = true
              + reset_name                  = false
              + system_cache                = false
              + user_cache                  = false
              + verify                      = false
            }
        }

      + scope {
          + all_computers = true
          + all_jss_users = false
        }
    }

When I perform an apply, here is the result:

jamfpro_policy.test: Creating...
╷
│ Error: failed to construct Jamf Pro Policy: invalid combination - all computers with scoped endpoints
│ 
│   with jamfpro_policy.test,
│   on resource_jamfpro_policy.tf line 1, in resource "jamfpro_policy" "test":
│    1: resource "jamfpro_policy" "test" {
│ 
╵

If I change the all_computers in .tf file from true to false: the policy is partially created, without the payload, and I got this error:

jamfpro_policy.test: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with jamfpro_policy.test,
│   on resource_jamfpro_policy.tf line 1, in resource "jamfpro_policy" "test":
│    1: resource "jamfpro_policy" "test" {
│ 
│ 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: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1012bbf90]

goroutine 16 [running]:
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies.prepStatePayloadPackages(...)
    github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies/policies_state.go:398
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies.statePayloads(0x14000147300, 0x1400030ea20, 0x14000050e88)
    github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies/policies_state.go:379 +0x140
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies.updateTerraformState(0x14000147300, 0x1400030ea20, {0x10152eec6, 0x2})
    github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies/policies_state.go:35 +0x1b4
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies.ResourceJamfProPoliciesRead({0x14000147300?, 0x10152eec6?}, 0x14000147300, {0x101740680?, 0x140006b4880?})
    github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies/policies_crud.go:82 +0x210
github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies.ResourceJamfProPoliciesCreate({0x1019a1728, 0x14000156a10}, 0x14000147300, {0x101740680, 0x140006b4880?})
    github.com/deploymenttheory/terraform-provider-jamfpro/internal/endpoints/policies/policies_crud.go:48 +0x2e0
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x140004c3dc0, {0x1019a1680, 0x14000427d10}, 0x14000147300, {0x101740680, 0x140006b4880})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:806 +0xe4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140004c3dc0, {0x1019a1680, 0x14000427d10}, 0x140000ac340, 0x14000147180, {0x101740680, 0x140006b4880})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:937 +0x884
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140003de888, {0x1019a1680?, 0x14000427c50?}, 0x14000141590)
    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(0x1400034e140, {0x1019a1680?, 0x14000427290?}, 0x140001563f0)
    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({0x10194d780, 0x1400034e140}, {0x1019a1680, 0x14000427290}, 0x14000146880, 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(0x1400003d600, {0x1019a1680, 0x14000427200}, {0x1019a7760, 0x140002c4000}, 0x140005aeea0, 0x140004de570, 0x102238638, 0x0)
    google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x1400003d600, {0x1019a7760, 0x140002c4000}, 0x140005aeea0)
    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 13
    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.
danjamf commented 3 weeks ago

Saw same error - from debugging it's dependent on the DistributionPoint state. Possible fix pull request in

danjamf commented 3 weeks ago

It's also worth noting that from what I can see, only packages and scripts are supported today (even with the above fix)

ShocOne commented 3 days ago

policies have been updated as per the other ticket with the changes within main at the time of writing and will part of the next release post v0.1.0. else you can compile it early if you wish to trail functionality earlier. thanks