-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from deploymenttheory/update-app-catalog-app-…
…installer-titles removed managed software updates from provider
- Loading branch information
Showing
8 changed files
with
238 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,80 @@ | ||
package managedsoftwareupdates | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// construct constructs a ResourceManagedSoftwareUpdatePlan object from the provided schema data. | ||
// construct builds a ResourceManagedSoftwareUpdatePlan object from the provided schema data. | ||
func construct(d *schema.ResourceData) (*jamfpro.ResourceManagedSoftwareUpdatePlan, error) { | ||
resource := &jamfpro.ResourceManagedSoftwareUpdatePlan{ | ||
Config: jamfpro.ResourcManagedSoftwareUpdatePlanConfig{ | ||
UpdateAction: d.Get("config.0.update_action").(string), | ||
VersionType: d.Get("config.0.version_type").(string), | ||
SpecificVersion: d.Get("config.0.specific_version").(string), | ||
MaxDeferrals: d.Get("config.0.max_deferrals").(int), | ||
ForceInstallLocalDateTime: d.Get("config.0.force_install_local_date_time").(string), | ||
}, | ||
Config: jamfpro.ResourcManagedSoftwareUpdatePlanConfig{}, | ||
} | ||
|
||
// Handle group | ||
if v, ok := d.GetOk("group"); ok { | ||
groups := v.([]interface{}) | ||
if len(groups) > 0 { | ||
group := groups[0].(map[string]interface{}) | ||
groupList := v.([]interface{}) | ||
if len(groupList) > 0 { | ||
group := groupList[0].(map[string]interface{}) | ||
resource.Group = jamfpro.ResourcManagedSoftwareUpdatePlanObject{ | ||
GroupId: group["group_id"].(string), | ||
ObjectType: group["object_type"].(string), | ||
} | ||
} | ||
} | ||
|
||
// Optional: Add build_version if it's set | ||
if v, ok := d.GetOk("config.0.build_version"); ok { | ||
// Handle device | ||
if v, ok := d.GetOk("device"); ok { | ||
deviceList := v.([]interface{}) | ||
if len(deviceList) > 0 { | ||
device := deviceList[0].(map[string]interface{}) | ||
resource.Devices = []jamfpro.ResourcManagedSoftwareUpdatePlanObject{ | ||
{ | ||
DeviceId: device["device_id"].(string), | ||
ObjectType: device["object_type"].(string), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
// Now handle the fields that were previously inside the config block | ||
resource.Config.UpdateAction = d.Get("update_action").(string) | ||
resource.Config.VersionType = d.Get("version_type").(string) | ||
|
||
if v, ok := d.GetOk("specific_version"); ok { | ||
resource.Config.SpecificVersion = v.(string) | ||
} else { | ||
resource.Config.SpecificVersion = "NO_SPECIFIC_VERSION" | ||
} | ||
|
||
if v, ok := d.GetOk("build_version"); ok { | ||
resource.Config.BuildVersion = v.(string) | ||
} else { | ||
resource.Config.BuildVersion = "" | ||
} | ||
|
||
// Validate that specific_version is set when required | ||
if resource.Config.VersionType == "SPECIFIC_VERSION" || resource.Config.VersionType == "CUSTOM_VERSION" { | ||
if resource.Config.SpecificVersion == "" { | ||
return nil, fmt.Errorf("specific_version is required when version_type is SPECIFIC_VERSION or CUSTOM_VERSION") | ||
} | ||
if v, ok := d.GetOk("max_deferrals"); ok { | ||
resource.Config.MaxDeferrals = v.(int) | ||
} else { | ||
resource.Config.MaxDeferrals = 0 | ||
} | ||
|
||
// Validate that max_deferrals is set when required | ||
if resource.Config.UpdateAction == "DOWNLOAD_INSTALL_ALLOW_DEFERRAL" && resource.Config.MaxDeferrals == 0 { | ||
return nil, fmt.Errorf("max_deferrals is required when update_action is DOWNLOAD_INSTALL_ALLOW_DEFERRAL") | ||
if v, ok := d.GetOk("force_install_local_date_time"); ok { | ||
resource.Config.ForceInstallLocalDateTime = v.(string) | ||
} else { | ||
resource.Config.ForceInstallLocalDateTime = "" | ||
} | ||
|
||
log.Printf("[DEBUG] Constructed Jamf Pro Managed Software Update Plan: %+v\n", resource) | ||
// Debug logging for config specifically | ||
configJSON, err := json.MarshalIndent(resource.Config, "", " ") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal Jamf Pro managed software update config to JSON: %v", err) | ||
} | ||
log.Printf("[DEBUG] Constructed Jamf Pro managed software update config JSON:\n%s\n", string(configJSON)) | ||
|
||
return resource, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
internal/resources/managedsoftwareupdates/data_validator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package managedsoftwareupdates | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// mainCustomDiffFunc orchestrates all custom diff validations. | ||
func mainCustomDiffFunc(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error { | ||
if err := validateGroupOrDevice(ctx, diff, i); err != nil { | ||
return err | ||
} | ||
|
||
if err := validateConfigFields(ctx, diff, i); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// validateGroupOrDevice ensures that either 'group' or 'device' is specified, but not both. | ||
func validateGroupOrDevice(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error { | ||
resourceName := diff.Get("name").(string) | ||
_, hasGroup := diff.GetOk("group") | ||
_, hasDevice := diff.GetOk("device") | ||
|
||
if hasGroup && hasDevice { | ||
return fmt.Errorf("in 'jamfpro_managed_software_update.%s': only one of 'group' or 'device' can be specified, not both", resourceName) | ||
} | ||
|
||
if !hasGroup && !hasDevice { | ||
return fmt.Errorf("in 'jamfpro_managed_software_update.%s': either 'group' or 'device' must be specified", resourceName) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// validateConfigFields performs validation on the 'config' block fields. | ||
func validateConfigFields(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error { | ||
resourceName := diff.Get("name").(string) | ||
config := diff.Get("config").([]interface{}) | ||
|
||
if len(config) == 0 { | ||
return fmt.Errorf("in 'jamfpro_managed_software_update.%s': 'config' block is required", resourceName) | ||
} | ||
|
||
configMap := config[0].(map[string]interface{}) | ||
updateAction := configMap["update_action"].(string) | ||
versionType := configMap["version_type"].(string) | ||
specificVersion := configMap["specific_version"].(string) | ||
maxDeferrals := configMap["max_deferrals"].(int) | ||
|
||
if updateAction == "DOWNLOAD_INSTALL_ALLOW_DEFERRAL" && maxDeferrals == 0 { | ||
return fmt.Errorf("in 'jamfpro_managed_software_update.%s': 'max_deferrals' must be set when 'update_action' is 'DOWNLOAD_INSTALL_ALLOW_DEFERRAL'", resourceName) | ||
} | ||
|
||
if (versionType == "SPECIFIC_VERSION" || versionType == "CUSTOM_VERSION") && specificVersion == "" { | ||
return fmt.Errorf("in 'jamfpro_managed_software_update.%s': 'specific_version' must be set when 'version_type' is 'SPECIFIC_VERSION' or 'CUSTOM_VERSION'", resourceName) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.