diff --git a/internal/provider/resources.go b/internal/provider/resources.go index c5d52075..7bb92b38 100644 --- a/internal/provider/resources.go +++ b/internal/provider/resources.go @@ -10,7 +10,7 @@ import ( graphBetaDeviceAndAppManagementM365AppsInstallationOptions "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/m365_apps_installation_options" graphBetaDeviceAndAppManagementMobileAppAssignment "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/mobile_app_assignment" graphBetaDeviceAndAppManagementRoleDefinition "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/role_definition" - graphBetaDeviceAndAppManagementSettingsCatalogV3 "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/settings_catalog_v3" + graphBetaDeviceAndAppManagementSettingsCatalog "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/settings_catalog_v3" graphBetaDeviceAndAppManagementWinGetApp "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/beta/winget_app" graphDeviceAndAppManagementCloudPcDeviceImage "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image" graphDeviceAndAppManagementCloudPcProvisioningPolicy "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy" @@ -40,7 +40,7 @@ func (p *M365Provider) Resources(ctx context.Context) []func() resource.Resource graphBetaDeviceAndAppManagementDeviceManagementScript.NewDeviceManagementScriptResource, graphBetaDeviceAndAppManagementM365AppsInstallationOptions.NewM365AppsInstallationOptionsResource, graphBetaDeviceAndAppManagementMobileAppAssignment.NewMobileAppAssignmentResource, - graphBetaDeviceAndAppManagementSettingsCatalogV3.NewSettingsCatalogResource, + graphBetaDeviceAndAppManagementSettingsCatalog.NewSettingsCatalogResource, graphBetaDeviceAndAppManagementRoleDefinition.NewRoleDefinitionResource, graphBetaDeviceAndAppManagementWinGetApp.NewWinGetAppResource, graphBetaIdentityAndAccessConditionalAccessPolicy.NewConditionalAccessPolicyResource, diff --git a/internal/resources/_resource_template/construct.go b/internal/resources/_resource_template/construct.go new file mode 100644 index 00000000..6bc29f0d --- /dev/null +++ b/internal/resources/_resource_template/construct.go @@ -0,0 +1,33 @@ +package graphBetaAssignmentFilter + +import ( + "context" + "fmt" + + "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" + "github.com/hashicorp/terraform-plugin-log/tflog" + + "github.com/microsoftgraph/msgraph-beta-sdk-go/models" +) + +// constructResource maps the Terraform schema to the SDK model +func constructResource(ctx context.Context, typeName string, data *AssignmentFilterResourceModel) (*models.DeviceAndAppManagementAssignmentFilter, error) { + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) + + requestBody := models.NewDeviceAndAppManagementAssignmentFilter() + + displayName := data.DisplayName.ValueString() + requestBody.SetDisplayName(&displayName) + + // add more fields here as needed + + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { + tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ + "error": err.Error(), + }) + } + + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + + return requestBody, nil +} diff --git a/internal/resources/_resource_template/crud.go b/internal/resources/_resource_template/crud.go new file mode 100644 index 00000000..3624a471 --- /dev/null +++ b/internal/resources/_resource_template/crud.go @@ -0,0 +1,179 @@ +package graphVersionResourceTemplate + +import ( + "context" + "fmt" + "time" + + "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/crud" + "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/errors" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Create handles the Create operation. +func (r *ResourceTemplateResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan ResourceTemplateResourceModel + + tflog.Debug(ctx, fmt.Sprintf("Starting creation of resource: %s_%s", r.ProviderTypeName, r.TypeName)) + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + ctx, cancel := crud.HandleTimeout(ctx, plan.Timeouts.Create, 30*time.Second, &resp.Diagnostics) + if cancel == nil { + return + } + defer cancel() + + requestBody, err := constructResource(ctx, r.TypeName, &plan) + if err != nil { + resp.Diagnostics.AddError( + "Error constructing resource", + fmt.Sprintf("Could not construct resource: %s_%s: %s", r.ProviderTypeName, r.TypeName, err.Error()), + ) + return + } + + resource, err := r.client. + DeviceManagement(). + ResourceTemplates(). + Post(ctx, requestBody, nil) + + if err != nil { + errors.HandleGraphError(ctx, err, resp, "Create", r.WritePermissions) + return + } + + plan.ID = types.StringValue(*resource.GetId()) + + MapRemoteStateToTerraform(ctx, &plan, resource) + + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Finished Create Method: %s_%s", r.ProviderTypeName, r.TypeName)) +} + +// Read handles the Read operation. +func (r *ResourceTemplateResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ResourceTemplateResourceModel + tflog.Debug(ctx, fmt.Sprintf("Starting Read method for: %s_%s", r.ProviderTypeName, r.TypeName)) + + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Reading %s_%s with ID: %s", r.ProviderTypeName, r.TypeName, state.ID.ValueString())) + + ctx, cancel := crud.HandleTimeout(ctx, state.Timeouts.Read, 30*time.Second, &resp.Diagnostics) + if cancel == nil { + return + } + defer cancel() + + resource, err := r.client. + DeviceManagement(). + ResourceTemplates(). + ByDeviceAndAppManagementResourceTemplateId(state.ID.ValueString()). + Get(ctx, nil) + + if err != nil { + errors.HandleGraphError(ctx, err, resp, "Read", r.ReadPermissions) + return + } + + MapRemoteStateToTerraform(ctx, &state, resource) + + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Finished Read Method: %s_%s", r.ProviderTypeName, r.TypeName)) +} + +// Update handles the Update operation. +func (r *ResourceTemplateResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan ResourceTemplateResourceModel + + tflog.Debug(ctx, fmt.Sprintf("Starting Update of resource: %s_%s", r.ProviderTypeName, r.TypeName)) + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + ctx, cancel := crud.HandleTimeout(ctx, plan.Timeouts.Update, 30*time.Second, &resp.Diagnostics) + if cancel == nil { + return + } + defer cancel() + + requestBody, err := constructResource(ctx, r.TypeName, &plan) + if err != nil { + resp.Diagnostics.AddError( + "Error constructing resource for update method", + fmt.Sprintf("Could not construct resource: %s_%s: %s", r.ProviderTypeName, r.TypeName, err.Error()), + ) + return + } + + _, err = r.client. + DeviceManagement(). + ResourceTemplates(). + ByDeviceAndAppManagementResourceTemplateId(plan.ID.ValueString()). + Patch(ctx, requestBody, nil) + + if err != nil { + errors.HandleGraphError(ctx, err, resp, "Update", r.ReadPermissions) + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Finished Update Method: %s_%s", r.ProviderTypeName, r.TypeName)) +} + +// Delete handles the Delete operation. +func (r *ResourceTemplateResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var data ResourceTemplateResourceModel + + tflog.Debug(ctx, fmt.Sprintf("Starting deletion of resource: %s_%s", r.ProviderTypeName, r.TypeName)) + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + ctx, cancel := crud.HandleTimeout(ctx, data.Timeouts.Delete, 30*time.Second, &resp.Diagnostics) + if cancel == nil { + return + } + defer cancel() + + err := r.client. + DeviceManagement(). + ResourceTemplates(). + ByDeviceAndAppManagementResourceTemplateId(data.ID.ValueString()). + Delete(ctx, nil) + + if err != nil { + errors.HandleGraphError(ctx, err, resp, "Delete", r.ReadPermissions) + return + } + + resp.State.RemoveResource(ctx) + + tflog.Debug(ctx, fmt.Sprintf("Finished Delete Method: %s_%s", r.ProviderTypeName, r.TypeName)) +} diff --git a/internal/resources/_resource_template/model.go b/internal/resources/_resource_template/model.go new file mode 100644 index 00000000..5b6771b0 --- /dev/null +++ b/internal/resources/_resource_template/model.go @@ -0,0 +1,13 @@ +// REF: include the graph api docs link for the resource type here +package graphVersionResourceTemplate + +import ( + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type ResourceTemplateResourceModel struct { + ID types.String `tfsdk:"id"` + etc types.String `tfsdk:"etc"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} diff --git a/internal/resources/_resource_template/modify_plan.go b/internal/resources/_resource_template/modify_plan.go new file mode 100644 index 00000000..65bb73a2 --- /dev/null +++ b/internal/resources/_resource_template/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaWinGetApp + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *ResourceTemplateResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/_resource_template/resource.go b/internal/resources/_resource_template/resource.go new file mode 100644 index 00000000..25001b6a --- /dev/null +++ b/internal/resources/_resource_template/resource.go @@ -0,0 +1,82 @@ +package graphVersionResourceTemplate + +import ( + "context" + + "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common" + commonschema "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/schema" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" +) + +const ( + ResourceName = "graph_apitype_resource_type_resource_name" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &ResourceTemplateResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &ResourceTemplateResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &ResourceTemplateResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &ResourceTemplateResource{} +) + +func NewResourceTemplateResource() resource.Resource { + return &ResourceTemplateResource{ + ReadPermissions: []string{ + "DeviceManagementConfiguration.Read.All", + }, + WritePermissions: []string{ + "DeviceManagementConfiguration.ReadWrite.All", + }, + } +} + +type ResourceTemplateResource struct { + client *msgraphbetasdk.GraphServiceClient + ProviderTypeName string + TypeName string + ReadPermissions []string + WritePermissions []string +} + +// Metadata returns the resource type name. +func (r *ResourceTemplateResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_" + ResourceName +} + +// Configure sets the client for the resource. +func (r *ResourceTemplateResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + r.client = common.SetGraphBetaClientForResource(ctx, req, resp, r.TypeName) +} + +// ImportState imports the resource state. +func (r *ResourceTemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// Function to create the full device management win32 lob app schema +func (r *ResourceTemplateResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "The resource `resource_name` manages a graph api resource of type `resource_name`", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "Unique Identifier for the resource.", + Computed: true, + }, + "etc": schema.StringAttribute{ + Description: "Add schema from here.", + Computed: true, + }, + "timeouts": commonschema.Timeouts(ctx), + }, + } +} diff --git a/internal/resources/_resource_template/state.go b/internal/resources/_resource_template/state.go new file mode 100644 index 00000000..d78b7fa3 --- /dev/null +++ b/internal/resources/_resource_template/state.go @@ -0,0 +1,28 @@ +package graphVersionResourceTemplate + +import ( + "context" + + "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/state" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models" +) + +func MapRemoteStateToTerraform(ctx context.Context, data *ResourceTemplateResourceModel, remoteResource graphmodels.DeviceAndAppManagementAssignmentFilterable) { + if remoteResource == nil { + tflog.Debug(ctx, "Remote resource is nil") + return + } + + tflog.Debug(ctx, "Starting to map remote state to Terraform state", map[string]interface{}{ + "resourceId": state.StringPtrToString(remoteResource.GetId()), + }) + + data.ID = types.StringValue(state.StringPtrToString(remoteResource.GetId())) + // add more fields here as needed + + tflog.Debug(ctx, "Finished mapping remote state to Terraform state", map[string]interface{}{ + "resourceId": data.ID.ValueString(), + }) +} diff --git a/internal/resources/common/validators/settings_cataloge.go b/internal/resources/common/validators/settings_cataloge.go deleted file mode 100644 index ad310802..00000000 --- a/internal/resources/common/validators/settings_cataloge.go +++ /dev/null @@ -1,77 +0,0 @@ -package validators - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/schema/validator" -) - -// settingsCatalogValidator validates settings catalog json structure -type settingsCatalogValidator struct{} - -// SettingsCatalogValidator returns a validator which ensures settings catalog json is valid -func SettingsCatalogValidator() validator.String { - return &settingsCatalogValidator{} -} - -// Description describes the validation in plain text formatting. -func (v settingsCatalogValidator) Description(_ context.Context) string { - return "validates settings catalog configuration" -} - -// MarkdownDescription describes the validation in Markdown formatting. -func (v settingsCatalogValidator) MarkdownDescription(ctx context.Context) string { - return v.Description(ctx) -} - -// Validate performs the validation. -func (v settingsCatalogValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { - if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { - return - } - - // Parse JSON - var settingsData struct { - SettingsDetails []struct { - SettingInstance struct { - ODataType string `json:"@odata.type"` - SimpleSettingValue *struct { - ODataType string `json:"@odata.type"` - ValueState string `json:"valueState,omitempty"` - Value string `json:"value"` - } `json:"simpleSettingValue,omitempty"` - } `json:"settingInstance"` - } `json:"settingsDetails"` - } - - if err := json.Unmarshal([]byte(req.ConfigValue.ValueString()), &settingsData); err != nil { - resp.Diagnostics.AddAttributeError( - req.Path, - "Invalid Settings Catalog JSON", - fmt.Sprintf("Error parsing settings catalog JSON: %s", err), - ) - return - } - - // Validate each setting - for i, setting := range settingsData.SettingsDetails { - // Check for secret settings - if setting.SettingInstance.SimpleSettingValue != nil && - setting.SettingInstance.SimpleSettingValue.ODataType == "#microsoft.graph.deviceManagementConfigurationSecretSettingValue" { - - valueState := setting.SettingInstance.SimpleSettingValue.ValueState - expectedState := "notEncrypted" - - if valueState != expectedState { - resp.Diagnostics.AddAttributeError( - req.Path, - "Invalid Secret Setting Value State", - fmt.Sprintf("Setting %d: For Secret Setting Value got '%s', expected '%s'. You must use 'notEncrypted' when trying to set a new secret value.", - i, valueState, expectedState), - ) - } - } - } -} diff --git a/internal/resources/device_and_app_management/beta/assignment_filter/construct.go b/internal/resources/device_and_app_management/beta/assignment_filter/construct.go index e16a1bde..078c867c 100644 --- a/internal/resources/device_and_app_management/beta/assignment_filter/construct.go +++ b/internal/resources/device_and_app_management/beta/assignment_filter/construct.go @@ -13,7 +13,7 @@ import ( // constructResource maps the Terraform schema to the SDK model func constructResource(ctx context.Context, data *AssignmentFilterResourceModel) (*models.DeviceAndAppManagementAssignmentFilter, error) { - tflog.Debug(ctx, "Constructing Assignment Filter resource from model") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewDeviceAndAppManagementAssignmentFilter() @@ -61,11 +61,13 @@ func constructResource(ctx context.Context, data *AssignmentFilterResourceModel) } requestBody.SetRoleScopeTags(roleScopeTags) - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/assignment_filter/modify_plan.go b/internal/resources/device_and_app_management/beta/assignment_filter/modify_plan.go new file mode 100644 index 00000000..d19256db --- /dev/null +++ b/internal/resources/device_and_app_management/beta/assignment_filter/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaAssignmentFilter + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *AssignmentFilterResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/assignment_filter/resource.go b/internal/resources/device_and_app_management/beta/assignment_filter/resource.go index 6ba018ad..279c9c1b 100644 --- a/internal/resources/device_and_app_management/beta/assignment_filter/resource.go +++ b/internal/resources/device_and_app_management/beta/assignment_filter/resource.go @@ -17,9 +17,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &AssignmentFilterResource{} -var _ resource.ResourceWithConfigure = &AssignmentFilterResource{} -var _ resource.ResourceWithImportState = &AssignmentFilterResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_assignment_filter" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &AssignmentFilterResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &AssignmentFilterResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &AssignmentFilterResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &AssignmentFilterResource{} +) func NewAssignmentFilterResource() resource.Resource { return &AssignmentFilterResource{ @@ -40,19 +54,9 @@ type AssignmentFilterResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *AssignmentFilterResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *AssignmentFilterResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *AssignmentFilterResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_assignment_filter" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/browser_site/construct.go b/internal/resources/device_and_app_management/beta/browser_site/construct.go index aee24d1f..6734816c 100644 --- a/internal/resources/device_and_app_management/beta/browser_site/construct.go +++ b/internal/resources/device_and_app_management/beta/browser_site/construct.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSite import ( "context" @@ -9,8 +9,9 @@ import ( models "github.com/microsoftgraph/msgraph-beta-sdk-go/models" ) +// constructResource constructs an assignment filter resource using data from the Terraform model. func constructResource(ctx context.Context, data *BrowserSiteResourceModel) (models.BrowserSiteable, error) { - tflog.Debug(ctx, "Constructing Intune Browser Site from model") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewBrowserSite() @@ -74,11 +75,13 @@ func constructResource(ctx context.Context, data *BrowserSiteResourceModel) (mod requestBody.SetWebUrl(&webUrl) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/browser_site/crud.go b/internal/resources/device_and_app_management/beta/browser_site/crud.go index 75f1bc78..8a483eb7 100644 --- a/internal/resources/device_and_app_management/beta/browser_site/crud.go +++ b/internal/resources/device_and_app_management/beta/browser_site/crud.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSite import ( "context" diff --git a/internal/resources/device_and_app_management/beta/browser_site/model.go b/internal/resources/device_and_app_management/beta/browser_site/model.go index 05086e6d..ba88ee37 100644 --- a/internal/resources/device_and_app_management/beta/browser_site/model.go +++ b/internal/resources/device_and_app_management/beta/browser_site/model.go @@ -1,5 +1,5 @@ // REF: https://learn.microsoft.com/en-us/graph/api/resources/browsersite?view=graph-rest-beta -package graphbetabrowsersite +package graphBetaBrowserSite import ( sharedmodels "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/shared_models/graph_beta" diff --git a/internal/resources/device_and_app_management/beta/browser_site/modify_plan.go b/internal/resources/device_and_app_management/beta/browser_site/modify_plan.go new file mode 100644 index 00000000..372c29be --- /dev/null +++ b/internal/resources/device_and_app_management/beta/browser_site/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaBrowserSite + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *BrowserSiteResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/browser_site/resource.go b/internal/resources/device_and_app_management/beta/browser_site/resource.go index 5686d164..f813fd61 100644 --- a/internal/resources/device_and_app_management/beta/browser_site/resource.go +++ b/internal/resources/device_and_app_management/beta/browser_site/resource.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSite import ( "context" @@ -14,9 +14,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &BrowserSiteResource{} -var _ resource.ResourceWithConfigure = &BrowserSiteResource{} -var _ resource.ResourceWithImportState = &BrowserSiteResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_browser_site" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &BrowserSiteResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &BrowserSiteResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &BrowserSiteResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &BrowserSiteResource{} +) func NewBrowserSiteResource() resource.Resource { return &BrowserSiteResource{ @@ -37,19 +51,9 @@ type BrowserSiteResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *BrowserSiteResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *BrowserSiteResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *BrowserSiteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_browser_site" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/browser_site/state.go b/internal/resources/device_and_app_management/beta/browser_site/state.go index 3696c945..182f45db 100644 --- a/internal/resources/device_and_app_management/beta/browser_site/state.go +++ b/internal/resources/device_and_app_management/beta/browser_site/state.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSite import ( "context" diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/construct.go b/internal/resources/device_and_app_management/beta/browser_site_list/construct.go index 632759bb..8ea24ee8 100644 --- a/internal/resources/device_and_app_management/beta/browser_site_list/construct.go +++ b/internal/resources/device_and_app_management/beta/browser_site_list/construct.go @@ -1,7 +1,8 @@ -package graphbetabrowsersite +package graphBetaBrowserSiteList import ( "context" + "fmt" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -9,7 +10,7 @@ import ( ) func constructResource(ctx context.Context, data *BrowserSiteListResourceModel) (models.BrowserSiteListable, error) { - tflog.Debug(ctx, "Constructing Intune Browser Site List resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewBrowserSiteList() @@ -23,11 +24,13 @@ func constructResource(ctx context.Context, data *BrowserSiteListResourceModel) requestBody.SetDisplayName(&displayName) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/crud.go b/internal/resources/device_and_app_management/beta/browser_site_list/crud.go index f161e7e0..8c926d4c 100644 --- a/internal/resources/device_and_app_management/beta/browser_site_list/crud.go +++ b/internal/resources/device_and_app_management/beta/browser_site_list/crud.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSiteList import ( "context" diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/model.go b/internal/resources/device_and_app_management/beta/browser_site_list/model.go index 4cc9c7f9..b2875ec4 100644 --- a/internal/resources/device_and_app_management/beta/browser_site_list/model.go +++ b/internal/resources/device_and_app_management/beta/browser_site_list/model.go @@ -1,5 +1,5 @@ // REF: https://learn.microsoft.com/en-us/graph/api/resources/browsersitelist?view=graph-rest-beta -package graphbetabrowsersite +package graphBetaBrowserSiteList import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/modify_plan.go b/internal/resources/device_and_app_management/beta/browser_site_list/modify_plan.go new file mode 100644 index 00000000..8a73c912 --- /dev/null +++ b/internal/resources/device_and_app_management/beta/browser_site_list/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaBrowserSiteList + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *BrowserSiteListResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/resource.go b/internal/resources/device_and_app_management/beta/browser_site_list/resource.go index 75c8b834..bda8e4f5 100644 --- a/internal/resources/device_and_app_management/beta/browser_site_list/resource.go +++ b/internal/resources/device_and_app_management/beta/browser_site_list/resource.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSiteList import ( "context" @@ -16,9 +16,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &BrowserSiteListResource{} -var _ resource.ResourceWithConfigure = &BrowserSiteListResource{} -var _ resource.ResourceWithImportState = &BrowserSiteListResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_browser_site_list" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &BrowserSiteListResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &BrowserSiteListResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &BrowserSiteListResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &BrowserSiteListResource{} +) func NewBrowserSiteListResource() resource.Resource { return &BrowserSiteListResource{ @@ -51,7 +65,7 @@ func (r *BrowserSiteListResource) GetTypeName() string { // Metadata returns the resource type name. func (r *BrowserSiteListResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_browser_site_list" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/browser_site_list/state.go b/internal/resources/device_and_app_management/beta/browser_site_list/state.go index bf0cf843..72b8f06a 100644 --- a/internal/resources/device_and_app_management/beta/browser_site_list/state.go +++ b/internal/resources/device_and_app_management/beta/browser_site_list/state.go @@ -1,4 +1,4 @@ -package graphbetabrowsersite +package graphBetaBrowserSiteList import ( "context" diff --git a/internal/resources/device_and_app_management/beta/device_management_script/assignments.go b/internal/resources/device_and_app_management/beta/device_management_script/assignments.go index 08b3c3e3..3bf0ca26 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/assignments.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/assignments.go @@ -1,4 +1,4 @@ -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/crud" diff --git a/internal/resources/device_and_app_management/beta/device_management_script/construct.go b/internal/resources/device_and_app_management/beta/device_management_script/construct.go index ba57776d..4751cd62 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/construct.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/construct.go @@ -1,4 +1,4 @@ -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "context" @@ -11,7 +11,7 @@ import ( ) func constructResource(ctx context.Context, data *DeviceManagementScriptResourceModel) (models.DeviceManagementScriptable, error) { - tflog.Debug(ctx, "Constructed Device Management Script resource from modele") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewDeviceManagementScript() @@ -73,12 +73,14 @@ func constructResource(ctx context.Context, data *DeviceManagementScriptResource requestBody.SetRunAs32Bit(&runAs32Bit) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/device_management_script/crud.go b/internal/resources/device_and_app_management/beta/device_management_script/crud.go index 4ea13e1f..1f68aa34 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/crud.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/crud.go @@ -1,4 +1,4 @@ -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "context" diff --git a/internal/resources/device_and_app_management/beta/device_management_script/model.go b/internal/resources/device_and_app_management/beta/device_management_script/model.go index edeb9af9..6f3fc791 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/model.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/model.go @@ -1,6 +1,6 @@ // https://learn.microsoft.com/en-us/graph/api/resources/intune-shared-devicemanagementscript?view=graph-rest-beta -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" diff --git a/internal/resources/device_and_app_management/beta/device_management_script/modify_plan.go b/internal/resources/device_and_app_management/beta/device_management_script/modify_plan.go new file mode 100644 index 00000000..39b312b9 --- /dev/null +++ b/internal/resources/device_and_app_management/beta/device_management_script/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaDeviceManagementScript + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *DeviceManagementScriptResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/device_management_script/resource.go b/internal/resources/device_and_app_management/beta/device_management_script/resource.go index d2413aa3..5ca2d5ba 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/resource.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/resource.go @@ -1,4 +1,4 @@ -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "context" @@ -14,9 +14,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &DeviceManagementScriptResource{} -var _ resource.ResourceWithConfigure = &DeviceManagementScriptResource{} -var _ resource.ResourceWithImportState = &DeviceManagementScriptResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_device_management_script" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &DeviceManagementScriptResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &DeviceManagementScriptResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &DeviceManagementScriptResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &DeviceManagementScriptResource{} +) func NewDeviceManagementScriptResource() resource.Resource { return &DeviceManagementScriptResource{ @@ -49,7 +63,7 @@ func (r *DeviceManagementScriptResource) GetTypeName() string { // Metadata returns the resource type name. func (r *DeviceManagementScriptResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_device_management_script" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/device_management_script/state.go b/internal/resources/device_and_app_management/beta/device_management_script/state.go index 59fb972a..635c8a0a 100644 --- a/internal/resources/device_and_app_management/beta/device_management_script/state.go +++ b/internal/resources/device_and_app_management/beta/device_management_script/state.go @@ -1,4 +1,4 @@ -package graphbetadevicemanagementscript +package graphBetaDeviceManagementScript import ( "context" diff --git a/internal/resources/device_and_app_management/beta/m365_apps_installation_options/construct.go b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/construct.go index b09f599d..04fbb6d9 100644 --- a/internal/resources/device_and_app_management/beta/m365_apps_installation_options/construct.go +++ b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/construct.go @@ -12,7 +12,7 @@ import ( // constructResource maps the Terraform schema to the SDK model func constructResource(ctx context.Context, data *M365AppsInstallationOptionsResourceModel) (models.M365AppsInstallationOptionsable, error) { - tflog.Debug(ctx, "Constructing M365AppsInstallationOptions Resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewM365AppsInstallationOptions() @@ -43,11 +43,13 @@ func constructResource(ctx context.Context, data *M365AppsInstallationOptionsRes requestBody.SetAppsForMac(appsForMac) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/m365_apps_installation_options/modify_plan.go b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/modify_plan.go new file mode 100644 index 00000000..cc092b83 --- /dev/null +++ b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaM365AppsInstallationOptions + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *M365AppsInstallationOptionsResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/m365_apps_installation_options/resource.go b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/resource.go index 741e785d..cfd7b357 100644 --- a/internal/resources/device_and_app_management/beta/m365_apps_installation_options/resource.go +++ b/internal/resources/device_and_app_management/beta/m365_apps_installation_options/resource.go @@ -14,9 +14,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &M365AppsInstallationOptionsResource{} -var _ resource.ResourceWithConfigure = &M365AppsInstallationOptionsResource{} -var _ resource.ResourceWithImportState = &M365AppsInstallationOptionsResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_m365_apps_installation_options" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &M365AppsInstallationOptionsResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &M365AppsInstallationOptionsResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &M365AppsInstallationOptionsResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &M365AppsInstallationOptionsResource{} +) func NewM365AppsInstallationOptionsResource() resource.Resource { return &M365AppsInstallationOptionsResource{ @@ -37,19 +51,9 @@ type M365AppsInstallationOptionsResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *M365AppsInstallationOptionsResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *M365AppsInstallationOptionsResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *M365AppsInstallationOptionsResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_m365_apps_installation_options" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/construct.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/construct.go index 8284f4ae..2b3f5160 100644 --- a/internal/resources/device_and_app_management/beta/macos_pkg_app/construct.go +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/construct.go @@ -1,7 +1,8 @@ -package graphbetamacospkgapp +package graphBetaMacosPkgApp import ( "context" + "fmt" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" "github.com/hashicorp/terraform-plugin-framework/types" @@ -11,7 +12,7 @@ import ( // constructResource constructs a MacOSPkgApp resource using data from the Terraform model. func constructResource(ctx context.Context, data *MacOSPkgAppResourceModel) (models.MacOSPkgAppable, error) { - tflog.Debug(ctx, "Constructing MacOSPkgApp resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewMacOSPkgApp() @@ -138,11 +139,13 @@ func constructResource(ctx context.Context, data *MacOSPkgAppResourceModel) (mod requestBody.SetPostInstallScript(postInstallScript) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/crud.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/crud.go index b3909732..bf60306a 100644 --- a/internal/resources/device_and_app_management/beta/macos_pkg_app/crud.go +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/crud.go @@ -1,4 +1,4 @@ -package graphbetamacospkgapp +package graphBetaMacosPkgApp import ( "context" diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/model.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/model.go index 22a87ed3..e40d0c37 100644 --- a/internal/resources/device_and_app_management/beta/macos_pkg_app/model.go +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/model.go @@ -1,5 +1,5 @@ // REF: https://learn.microsoft.com/en-us/graph/api/resources/intune-apps-macospkgapp?view=graph-rest-beta -package graphbetamacospkgapp +package graphBetaMacosPkgApp import ( sharedmodels "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/shared_models/graph_beta" diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/modify_plan.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/modify_plan.go new file mode 100644 index 00000000..4081fe5d --- /dev/null +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaMacosPkgApp + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *MacOSPkgAppResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/resource.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/resource.go index e2af3acd..fd0abcb9 100644 --- a/internal/resources/device_and_app_management/beta/macos_pkg_app/resource.go +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/resource.go @@ -1,4 +1,4 @@ -package graphbetamacospkgapp +package graphBetaMacosPkgApp import ( "context" @@ -12,10 +12,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -// Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &MacOSPkgAppResource{} -var _ resource.ResourceWithConfigure = &MacOSPkgAppResource{} -var _ resource.ResourceWithImportState = &MacOSPkgAppResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_macos_pkg_app" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &MacOSPkgAppResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &MacOSPkgAppResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &MacOSPkgAppResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &MacOSPkgAppResource{} +) func NewMacOSPkgAppResource() resource.Resource { return &MacOSPkgAppResource{ @@ -38,19 +51,9 @@ type MacOSPkgAppResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *MacOSPkgAppResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *MacOSPkgAppResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *MacOSPkgAppResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_macos_pkg_app" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/macos_pkg_app/state.go b/internal/resources/device_and_app_management/beta/macos_pkg_app/state.go index 95aab2cb..ad4a3493 100644 --- a/internal/resources/device_and_app_management/beta/macos_pkg_app/state.go +++ b/internal/resources/device_and_app_management/beta/macos_pkg_app/state.go @@ -1,4 +1,4 @@ -package graphbetamacospkgapp +package graphBetaMacosPkgApp import ( "context" diff --git a/internal/resources/device_and_app_management/beta/mobile_app_assignment/construct.go b/internal/resources/device_and_app_management/beta/mobile_app_assignment/construct.go index e4043a0f..70a00a74 100644 --- a/internal/resources/device_and_app_management/beta/mobile_app_assignment/construct.go +++ b/internal/resources/device_and_app_management/beta/mobile_app_assignment/construct.go @@ -12,7 +12,7 @@ import ( // ConstructResource maps the Terraform schema to the SDK model func ConstructResource(ctx context.Context, data *MobileAppAssignmentResourceModel) (*models.MobileAppAssignment, error) { - tflog.Debug(ctx, "Constructing Mobile App Assignment resource from model") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewMobileAppAssignment() @@ -99,7 +99,7 @@ func ConstructResource(ctx context.Context, data *MobileAppAssignmentResourceMod settings.SetInstallTimeSettings(installTimeSettings) requestBody.SetSettings(settings) - // Set Source + if !data.Source.IsNull() { sourceValue, err := models.ParseDeviceAndAppManagementAssignmentSource(data.Source.ValueString()) if err != nil { @@ -114,17 +114,18 @@ func ConstructResource(ctx context.Context, data *MobileAppAssignmentResourceMod } } - // Set SourceID if !data.SourceID.IsNull() { sourceID := data.SourceID.ValueString() requestBody.SetSourceId(&sourceID) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/mobile_app_assignment/resource.go b/internal/resources/device_and_app_management/beta/mobile_app_assignment/resource.go index a6f53d8b..e7658dfd 100644 --- a/internal/resources/device_and_app_management/beta/mobile_app_assignment/resource.go +++ b/internal/resources/device_and_app_management/beta/mobile_app_assignment/resource.go @@ -13,9 +13,20 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &MobileAppAssignmentResource{} -var _ resource.ResourceWithConfigure = &MobileAppAssignmentResource{} -var _ resource.ResourceWithImportState = &MobileAppAssignmentResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_mobile_app_assignment" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &MobileAppAssignmentResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &MobileAppAssignmentResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &MobileAppAssignmentResource{} +) func NewMobileAppAssignmentResource() resource.Resource { return &MobileAppAssignmentResource{ @@ -38,19 +49,9 @@ type MobileAppAssignmentResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *MobileAppAssignmentResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *MobileAppAssignmentResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *MobileAppAssignmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_mobile_app_assignment" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/role_assignment/model.go b/internal/resources/device_and_app_management/beta/role_assignment/model.go index aed300cb..0e8d273e 100644 --- a/internal/resources/device_and_app_management/beta/role_assignment/model.go +++ b/internal/resources/device_and_app_management/beta/role_assignment/model.go @@ -1,4 +1,4 @@ -package graphbetaroleassignment +package graphBetaRoleAssignment type RoleAssignmentResourceModel struct { ODataType string `json:"@odata.type"` diff --git a/internal/resources/device_and_app_management/beta/role_definition/construct.go b/internal/resources/device_and_app_management/beta/role_definition/construct.go index 1dfb0b7e..45ca0ed0 100644 --- a/internal/resources/device_and_app_management/beta/role_definition/construct.go +++ b/internal/resources/device_and_app_management/beta/role_definition/construct.go @@ -1,7 +1,8 @@ -package graphbetaroledefinition +package graphBetaRoleDefinition import ( "context" + "fmt" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -10,7 +11,7 @@ import ( // constructResource constructs a RoleDefinition resource using data from the Terraform model. func constructResource(ctx context.Context, data *RoleDefinitionResourceModel) (models.RoleDefinitionable, error) { - tflog.Debug(ctx, "Constructing RoleDefinition resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewRoleDefinition() @@ -90,11 +91,13 @@ func constructResource(ctx context.Context, data *RoleDefinitionResourceModel) ( requestBody.SetRoleScopeTagIds(roleScopeTagIds) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/role_definition/crud.go b/internal/resources/device_and_app_management/beta/role_definition/crud.go index 334ec6e1..ac674291 100644 --- a/internal/resources/device_and_app_management/beta/role_definition/crud.go +++ b/internal/resources/device_and_app_management/beta/role_definition/crud.go @@ -1,4 +1,4 @@ -package graphbetaroledefinition +package graphBetaRoleDefinition import ( "context" diff --git a/internal/resources/device_and_app_management/beta/role_definition/model.go b/internal/resources/device_and_app_management/beta/role_definition/model.go index 517b2321..6aa1b731 100644 --- a/internal/resources/device_and_app_management/beta/role_definition/model.go +++ b/internal/resources/device_and_app_management/beta/role_definition/model.go @@ -1,5 +1,5 @@ // REF: https://learn.microsoft.com/en-us/graph/api/resources/intune-rbac-roledefinition?view=graph-rest-beta -package graphbetaroledefinition +package graphBetaRoleDefinition import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" diff --git a/internal/resources/device_and_app_management/beta/role_definition/modify_plan.go b/internal/resources/device_and_app_management/beta/role_definition/modify_plan.go new file mode 100644 index 00000000..56dffff7 --- /dev/null +++ b/internal/resources/device_and_app_management/beta/role_definition/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaRoleDefinition + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *RoleDefinitionResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/role_definition/resource.go b/internal/resources/device_and_app_management/beta/role_definition/resource.go index a7a3150d..d997a57c 100644 --- a/internal/resources/device_and_app_management/beta/role_definition/resource.go +++ b/internal/resources/device_and_app_management/beta/role_definition/resource.go @@ -1,4 +1,4 @@ -package graphbetaroledefinition +package graphBetaRoleDefinition import ( "context" @@ -12,10 +12,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -// Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &RoleDefinitionResource{} -var _ resource.ResourceWithConfigure = &RoleDefinitionResource{} -var _ resource.ResourceWithImportState = &RoleDefinitionResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_role_definition" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &RoleDefinitionResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &RoleDefinitionResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &RoleDefinitionResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &RoleDefinitionResource{} +) func NewRoleDefinitionResource() resource.Resource { return &RoleDefinitionResource{ @@ -38,19 +51,9 @@ type RoleDefinitionResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *RoleDefinitionResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *RoleDefinitionResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *RoleDefinitionResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_role_definition" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/beta/role_definition/state.go b/internal/resources/device_and_app_management/beta/role_definition/state.go index e85a663d..893e3415 100644 --- a/internal/resources/device_and_app_management/beta/role_definition/state.go +++ b/internal/resources/device_and_app_management/beta/role_definition/state.go @@ -1,4 +1,4 @@ -package graphbetaroledefinition +package graphBetaRoleDefinition import ( "context" diff --git a/internal/resources/device_and_app_management/beta/settings_catalog_v3/construct_resource.go b/internal/resources/device_and_app_management/beta/settings_catalog_v3/construct_resource.go index 963c94f2..4f6efe55 100644 --- a/internal/resources/device_and_app_management/beta/settings_catalog_v3/construct_resource.go +++ b/internal/resources/device_and_app_management/beta/settings_catalog_v3/construct_resource.go @@ -3,6 +3,7 @@ package graphBetaSettingsCatalog import ( "context" "encoding/json" + "fmt" "strings" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" @@ -14,7 +15,7 @@ import ( // Main entry point to construct the intune settings catalog profile resource for the Terraform provider. func constructResource(ctx context.Context, data *SettingsCatalogProfileResourceModel) (graphmodels.DeviceManagementConfigurationPolicyable, error) { - tflog.Debug(ctx, "Constructing Intune Settings Catalog resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := graphmodels.NewDeviceManagementConfigurationPolicy() @@ -65,20 +66,21 @@ func constructResource(ctx context.Context, data *SettingsCatalogProfileResource settings := constructSettingsCatalogSettings(ctx, data.Settings) requestBody.SetSettings(settings) - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } - tflog.Debug(ctx, "Finished constructing Windows Settings Catalog resource") + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } // settingsCatalogModel is a struct that represents the JSON structure of settings catalog settings. // This struct is used to unmarshal the settings JSON string into a structured format. // It represents windows, macOS, and iOS settings settings catalog settings. -var settingsCatalogModel struct { +var SettingsCatalogModel struct { SettingsDetails []struct { ID string `json:"id"` SettingInstance struct { @@ -322,7 +324,7 @@ var settingsCatalogModel struct { func constructSettingsCatalogSettings(ctx context.Context, settingsJSON types.String) []graphmodels.DeviceManagementConfigurationSettingable { tflog.Debug(ctx, "Constructing settings catalog settings") - if err := json.Unmarshal([]byte(settingsJSON.ValueString()), &settingsCatalogModel); err != nil { + if err := json.Unmarshal([]byte(settingsJSON.ValueString()), &SettingsCatalogModel); err != nil { tflog.Error(ctx, "Failed to unmarshal settings JSON", map[string]interface{}{ "error": err.Error(), }) @@ -331,12 +333,12 @@ func constructSettingsCatalogSettings(ctx context.Context, settingsJSON types.St // Add debug logging after unmarshaling tflog.Debug(ctx, "Unmarshaled settings data", map[string]interface{}{ - "data": settingsCatalogModel, + "data": SettingsCatalogModel, }) settingsCollection := make([]graphmodels.DeviceManagementConfigurationSettingable, 0) - for _, detail := range settingsCatalogModel.SettingsDetails { + for _, detail := range SettingsCatalogModel.SettingsDetails { baseSetting := graphmodels.NewDeviceManagementConfigurationSetting() switch detail.SettingInstance.ODataType { diff --git a/internal/resources/device_and_app_management/beta/settings_catalog_v3/modify_plan.go b/internal/resources/device_and_app_management/beta/settings_catalog_v3/modify_plan.go index 3bdb5178..d5a8d5da 100644 --- a/internal/resources/device_and_app_management/beta/settings_catalog_v3/modify_plan.go +++ b/internal/resources/device_and_app_management/beta/settings_catalog_v3/modify_plan.go @@ -13,5 +13,5 @@ func (r *SettingsCatalogResource) ModifyPlan(ctx context.Context, req resource.M return } - tflog.Debug(ctx, "ModifyPlan TODO") + tflog.Debug(ctx, "Modify Plan Place holder") } diff --git a/internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_base_v7.go b/internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_v7.go similarity index 97% rename from internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_base_v7.go rename to internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_v7.go index 2894ed2e..bd36f182 100644 --- a/internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_base_v7.go +++ b/internal/resources/device_and_app_management/beta/settings_catalog_v3/resource_v7.go @@ -18,6 +18,10 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) +const ( + ResourceName = "graph_beta_device_and_app_management_settings_catalog" +) + var ( // Basic resource interface (CRUD operations) _ resource.Resource = &SettingsCatalogResource{} @@ -55,7 +59,7 @@ type SettingsCatalogResource struct { // Metadata returns the resource type name. func (r *SettingsCatalogResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_settings_catalog" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. @@ -99,7 +103,7 @@ func (r *SettingsCatalogResource) Schema(ctx context.Context, req resource.Schem "terraform documentation for the settings catalog for examples and how to correctly format the HCL.", Validators: []validator.String{ customValidator.JSONSchemaValidator(), - //customValidator.SettingsCatalogValidator(), + //SettingsCatalogValidator(), }, PlanModifiers: []planmodifier.String{ planmodifiers.UseStateForUnknownString(), diff --git a/internal/resources/device_and_app_management/beta/settings_catalog_v3/validate_settings_cataloge_settings.go b/internal/resources/device_and_app_management/beta/settings_catalog_v3/validate_settings_cataloge_settings.go new file mode 100644 index 00000000..44c9e13e --- /dev/null +++ b/internal/resources/device_and_app_management/beta/settings_catalog_v3/validate_settings_cataloge_settings.go @@ -0,0 +1,94 @@ +package graphBetaSettingsCatalog + +// import ( +// "context" +// "encoding/json" +// "fmt" + +// "github.com/hashicorp/terraform-plugin-framework/schema/validator" +// ) + +// // settingsCatalogValidator validates settings catalog json structure +// type settingsCatalogValidator struct{} + +// // SettingsCatalogValidator returns a validator which ensures settings catalog json is valid +// func SettingsCatalogValidator() validator.String { +// return &settingsCatalogValidator{} +// } + +// // Description describes the validation in plain text formatting. +// func (v settingsCatalogValidator) Description(_ context.Context) string { +// return "validates settings catalog configuration" +// } + +// // MarkdownDescription describes the validation in Markdown formatting. +// func (v settingsCatalogValidator) MarkdownDescription(ctx context.Context) string { +// return v.Description(ctx) +// } + +// // Validate performs the validation. +// // Validate performs the validation. +// func (v settingsCatalogValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { +// if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { +// return +// } + +// // Parse JSON directly into the existing settingsCatalogModel var +// if err := json.Unmarshal([]byte(req.ConfigValue.ValueString()), &SettingsCatalogModel); err != nil { +// resp.Diagnostics.AddAttributeError( +// req.Path, +// "Invalid Settings Catalog JSON", +// fmt.Sprintf("Error parsing settings catalog JSON: %s", err), +// ) +// return +// } + +// // Helper function to check secret setting value state +// checkSecretValueState := func(path string, i int, j *int, valueState string) { +// expectedState := "notEncrypted" +// if valueState != expectedState { +// errorMsg := fmt.Sprintf("Setting %d: For Secret Setting Value got '%s', expected '%s'. You must use 'notEncrypted' when trying to set a new secret value.", i, valueState, expectedState) +// if j != nil { +// errorMsg = fmt.Sprintf("Setting %d, Child %d: For Secret Setting Value got '%s', expected '%s'. You must use 'notEncrypted' when trying to set a new secret value.", i, *j, valueState, expectedState) +// } +// resp.Diagnostics.AddAttributeError( +// path, +// "Invalid Secret Setting Value State", +// errorMsg, +// ) +// } +// } + +// // Validate each setting +// for i, setting := range SettingsCatalogModel.SettingsDetails { +// // Check root level SimpleSettingValue +// if setting.SettingInstance.SimpleSettingValue != nil && +// setting.SettingInstance.SimpleSettingValue.ODataType == "#microsoft.graph.deviceManagementConfigurationSecretSettingValue" { +// checkSecretValueState(req.Path, i, nil, setting.SettingInstance.SimpleSettingValue.ValueState) +// } + +// // Check ChoiceSettingValue children +// if setting.SettingInstance.ChoiceSettingValue != nil { +// for j, child := range setting.SettingInstance.ChoiceSettingValue.Children { +// if child.SimpleSettingValue != nil && +// child.SimpleSettingValue.ODataType == "#microsoft.graph.deviceManagementConfigurationSecretSettingValue" { +// jCopy := j // Create copy for pointer +// checkSecretValueState(req.Path, i, &jCopy, child.SimpleSettingValue.ValueState) +// } +// } +// } + +// // Check GroupSettingCollectionValue +// if setting.SettingInstance.GroupSettingCollectionValue != nil { +// for j, group := range setting.SettingInstance.GroupSettingCollectionValue { +// for k, child := range group.Children { +// if child.SimpleSettingValue != nil && +// child.SimpleSettingValue.ODataType == "#microsoft.graph.deviceManagementConfigurationSecretSettingValue" { +// kCopy := k +// checkSecretValueState(req.Path, i, &kCopy, child.SimpleSettingValue.ValueState) +// } +// } +// } +// } +// } +// } diff --git a/internal/resources/device_and_app_management/beta/win32_lob_app/construct.go b/internal/resources/device_and_app_management/beta/win32_lob_app/construct.go index 0fd2595d..2aa8e902 100644 --- a/internal/resources/device_and_app_management/beta/win32_lob_app/construct.go +++ b/internal/resources/device_and_app_management/beta/win32_lob_app/construct.go @@ -10,19 +10,19 @@ import ( ) func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (graphmodels.Win32LobAppable, error) { - tflog.Debug(ctx, "Constructing Win32LobApp resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) - win32LobApp := graphmodels.NewWin32LobApp() + requestBody := graphmodels.NewWin32LobApp() // Set string properties using the helper function - construct.SetStringProperty(data.DisplayName, win32LobApp.SetDisplayName) - construct.SetStringProperty(data.Description, win32LobApp.SetDescription) - construct.SetStringProperty(data.Publisher, win32LobApp.SetPublisher) - construct.SetStringProperty(data.FileName, win32LobApp.SetFileName) - construct.SetStringProperty(data.InstallCommandLine, win32LobApp.SetInstallCommandLine) - construct.SetStringProperty(data.UninstallCommandLine, win32LobApp.SetUninstallCommandLine) - construct.SetStringProperty(data.SetupFilePath, win32LobApp.SetSetupFilePath) - construct.SetStringProperty(data.CommittedContentVersion, win32LobApp.SetCommittedContentVersion) + construct.SetStringProperty(data.DisplayName, requestBody.SetDisplayName) + construct.SetStringProperty(data.Description, requestBody.SetDescription) + construct.SetStringProperty(data.Publisher, requestBody.SetPublisher) + construct.SetStringProperty(data.FileName, requestBody.SetFileName) + construct.SetStringProperty(data.InstallCommandLine, requestBody.SetInstallCommandLine) + construct.SetStringProperty(data.UninstallCommandLine, requestBody.SetUninstallCommandLine) + construct.SetStringProperty(data.SetupFilePath, requestBody.SetSetupFilePath) + construct.SetStringProperty(data.CommittedContentVersion, requestBody.SetCommittedContentVersion) // Handle MinimumSupportedOperatingSystem if minOS := data.MinimumSupportedOperatingSystem; minOS != (WindowsMinimumOperatingSystemResourceModel{}) { @@ -42,7 +42,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra construct.SetBoolProperty(minOS.V10_2H20, minSupportedOS.SetV102H20) construct.SetBoolProperty(minOS.V10_21H1, minSupportedOS.SetV1021H1) - win32LobApp.SetMinimumSupportedOperatingSystem(minSupportedOS) + requestBody.SetMinimumSupportedOperatingSystem(minSupportedOS) } // Handle DetectionRules @@ -109,7 +109,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra detectionRules[i] = powershellRule } } - win32LobApp.SetDetectionRules(detectionRules) + requestBody.SetDetectionRules(detectionRules) } // Handle RequirementRules @@ -136,7 +136,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra requirementRules[i] = registryRequirement } - win32LobApp.SetRequirementRules(requirementRules) + requestBody.SetRequirementRules(requirementRules) } // Handle Rules @@ -163,7 +163,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra rules[i] = registryRule } - win32LobApp.SetRules(rules) + requestBody.SetRules(rules) } // Handle Install Experience @@ -182,7 +182,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra construct.SetInt32Property(installExperience.MaxRunTimeInMinutes, installExp.SetMaxRunTimeInMinutes) - win32LobApp.SetInstallExperience(installExp) + requestBody.SetInstallExperience(installExp) } // Handle Return Codes @@ -200,7 +200,7 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra returnCodes[i] = returnCode } - win32LobApp.SetReturnCodes(returnCodes) + requestBody.SetReturnCodes(returnCodes) } // Handle MSI Information @@ -216,15 +216,16 @@ func constructResource(ctx context.Context, data *Win32LobAppResourceModel) (gra if err != nil { return nil, fmt.Errorf("failed to parse MSI package type: %v", err) } - win32LobApp.SetMsiInformation(msiInformation) + requestBody.SetMsiInformation(msiInformation) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", win32LobApp); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } - tflog.Debug(ctx, "Finished constructing Win32LobApp resource") - return win32LobApp, nil + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/win32_lob_app/modify_plan.go b/internal/resources/device_and_app_management/beta/win32_lob_app/modify_plan.go new file mode 100644 index 00000000..a62afa3e --- /dev/null +++ b/internal/resources/device_and_app_management/beta/win32_lob_app/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaWin32LobApp + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *Win32LobAppResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/win32_lob_app/resource.go b/internal/resources/device_and_app_management/beta/win32_lob_app/resource.go index a5b027f9..7ca7e1e6 100644 --- a/internal/resources/device_and_app_management/beta/win32_lob_app/resource.go +++ b/internal/resources/device_and_app_management/beta/win32_lob_app/resource.go @@ -14,9 +14,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &Win32LobAppResource{} -var _ resource.ResourceWithConfigure = &Win32LobAppResource{} -var _ resource.ResourceWithImportState = &Win32LobAppResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_win32_lob_app" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &Win32LobAppResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &Win32LobAppResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &Win32LobAppResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &Win32LobAppResource{} +) func NewWin32LobAppResource() resource.Resource { return &Win32LobAppResource{ @@ -39,9 +53,9 @@ type Win32LobAppResource struct { WritePermissions []string } -// GetTypeName returns the type name of the resource from the state model. -func (r *Win32LobAppResource) GetTypeName() string { - return r.TypeName +// Metadata returns the resource type name. +func (r *Win32LobAppResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. @@ -54,10 +68,7 @@ func (r *Win32LobAppResource) ImportState(ctx context.Context, req resource.Impo resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } -func (r *Win32LobAppResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_win32_lob_app" -} - +// Function to create the full device management win32 lob app schema func (r *Win32LobAppResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ MarkdownDescription: "Manages a Win32 LOB App in Microsoft Intune.", diff --git a/internal/resources/device_and_app_management/beta/winget_app/construct.go b/internal/resources/device_and_app_management/beta/winget_app/construct.go index fee23635..b82abe8e 100644 --- a/internal/resources/device_and_app_management/beta/winget_app/construct.go +++ b/internal/resources/device_and_app_management/beta/winget_app/construct.go @@ -13,7 +13,7 @@ import ( // constructResource constructs a WinGetApp resource using data from the Terraform model. // It fetches additional details from the Microsoft Store using FetchStoreAppDetails. func constructResource(ctx context.Context, data *WinGetAppResourceModel) (models.WinGetAppable, error) { - tflog.Debug(ctx, "Constructing Microsoft Store For Business WinGetApp resource from model") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewWinGetApp() @@ -108,11 +108,13 @@ func constructResource(ctx context.Context, data *WinGetAppResourceModel) (model requestBody.SetInstallExperience(installExperience) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/beta/winget_app/modify_plan.go b/internal/resources/device_and_app_management/beta/winget_app/modify_plan.go new file mode 100644 index 00000000..936ed5ee --- /dev/null +++ b/internal/resources/device_and_app_management/beta/winget_app/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaWinGetApp + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *WinGetAppResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/beta/winget_app/resource.go b/internal/resources/device_and_app_management/beta/winget_app/resource.go index cc277174..2fdb18fc 100644 --- a/internal/resources/device_and_app_management/beta/winget_app/resource.go +++ b/internal/resources/device_and_app_management/beta/winget_app/resource.go @@ -16,9 +16,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &WinGetAppResource{} -var _ resource.ResourceWithConfigure = &WinGetAppResource{} -var _ resource.ResourceWithImportState = &WinGetAppResource{} +const ( + ResourceName = "graph_beta_device_and_app_management_win_get_app" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &WinGetAppResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &WinGetAppResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &WinGetAppResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &WinGetAppResource{} +) func NewWinGetAppResource() resource.Resource { return &WinGetAppResource{ @@ -41,19 +55,9 @@ type WinGetAppResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *WinGetAppResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *WinGetAppResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *WinGetAppResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_device_and_app_management_win_get_app" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. @@ -66,6 +70,7 @@ func (r *WinGetAppResource) ImportState(ctx context.Context, req resource.Import resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } +// Schema returns the schema for the resource. func (r *WinGetAppResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { // Create an instance of MobileAppAssignmentResource mobileAppAssignmentResource := graphBetaMobileAppAssignment.NewMobileAppAssignmentResource() diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/construct.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/construct.go index 2161c62c..ed146eb7 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/construct.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/construct.go @@ -2,6 +2,7 @@ package graphCloudPcDeviceImage import ( "context" + "fmt" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -11,7 +12,7 @@ import ( // constructResource maps the Terraform schema to the SDK model func constructResource(ctx context.Context, data *CloudPcDeviceImageResourceModel) (*models.CloudPcDeviceImage, error) { - tflog.Debug(ctx, "Constructing CloudPcDeviceImage Resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewCloudPcDeviceImage() @@ -30,11 +31,13 @@ func constructResource(ctx context.Context, data *CloudPcDeviceImageResourceMode requestBody.SetVersion(&version) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/modify_plan.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/modify_plan.go new file mode 100644 index 00000000..ce8f95a2 --- /dev/null +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/modify_plan.go @@ -0,0 +1,17 @@ +package graphCloudPcDeviceImage + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *CloudPcDeviceImageResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/resource.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/resource.go index e366c0de..184d0c27 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/resource.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_device_image/resource.go @@ -15,9 +15,23 @@ import ( msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" ) -var _ resource.Resource = &CloudPcDeviceImageResource{} -var _ resource.ResourceWithConfigure = &CloudPcDeviceImageResource{} -var _ resource.ResourceWithImportState = &CloudPcDeviceImageResource{} +const ( + ResourceName = "graph_device_and_app_management_cloud_pc_device_image" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &CloudPcDeviceImageResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &CloudPcDeviceImageResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &CloudPcDeviceImageResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &CloudPcDeviceImageResource{} +) func NewCloudPcDeviceImageResource() resource.Resource { return &CloudPcDeviceImageResource{ @@ -38,24 +52,14 @@ type CloudPcDeviceImageResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *CloudPcDeviceImageResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *CloudPcDeviceImageResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *CloudPcDeviceImageResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_device_and_app_management_cloud_pc_device_image" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. func (r *CloudPcDeviceImageResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - r.client = common.SetGraphStableClientForResource(ctx, req, resp, "CloudPcDeviceImageResource") + r.client = common.SetGraphStableClientForResource(ctx, req, resp, r.TypeName) } // ImportState imports the resource state. diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/construct.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/construct.go index 3523ca76..c57f5af4 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/construct.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/construct.go @@ -11,7 +11,7 @@ import ( // constructResource maps the Terraform schema to the SDK model func constructResource(ctx context.Context, data *CloudPcProvisioningPolicyResourceModel) (*models.CloudPcProvisioningPolicy, error) { - tflog.Debug(ctx, "Constructing CloudPcProvisioningPolicy Resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewCloudPcProvisioningPolicy() @@ -133,11 +133,13 @@ func constructResource(ctx context.Context, data *CloudPcProvisioningPolicyResou requestBody.SetWindowsSetting(windowsSetting) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/modify_plan.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/modify_plan.go new file mode 100644 index 00000000..98fd812a --- /dev/null +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/modify_plan.go @@ -0,0 +1,17 @@ +package graphCloudPcProvisioningPolicy + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *CloudPcProvisioningPolicyResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/resource.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/resource.go index e36c4de5..e8a1602c 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/resource.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_provisioning_policy/resource.go @@ -15,9 +15,23 @@ import ( msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" ) -var _ resource.Resource = &CloudPcProvisioningPolicyResource{} -var _ resource.ResourceWithConfigure = &CloudPcProvisioningPolicyResource{} -var _ resource.ResourceWithImportState = &CloudPcProvisioningPolicyResource{} +const ( + ResourceName = "graph_device_and_app_management_cloud_pc_provisioning_policy" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &CloudPcProvisioningPolicyResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &CloudPcProvisioningPolicyResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &CloudPcProvisioningPolicyResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &CloudPcProvisioningPolicyResource{} +) func NewCloudPcProvisioningPolicyResource() resource.Resource { return &CloudPcProvisioningPolicyResource{ @@ -38,24 +52,14 @@ type CloudPcProvisioningPolicyResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *CloudPcProvisioningPolicyResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *CloudPcProvisioningPolicyResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *CloudPcProvisioningPolicyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_device_and_app_management_cloud_pc_provisioning_policy" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. func (r *CloudPcProvisioningPolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - r.client = common.SetGraphStableClientForResource(ctx, req, resp, "CloudPcProvisioningPolicyResource") + r.client = common.SetGraphStableClientForResource(ctx, req, resp, r.TypeName) } // ImportState imports the resource state. diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/construct.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/construct.go index bf3f0341..761611ae 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/construct.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/construct.go @@ -10,7 +10,7 @@ import ( ) func constructResource(ctx context.Context, data *CloudPcUserSettingResourceModel) (*models.CloudPcUserSetting, error) { - tflog.Debug(ctx, "Constructing CloudPcUserSetting resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewCloudPcUserSetting() @@ -37,12 +37,14 @@ func constructResource(ctx context.Context, data *CloudPcUserSettingResourceMode requestBody.SetRestorePointSetting(restorePointSetting) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/modify_plan.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/modify_plan.go new file mode 100644 index 00000000..4110d99b --- /dev/null +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/modify_plan.go @@ -0,0 +1,17 @@ +package graphCloudPcUserSetting + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *CloudPcUserSettingResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/resource.go b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/resource.go index ae301adf..58c25e1e 100644 --- a/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/resource.go +++ b/internal/resources/device_and_app_management/v1.0/cloud_pc_user_setting/resource.go @@ -14,9 +14,23 @@ import ( msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" ) -var _ resource.Resource = &CloudPcUserSettingResource{} -var _ resource.ResourceWithConfigure = &CloudPcUserSettingResource{} -var _ resource.ResourceWithImportState = &CloudPcUserSettingResource{} +const ( + ResourceName = "graph_device_and_app_management_cloud_pc_user_setting" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &CloudPcUserSettingResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &CloudPcUserSettingResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &CloudPcUserSettingResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &CloudPcUserSettingResource{} +) func NewCloudPcUserSettingResource() resource.Resource { return &CloudPcUserSettingResource{ @@ -37,19 +51,9 @@ type CloudPcUserSettingResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *CloudPcUserSettingResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *CloudPcUserSettingResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *CloudPcUserSettingResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_device_and_app_management_cloud_pc_user_setting" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/construct.go b/internal/resources/device_and_app_management/v1.0/role_definition/construct.go index ebb25e53..e881ec80 100644 --- a/internal/resources/device_and_app_management/v1.0/role_definition/construct.go +++ b/internal/resources/device_and_app_management/v1.0/role_definition/construct.go @@ -1,7 +1,8 @@ -package graphroledefinition +package graphRoleDefinition import ( "context" + "fmt" "github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/construct" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -9,7 +10,7 @@ import ( ) func constructResource(ctx context.Context, data *RoleDefinitionResourceModel) (models.RoleDefinitionable, error) { - tflog.Debug(ctx, "Constructing RoleDefinition resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewRoleDefinition() @@ -64,11 +65,13 @@ func constructResource(ctx context.Context, data *RoleDefinitionResourceModel) ( requestBody.SetRolePermissions(rolePermissions) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/crud.go b/internal/resources/device_and_app_management/v1.0/role_definition/crud.go index 6ab5b7b6..c6025c6a 100644 --- a/internal/resources/device_and_app_management/v1.0/role_definition/crud.go +++ b/internal/resources/device_and_app_management/v1.0/role_definition/crud.go @@ -1,4 +1,4 @@ -package graphroledefinition +package graphRoleDefinition import ( "context" diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/model.go b/internal/resources/device_and_app_management/v1.0/role_definition/model.go index 41eff06b..9348b9ca 100644 --- a/internal/resources/device_and_app_management/v1.0/role_definition/model.go +++ b/internal/resources/device_and_app_management/v1.0/role_definition/model.go @@ -1,5 +1,5 @@ // REF: https://learn.microsoft.com/en-us/graph/api/resources/intune-rbac-roledefinition?view=graph-rest-1.0 -package graphroledefinition +package graphRoleDefinition import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/modify_plan.go b/internal/resources/device_and_app_management/v1.0/role_definition/modify_plan.go new file mode 100644 index 00000000..667a5cc7 --- /dev/null +++ b/internal/resources/device_and_app_management/v1.0/role_definition/modify_plan.go @@ -0,0 +1,17 @@ +package graphRoleDefinition + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *RoleDefinitionResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/resource.go b/internal/resources/device_and_app_management/v1.0/role_definition/resource.go index 1e66122a..f351c76d 100644 --- a/internal/resources/device_and_app_management/v1.0/role_definition/resource.go +++ b/internal/resources/device_and_app_management/v1.0/role_definition/resource.go @@ -1,4 +1,4 @@ -package graphroledefinition +package graphRoleDefinition import ( "context" @@ -12,10 +12,23 @@ import ( msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" ) -// Ensure provider defined types fully satisfy framework interfaces -var _ resource.Resource = &RoleDefinitionResource{} -var _ resource.ResourceWithConfigure = &RoleDefinitionResource{} -var _ resource.ResourceWithImportState = &RoleDefinitionResource{} +const ( + ResourceName = "graph_device_and_app_management_role_definition" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &RoleDefinitionResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &RoleDefinitionResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &RoleDefinitionResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &RoleDefinitionResource{} +) func NewRoleDefinitionResource() resource.Resource { return &RoleDefinitionResource{ @@ -36,19 +49,9 @@ type RoleDefinitionResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *RoleDefinitionResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *RoleDefinitionResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *RoleDefinitionResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_device_and_app_management_role_definition" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource. diff --git a/internal/resources/device_and_app_management/v1.0/role_definition/state.go b/internal/resources/device_and_app_management/v1.0/role_definition/state.go index 9a971896..522f40ab 100644 --- a/internal/resources/device_and_app_management/v1.0/role_definition/state.go +++ b/internal/resources/device_and_app_management/v1.0/role_definition/state.go @@ -1,4 +1,4 @@ -package graphroledefinition +package graphRoleDefinition import ( "context" diff --git a/internal/resources/identity_and_access/beta/conditional_access_policy/construct.go b/internal/resources/identity_and_access/beta/conditional_access_policy/construct.go index 181a81cd..3adc4254 100644 --- a/internal/resources/identity_and_access/beta/conditional_access_policy/construct.go +++ b/internal/resources/identity_and_access/beta/conditional_access_policy/construct.go @@ -13,7 +13,7 @@ import ( // constructResource maps the Terraform schema to the graph beta SDK model func constructResource(ctx context.Context, data *ConditionalAccessPolicyResourceModel) (*models.ConditionalAccessPolicy, error) { - tflog.Debug(ctx, "Constructing ConditionalAccessPolicy Resource") + tflog.Debug(ctx, fmt.Sprintf("Constructing %s resource from model", ResourceName)) requestBody := models.NewConditionalAccessPolicy() @@ -64,12 +64,14 @@ func constructResource(ctx context.Context, data *ConditionalAccessPolicyResourc requestBody.SetSessionControls(sessionControls) } - if err := construct.DebugLogGraphObject(ctx, "Final JSON to be sent to Graph API", requestBody); err != nil { + if err := construct.DebugLogGraphObject(ctx, fmt.Sprintf("Final JSON to be sent to Graph API for resource %s", ResourceName), requestBody); err != nil { tflog.Error(ctx, "Failed to debug log object", map[string]interface{}{ "error": err.Error(), }) } + tflog.Debug(ctx, fmt.Sprintf("Finished constructing %s resource", ResourceName)) + return requestBody, nil } diff --git a/internal/resources/identity_and_access/beta/conditional_access_policy/modify_plan.go b/internal/resources/identity_and_access/beta/conditional_access_policy/modify_plan.go new file mode 100644 index 00000000..5595fd7b --- /dev/null +++ b/internal/resources/identity_and_access/beta/conditional_access_policy/modify_plan.go @@ -0,0 +1,17 @@ +package graphBetaConditionalAccessPolicy + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// ModifyPlan handles plan modification for diff suppression +func (r *ConditionalAccessPolicyResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() { + return + } + + tflog.Debug(ctx, "Modify Plan Place holder") +} diff --git a/internal/resources/identity_and_access/beta/conditional_access_policy/resource.go b/internal/resources/identity_and_access/beta/conditional_access_policy/resource.go index 21a352f3..ebaf9db8 100644 --- a/internal/resources/identity_and_access/beta/conditional_access_policy/resource.go +++ b/internal/resources/identity_and_access/beta/conditional_access_policy/resource.go @@ -18,9 +18,23 @@ import ( msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go" ) -var _ resource.Resource = &ConditionalAccessPolicyResource{} -var _ resource.ResourceWithConfigure = &ConditionalAccessPolicyResource{} -var _ resource.ResourceWithImportState = &ConditionalAccessPolicyResource{} +const ( + ResourceName = "graph_beta_identity_and_access_conditional_access_policy" +) + +var ( + // Basic resource interface (CRUD operations) + _ resource.Resource = &ConditionalAccessPolicyResource{} + + // Allows the resource to be configured with the provider client + _ resource.ResourceWithConfigure = &ConditionalAccessPolicyResource{} + + // Enables import functionality + _ resource.ResourceWithImportState = &ConditionalAccessPolicyResource{} + + // Enables plan modification/diff suppression + _ resource.ResourceWithModifyPlan = &ConditionalAccessPolicyResource{} +) func NewConditionalAccessPolicyResource() resource.Resource { return &ConditionalAccessPolicyResource{ @@ -41,19 +55,9 @@ type ConditionalAccessPolicyResource struct { WritePermissions []string } -// GetID returns the ID of a resource from the state model. -func (s *ConditionalAccessPolicyResourceModel) GetID() string { - return s.ID.ValueString() -} - -// GetTypeName returns the type name of the resource from the state model. -func (r *ConditionalAccessPolicyResource) GetTypeName() string { - return r.TypeName -} - // Metadata returns the resource type name. func (r *ConditionalAccessPolicyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_graph_beta_identity_and_access_conditional_access_policy" + resp.TypeName = req.ProviderTypeName + "_" + ResourceName } // Configure sets the client for the resource.