Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - for M365AppsInstallationOptions to use the correct api endpoint and request constructors #116

Merged
merged 5 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ No modules.

| Name | Type |
|------|------|
| [microsoft365_cloud_pc_device_image.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/cloud_pc_device_image) | resource |
| [microsoft365_device_and_app_management_cloud_pc_device_image.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/device_and_app_management_cloud_pc_device_image) | resource |
| [microsoft365_cloud_pc_device_image.existing](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/data-sources/cloud_pc_device_image) | data source |

## Inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ No modules.

| Name | Type |
|------|------|
| [microsoft365_graph_cloud_pc_provisioning_policy.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_cloud_pc_provisioning_policy) | resource |
| [microsoft365_graph_device_and_app_management_cloud_pc_provisioning_policy.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_device_and_app_management_cloud_pc_provisioning_policy) | resource |

## Inputs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ No modules.

| Name | Type |
|------|------|
| [microsoft365_graph_cloud_pc_user_setting.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_cloud_pc_user_setting) | resource |
| [microsoft365_graph_device_and_app_management_cloud_pc_user_setting.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_device_and_app_management_cloud_pc_user_setting) | resource |

## Inputs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ No modules.

| Name | Type |
|------|------|
| [microsoft365_graph_device_and_app_management_role_definition.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_device_and_app_management_role_definition) | resource |
| [microsoft365_graph_device_and_app_management_role_definition.helpdesk_assignment](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_device_and_app_management_role_definition) | resource |
| [microsoft365_graph_beta_device_and_app_management_role_definition.example](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/resources/graph_beta_device_and_app_management_role_definition) | resource |
| [microsoft365_graph_device_and_app_management_role_definition.helpdesk_admin](https://registry.terraform.io/providers/hashicorp/microsoft365/latest/docs/data-sources/graph_device_and_app_management_role_definition) | data source |

## Inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// constructResource maps the Terraform schema to the SDK model
func constructResource(ctx context.Context, data *M365AppsInstallationOptionsResourceModel) (models.AdminMicrosoft365Appsable, error) {
func constructResource(ctx context.Context, data *M365AppsInstallationOptionsResourceModel) (models.M365AppsInstallationOptionsable, error) {
tflog.Debug(ctx, "Constructing M365AppsInstallationOptions Resource")
construct.DebugPrintStruct(ctx, "Constructed M365AppsInstallationOptions Resource from model", data)

Expand Down Expand Up @@ -44,8 +44,5 @@ func constructResource(ctx context.Context, data *M365AppsInstallationOptionsRes
installationOptions.SetAppsForMac(appsForMac)
}

requestBody := models.NewAdminMicrosoft365Apps()
requestBody.SetInstallationOptions(installationOptions)

return requestBody, nil
return installationOptions, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (r *M365AppsInstallationOptionsResource) Create(ctx context.Context, req re
return
}

options, err := r.client.Admin().Microsoft365Apps().Patch(ctx, requestBody, nil)
options, err := r.client.Admin().Microsoft365Apps().InstallationOptions().Patch(ctx, requestBody, nil)
if err != nil {
resp.Diagnostics.AddError(
"Error creating M365AppsInstallationOptions",
Expand Down Expand Up @@ -75,7 +75,7 @@ func (r *M365AppsInstallationOptionsResource) Read(ctx context.Context, req reso
}
defer cancel()

options, err := r.client.Admin().Microsoft365Apps().Get(ctx, nil)
options, err := r.client.Admin().Microsoft365Apps().InstallationOptions().Get(ctx, nil)
if err != nil {
crud.HandleReadErrorIfNotFound(ctx, resp, r, &state, err)
return
Expand Down Expand Up @@ -112,7 +112,7 @@ func (r *M365AppsInstallationOptionsResource) Update(ctx context.Context, req re
return
}

options, err := r.client.Admin().Microsoft365Apps().Patch(ctx, requestBody, nil)
options, err := r.client.Admin().Microsoft365Apps().InstallationOptions().Patch(ctx, requestBody, nil)
if err != nil {
crud.HandleUpdateErrorIfNotFound(ctx, resp, r, &plan, err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ 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"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
)

func MapRemoteStateToTerraform(ctx context.Context, data *M365AppsInstallationOptionsResourceModel, remoteResource models.AdminMicrosoft365Appsable) {
func MapRemoteStateToTerraform(ctx context.Context, data *M365AppsInstallationOptionsResourceModel, remoteResource models.M365AppsInstallationOptionsable) {
if remoteResource == nil {
tflog.Debug(ctx, "Remote resource is nil")
return
}

tflog.Debug(ctx, "Starting to map remote state to Terraform state for M365AppsInstallationOptions")

installationOptions := remoteResource.GetInstallationOptions()
if installationOptions == nil {
tflog.Debug(ctx, "Installation options are nil")
return
// Check if UpdateChannel exists and map it
updateChannel := remoteResource.GetUpdateChannel()
if updateChannel != nil {
data.UpdateChannel = state.EnumPtrToTypeString(updateChannel)
}

// Map UpdateChannel
data.UpdateChannel = state.EnumPtrToTypeString(installationOptions.GetUpdateChannel())

// Map AppsForWindows
if remoteWindows := installationOptions.GetAppsForWindows(); remoteWindows != nil {
// Map AppsForWindows if it exists
if remoteWindows := remoteResource.GetAppsForWindows(); remoteWindows != nil {
data.AppsForWindows = &AppsInstallationOptionsForWindows{
IsMicrosoft365AppsEnabled: types.BoolPointerValue(remoteWindows.GetIsMicrosoft365AppsEnabled()),
IsProjectEnabled: types.BoolPointerValue(remoteWindows.GetIsProjectEnabled()),
IsSkypeForBusinessEnabled: types.BoolPointerValue(remoteWindows.GetIsSkypeForBusinessEnabled()),
IsVisioEnabled: types.BoolPointerValue(remoteWindows.GetIsVisioEnabled()),
IsMicrosoft365AppsEnabled: state.BoolPtrToTypeBool(remoteWindows.GetIsMicrosoft365AppsEnabled()),
IsProjectEnabled: state.BoolPtrToTypeBool(remoteWindows.GetIsProjectEnabled()),
IsSkypeForBusinessEnabled: state.BoolPtrToTypeBool(remoteWindows.GetIsSkypeForBusinessEnabled()),
IsVisioEnabled: state.BoolPtrToTypeBool(remoteWindows.GetIsVisioEnabled()),
}
} else {
data.AppsForWindows = nil
}

// Map AppsForMac
if remoteMac := installationOptions.GetAppsForMac(); remoteMac != nil {
// Map AppsForMac if it exists
if remoteMac := remoteResource.GetAppsForMac(); remoteMac != nil {
data.AppsForMac = &AppsInstallationOptionsForMac{
IsMicrosoft365AppsEnabled: types.BoolPointerValue(remoteMac.GetIsMicrosoft365AppsEnabled()),
IsSkypeForBusinessEnabled: types.BoolPointerValue(remoteMac.GetIsSkypeForBusinessEnabled()),
IsMicrosoft365AppsEnabled: state.BoolPtrToTypeBool(remoteMac.GetIsMicrosoft365AppsEnabled()),
IsSkypeForBusinessEnabled: state.BoolPtrToTypeBool(remoteMac.GetIsSkypeForBusinessEnabled()),
}
} else {
data.AppsForMac = nil
}

tflog.Debug(ctx, "Finished mapping remote state to Terraform state for M365AppsInstallationOptions")
Expand Down
Loading