deploymenttheory / terraform-provider-jamfpro

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

Issue: category not set in jamfpro_script resource #201

Closed ecanault closed 1 month ago

ecanault commented 2 months ago

Hi,

When creating a new script, here is the result of terraform plan:

  # jamfpro_script.object["AFA7A12B-A770-44C7-9FF2-9E026C7DE79E"] will be created
  + resource "jamfpro_script" "object" {
      + category_id     = (known after apply)
      + category_name   = "Configuration"
      + id              = (known after apply)
      + name            = "s_run_0touch_reset.sh"
      + notes           = "https://github.com/jamf/DEPNotify-Starter/blob/master/depNotifyReset.sh"
      + priority        = "AFTER"
      + script_contents = <<-EOT
[...]
        EOT
    }

After terraform apply, if I launch another terraform plan without any changes:

   # jamfpro_script.object["AFA7A12B-A770-44C7-9FF2-9E026C7DE79E"] will be updated in-place
  ~ resource "jamfpro_script" "object" {
      ~ category_name   = "NONE" -> "Configuration"
        id              = "8"
        name            = "s_run_0touch_reset.sh"
        # (4 unchanged attributes hidden)
    }

And when I have a look in the terraform console:

> jamfpro_script.object["AFA7A12B-A770-44C7-9FF2-9E026C7DE79E"]
{
  "category_id" = "-1"
  "category_name" = "NONE"
  "id" = "8"
  "info" = ""
  "name" = "s_run_0touch_reset.sh"
  "notes" = "https://github.com/jamf/DEPNotify-Starter/blob/master/depNotifyReset.sh"
  "os_requirements" = ""
  "parameter10" = ""
  "parameter11" = ""
  "parameter4" = ""
  "parameter5" = ""
  "parameter6" = ""
  "parameter7" = ""
  "parameter8" = ""
  "parameter9" = ""
  "priority" = "AFTER"
  "script_contents" = <<-EOT
[...]
  EOT
  "timeouts" = null /* object */
}

Regards, Emmanuel

ShocOne commented 2 months ago

Fixed as part of PR #202 . Fields were previously required and have been made optional. Default values are sent if these fields are not populated by the hcl. Additionally added logic to the stating of scripts so that we only state the categroy_id and category_name if they are not defaults, else ignore.

ecanault commented 2 months ago

Thanks for the update, but it seems there's still an issue.

It's OK on the Terraform side:

> jamfpro_script.object["AFA7A12B-A770-44C7-9FF2-9E026C7DE79E"]
{
  "category_id" = tostring(null)
  "category_name" = "Configuration"
  "id" = "21"
  "info" = ""
  "name" = "s_run_0touch_reset.sh"
  "notes" = "https://github.com/jamf/DEPNotify-Starter/blob/master/depNotifyReset.sh"
  "os_requirements" = ""
  "parameter10" = ""
  "parameter11" = ""
  "parameter4" = ""
  "parameter5" = ""
  "parameter6" = ""
  "parameter7" = ""
  "parameter8" = ""
  "parameter9" = ""
  "priority" = "AFTER"
  "script_contents" = <<-EOT
  [...]
  EOT
  "timeouts" = null /* object */
}

And there is no update of the object in a terraform plan.

But categories are not set in Jamf Pro. Below are the views from the GUI and from the API perspectives:

Scripts__
<?xml version="1.0" encoding="UTF-8"?>
  <script>
    <id>21</id>
    <name>s_run_0touch_reset.sh</name>
    <category>No category assigned</category>
    <filename>s_run_0touch_reset.sh</filename>
    <info/>
    <notes>https://github.com/jamf/DEPNotify-Starter/blob/master/depNotifyReset.sh</notes>
    <priority>After</priority>
    <parameters/>
    <os_requirements/>
    <script_contents>
    [...]
    </script_contents>
    <script_contents_encoded>[...]</script_contents_encoded>
  </script>

Regards, Emmanuel

ecanault commented 2 months ago

Up

thejoeker12 commented 1 month ago

@ShocOne

ShocOne commented 1 month ago

hi there ,

in my hcl example

resource "jamfpro_script" "jamfpro_script_001" {
  name            = "tf-localtest-add-or-remove-group-membership-v4.0"
  script_contents = file("${path.module}/support_files/scripts/Add or Remove Group Membership.zsh")
  category_id   = "5"
  os_requirements = "13"
  priority        = "BEFORE"
  info            = "Adds target user or group to specified group membership, or removes said membership."
  notes           = "Jamf Pro script parameters: 4 -> 7"
  parameter4      = "100"           // targetID
  parameter5      = "group"         // Target Type - Must be either "user" or "group"
  parameter6      = "someGroupName" // targetMembership
  parameter7      = "add"           // Script Action - Must be either "add" or "remove"
}

the category assigns just fine

image

and i don't get any false positives for terraform plans

in your example remove the category_name field as it is computed and see if that resolves your issue

ecanault commented 1 month ago

Hi,

Yes! 🙂

It works using category_id instead of category_name.

Thanks a lot, this one can be closed too!