Skip to content

Solution unmarshall error when importing solution with missing dependencies #349

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

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
3 changes: 3 additions & 0 deletions .devcontainer/features/acceptance_test_dependencies/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ terraform {
local = {
source = "hashicorp/local"
}
null = {
source = "hashicorp/null"
}
}
}
1 change: 1 addition & 0 deletions .devcontainer/features/local_provider_dev/terraform.rc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ provider_installation {
"hashicorp/azuread" = "/go/bin"
"hashicorp/random" = "/go/bin"
"hashicorp/local" = "/go/bin"
"hashicorp/null" = "/go/bin"
}

# For all other providers, install them directly from their origin provider
Expand Down
11 changes: 10 additions & 1 deletion internal/powerplatform/services/solution/api_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -99,7 +100,15 @@ func (client *SolutionClient) CreateSolution(ctx context.Context, environmentId
return nil, err
}
if stageSolutionResponse.StageSolutionResults.StageSolutionStatus != "Passed" {
return nil, fmt.Errorf("stage solution failed: %s", stageSolutionResponse.StageSolutionResults.StageSolutionStatus)
e := fmt.Errorf("solution failed with status: '%s'", stageSolutionResponse.StageSolutionResults.StageSolutionStatus)

for _, missingDependency := range stageSolutionResponse.StageSolutionResults.MissingDependencies {
e = errors.Join(fmt.Errorf("missing dependency: '%s'", missingDependency.RequiredComponentSchemaName), e)
}
for _, validation := range stageSolutionResponse.StageSolutionResults.SolutionValidationResults {
e = errors.Join(fmt.Errorf("solution validation failed: %s", validation.Message), e)
}
return nil, e
}

//import solution
Expand Down
29 changes: 26 additions & 3 deletions internal/powerplatform/services/solution/model_solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,34 @@ type StageSolutionImportResponseDto struct {
type StageSolutionImportResultResponseDto struct {
StageSolutionUploadId string `json:"StageSolutionUploadId"`
StageSolutionStatus string `json:"StageSolutionStatus"`
SolutionValidationResults []string `json:"SolutionValidationResults"`
MissingDependencies []string `json:"MissingDependencies"`
SolutionValidationResults []SolutionValidationResults `json:"SolutionValidationResults"`
MissingDependencies []MissingDependenciesDto `json:"MissingDependencies"`
SolutionDetails StageSolutionSolutionDetailsDto `json:"SolutionDetails"`
}

type SolutionValidationResults struct {
SolutionValidationResultType string `json:"SolutionValidationResultType"`
ErrorCode int `json:"ErrorCode"`
AdditionalInfo string `json:"AdditionalInfo"`
Message string `json:"Message"`
}

type MissingDependenciesDto struct {
RequiredComponentSchemaName string `json:"RequiredComponentSchemaName"`
RequiredComponentDisplayName string `json:"RequiredComponentDisplayName"`
RequiredComponentParentSchemaName string `json:"RequiredComponentParentSchemaName"`
RequiredComponentParentDisplayName string `json:"RequiredComponentParentDisplayName"`
RequiredComponentId string `json:"RequiredComponentId"`
RequiredSolutionName string `json:"RequiredSolutionName"`
RequiredComponentType string `json:"RequiredComponentType"`
DependentComponentSchemaName string `json:"DependentComponentSchemaName"`
DependentComponentDisplayName string `json:"DependentComponentDisplayName"`
DependentComponentParentSchemaName string `json:"DependentComponentParentSchemaName"`
DependentComponentParentDisplayName string `json:"DependentComponentParentDisplayName"`
DependentComponentType string `json:"DependentComponentType"`
DependentComponentId string `json:"DependentComponentId"`
}

type StageSolutionSolutionDetailsDto struct {
SolutionUniqueName string `json:"SolutionUniqueName"`
SolutionFriendlyName string `json:"SolutionFriendlyName"`
Expand Down Expand Up @@ -117,4 +140,4 @@ type EnvironmentIdPropertiesDto struct {

type LinkedEnvironmentIdMetadataDto struct {
InstanceURL string
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func (r *SolutionResource) importSolution(ctx context.Context, plan *SolutionRes
diagnostics.AddError(fmt.Sprintf("Client error when reading solution file %s", plan.SolutionFile.ValueString()), err.Error())
}

cwd, _ := os.Getwd()
tflog.Debug(ctx, fmt.Sprintf("Current working directory: %s", cwd))

settingsContent := make([]byte, 0)
//todo check if settings file is not empty in .tf
if plan.SettingsFile.ValueString() != "" {
Expand Down