diff --git a/docs/resources/quality_forms_evaluation.md b/docs/resources/quality_forms_evaluation.md index ee0c47623..2cbb55aa5 100644 --- a/docs/resources/quality_forms_evaluation.md +++ b/docs/resources/quality_forms_evaluation.md @@ -121,11 +121,14 @@ Optional: - `default_answers_to_highest` (Boolean) Specifies whether to default answers to highest score. Defaults to `false`. - `default_answers_to_na` (Boolean) Specifies whether to default answers to not applicable. Defaults to `false`. -- `id` (String) ID of the question group. READ-ONLY. No value should be provided for this field as one will be generated by the API. - `manual_weight` (Boolean) Specifies whether a manual weight is set. Defaults to `true`. - `na_enabled` (Boolean) Specifies whether a not applicable answer is enabled. Defaults to `false`. - `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--visibility_condition)) +Read-Only: + +- `id` (String) ID of the question group. + ### Nested Schema for `question_groups.questions` @@ -138,12 +141,15 @@ Optional: - `comments_required` (Boolean) Specifies whether comments are required. Defaults to `false`. - `help_text` (String) Help text for the question. -- `id` (String) ID of the question. READ-ONLY. No value should be provided for this field as one will be generated by the API. - `is_critical` (Boolean) True if the question is a critical question Defaults to `false`. - `is_kill` (Boolean) True if the question is a fatal question Defaults to `false`. - `na_enabled` (Boolean) Specifies whether a not applicable answer is enabled. Defaults to `false`. - `visibility_condition` (Block List, Max: 1) Defines conditions where question would be visible (see [below for nested schema](#nestedblock--question_groups--questions--visibility_condition)) +Read-Only: + +- `id` (String) ID of the question. + ### Nested Schema for `question_groups.questions.answer_options` @@ -152,9 +158,9 @@ Required: - `text` (String) - `value` (Number) -Optional: +Read-Only: -- `id` (String) The ID for the answer option. READ-ONLY. No value should be provided for this field as one will be generated by the API. +- `id` (String) The ID for the answer option. diff --git a/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go b/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go index 1745bd817..addb5f443 100644 --- a/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go +++ b/genesyscloud/data_source_genesyscloud_quality_forms_evaluation.go @@ -15,7 +15,6 @@ import ( ) type EvaluationFormQuestionGroupStruct struct { - Id string Name string DefaultAnswersToHighest bool DefaultAnswersToNA bool @@ -33,7 +32,6 @@ type EvaluationFormStruct struct { } type EvaluationFormQuestionStruct struct { - Id string Text string HelpText string NaEnabled bool @@ -45,7 +43,6 @@ type EvaluationFormQuestionStruct struct { } type AnswerOptionStruct struct { - Id string Text string Value int AssistanceConditions []AssistanceConditionStruct diff --git a/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go b/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go index dc500ea7f..08afdd8f5 100644 --- a/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go +++ b/genesyscloud/resource_genesyscloud_quality_forms_evaluation.go @@ -24,15 +24,12 @@ import ( "github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" ) -const readOnlyWarningMessage = "READ-ONLY. No value should be provided for this field as one will be generated by the API." - var ( evaluationFormQuestionGroup = &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { - Description: fmt.Sprintf("ID of the question group. %s", readOnlyWarningMessage), + Description: "ID of the question group.", Type: schema.TypeString, - Optional: true, Computed: true, }, "name": { @@ -89,9 +86,8 @@ var ( evaluationFormQuestion = &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { - Description: fmt.Sprintf("ID of the question. %s", readOnlyWarningMessage), + Description: "ID of the question.", Type: schema.TypeString, - Optional: true, Computed: true, }, "text": { @@ -166,8 +162,7 @@ var ( Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Description: fmt.Sprintf("The ID for the answer option. %s", readOnlyWarningMessage), - Optional: true, + Description: "The ID for the answer option.", Computed: true, }, "text": { @@ -251,18 +246,13 @@ func createEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte name := d.Get("name").(string) published := d.Get("published").(bool) - questionGroups, qgErr := buildSdkQuestionGroups(d) - if qgErr != nil { - return qgErr - } - sdkConfig := meta.(*provider.ProviderMeta).ClientConfig qualityAPI := platformclientv2.NewQualityApiWithConfig(sdkConfig) log.Printf("Creating Evaluation Form %s", name) form, resp, err := qualityAPI.PostQualityFormsEvaluations(platformclientv2.Evaluationform{ Name: &name, - QuestionGroups: questionGroups, + QuestionGroups: buildSdkQuestionGroups(d), }) if err != nil { return util.BuildAPIDiagnosticError("genesyscloud_quality_forms_evaluation", fmt.Sprintf("Failed to create evaluation form %s error: %s", name, err), resp) @@ -340,11 +330,6 @@ func updateEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte name := d.Get("name").(string) published := d.Get("published").(bool) - questionGroups, qgErr := buildSdkQuestionGroups(d) - if qgErr != nil { - return qgErr - } - sdkConfig := meta.(*provider.ProviderMeta).ClientConfig qualityAPI := platformclientv2.NewQualityApiWithConfig(sdkConfig) @@ -359,7 +344,7 @@ func updateEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte log.Printf("Updating Evaluation Form %s", name) form, resp, err := qualityAPI.PutQualityFormsEvaluation(*unpublishedForm.Id, platformclientv2.Evaluationform{ Name: &name, - QuestionGroups: questionGroups, + QuestionGroups: buildSdkQuestionGroups(d), }) if err != nil { return util.BuildAPIDiagnosticError("genesyscloud_quality_forms_evaluation", fmt.Sprintf("Failed to update evaluation form %s error: %s", name, err), resp) @@ -418,7 +403,7 @@ func deleteEvaluationForm(ctx context.Context, d *schema.ResourceData, meta inte }) } -func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluationquestiongroup, diag.Diagnostics) { +func buildSdkQuestionGroups(d *schema.ResourceData) *[]platformclientv2.Evaluationquestiongroup { questionGroupType := "questionGroup" var evalQuestionGroups []platformclientv2.Evaluationquestiongroup @@ -426,10 +411,6 @@ func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluat for _, questionGroup := range questionGroupList { questionGroupsMap := questionGroup.(map[string]interface{}) - if id, _ := questionGroupsMap["id"].(string); id != "" { - return nil, diag.Errorf("The id field for question_groups is intended to be read-only. Got: '%s'", id) - } - questionGroupName := questionGroupsMap["name"].(string) defaultAnswersToHighest := questionGroupsMap["default_answers_to_highest"].(bool) defaultAnswersToNA := questionGroupsMap["default_answers_to_na"].(bool) @@ -446,14 +427,9 @@ func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluat NaEnabled: &naEnabled, Weight: &weight, ManualWeight: &manualWeight, + Questions: buildSdkQuestions(questions), } - sdkQuestions, diagErr := buildSdkQuestions(questions) - if diagErr != nil { - return nil, diagErr - } - sdkquestionGroup.Questions = sdkQuestions - visibilityCondition := questionGroupsMap["visibility_condition"].([]interface{}) sdkquestionGroup.VisibilityCondition = buildSdkVisibilityCondition(visibilityCondition) @@ -461,20 +437,16 @@ func buildSdkQuestionGroups(d *schema.ResourceData) (*[]platformclientv2.Evaluat } } - return &evalQuestionGroups, nil + return &evalQuestionGroups } -func buildSdkQuestions(questions []interface{}) (*[]platformclientv2.Evaluationquestion, diag.Diagnostics) { +func buildSdkQuestions(questions []interface{}) *[]platformclientv2.Evaluationquestion { questionType := "multipleChoiceQuestion" sdkQuestions := make([]platformclientv2.Evaluationquestion, 0) for _, question := range questions { questionsMap := question.(map[string]interface{}) - if id, _ := questionsMap["id"].(string); id != "" { - return nil, diag.Errorf("The id field for questions is intended to be read-only. Got: '%s'", id) - } - text := questionsMap["text"].(string) helpText := questionsMap["help_text"].(string) naEnabled := questionsMap["na_enabled"].(bool) @@ -491,32 +463,23 @@ func buildSdkQuestions(questions []interface{}) (*[]platformclientv2.Evaluationq CommentsRequired: &commentsRequired, IsKill: &isKill, IsCritical: &isCritical, + AnswerOptions: buildSdkAnswerOptions(answerQuestions), } - sdkAnswerOptions, err := buildSdkAnswerOptions(answerQuestions) - if err != nil { - return nil, err - } - sdkQuestion.AnswerOptions = sdkAnswerOptions - visibilityCondition := questionsMap["visibility_condition"].([]interface{}) sdkQuestion.VisibilityCondition = buildSdkVisibilityCondition(visibilityCondition) sdkQuestions = append(sdkQuestions, sdkQuestion) } - return &sdkQuestions, nil + return &sdkQuestions } -func buildSdkAnswerOptions(answerOptions []interface{}) (*[]platformclientv2.Answeroption, diag.Diagnostics) { +func buildSdkAnswerOptions(answerOptions []interface{}) *[]platformclientv2.Answeroption { sdkAnswerOptions := make([]platformclientv2.Answeroption, 0) for _, answerOptionsList := range answerOptions { answerOptionsMap := answerOptionsList.(map[string]interface{}) - if id, _ := answerOptionsMap["id"].(string); id != "" { - return nil, diag.Errorf("The id field for answer_options is intended to be read-only. Got: '%s'", id) - } - answerText := answerOptionsMap["text"].(string) answerValue := answerOptionsMap["value"].(int) @@ -528,7 +491,7 @@ func buildSdkAnswerOptions(answerOptions []interface{}) (*[]platformclientv2.Ans sdkAnswerOptions = append(sdkAnswerOptions, sdkAnswerOption) } - return &sdkAnswerOptions, nil + return &sdkAnswerOptions } func buildSdkVisibilityCondition(visibilityCondition []interface{}) *platformclientv2.Visibilitycondition { @@ -694,13 +657,8 @@ func GenerateEvaluationFormQuestionGroups(questionGroups *[]EvaluationFormQuesti questionGroupsString := "" for _, questionGroup := range *questionGroups { - idValue := util.NullValue - if questionGroup.Id != "" { - idValue = strconv.Quote(questionGroup.Id) - } questionGroupString := fmt.Sprintf(` question_groups { - id = %s name = "%s" default_answers_to_highest = %v default_answers_to_na = %v @@ -710,7 +668,7 @@ func GenerateEvaluationFormQuestionGroups(questionGroups *[]EvaluationFormQuesti %s %s } - `, idValue, questionGroup.Name, + `, questionGroup.Name, questionGroup.DefaultAnswersToHighest, questionGroup.DefaultAnswersToNA, questionGroup.NaEnabled, @@ -734,13 +692,8 @@ func GenerateEvaluationFormQuestions(questions *[]EvaluationFormQuestionStruct) questionsString := "" for _, question := range *questions { - idValue := util.NullValue - if question.Id != "" { - idValue = strconv.Quote(question.Id) - } questionString := fmt.Sprintf(` questions { - id = %s text = "%s" help_text = "%s" na_enabled = %v @@ -750,7 +703,7 @@ func GenerateEvaluationFormQuestions(questions *[]EvaluationFormQuestionStruct) %s %s } - `, idValue, question.Text, + `, question.Text, question.HelpText, question.NaEnabled, question.CommentsRequired, @@ -774,18 +727,12 @@ func GenerateFormAnswerOptions(answerOptions *[]AnswerOptionStruct) string { answerOptionsString := "" for _, answerOption := range *answerOptions { - idValue := util.NullValue - if answerOption.Id != "" { - idValue = strconv.Quote(answerOption.Id) - } answerOptionString := fmt.Sprintf(` answer_options { - id = %s text = "%s" value = %v } - `, idValue, - answerOption.Text, + `, answerOption.Text, answerOption.Value, ) diff --git a/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go b/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go index bf61fef71..3c28fc71d 100644 --- a/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go +++ b/genesyscloud/resource_genesyscloud_quality_forms_evaluation_test.go @@ -15,9 +15,6 @@ import ( func TestAccResourceEvaluationFormBasic(t *testing.T) { formResource1 := "test-evaluation-form-1" - questionGroupId := uuid.NewString() - questionId := uuid.NewString() - answer1Id := uuid.NewString() answer1Text := "Yes" answer1Value := 1 @@ -26,16 +23,13 @@ func TestAccResourceEvaluationFormBasic(t *testing.T) { Name: "terraform-form-evaluations-" + uuid.NewString(), QuestionGroups: []EvaluationFormQuestionGroupStruct{ { - Id: questionGroupId, Name: "Test Question Group 1", Weight: 1, Questions: []EvaluationFormQuestionStruct{ { - Id: questionId, Text: "Did the agent perform the opening spiel?", AnswerOptions: []AnswerOptionStruct{ { - Id: answer1Id, Text: answer1Text, Value: answer1Value, }, @@ -104,9 +98,7 @@ func TestAccResourceEvaluationFormBasic(t *testing.T) { resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "name", evaluationForm1.Name), resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "published", util.FalseValue), resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.0.name", evaluationForm1.QuestionGroups[0].Name), - resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.0.id", evaluationForm1.QuestionGroups[0].Id), resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.#", fmt.Sprint(len(evaluationForm1.QuestionGroups))), - resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.0.questions.0.id", evaluationForm1.QuestionGroups[0].Questions[0].Id), resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.0.questions.0.text", evaluationForm1.QuestionGroups[0].Questions[0].Text), resource.TestCheckResourceAttr("genesyscloud_quality_forms_evaluation."+formResource1, "question_groups.0.questions.0.answer_options.#", fmt.Sprint(len(evaluationForm1.QuestionGroups[0].Questions[0].AnswerOptions))), ), diff --git a/genesyscloud/resource_genesyscloud_quality_forms_survey.go b/genesyscloud/resource_genesyscloud_quality_forms_survey.go index 6da38f3fb..a388e523e 100644 --- a/genesyscloud/resource_genesyscloud_quality_forms_survey.go +++ b/genesyscloud/resource_genesyscloud_quality_forms_survey.go @@ -512,7 +512,7 @@ func buildSurveyQuestions(questions []interface{}) *[]platformclientv2.Surveyque naEnabled := questionsMap["na_enabled"].(bool) answerQuestions := questionsMap["answer_options"].([]interface{}) maxResponseCharacters := questionsMap["max_response_characters"].(int) - sdkAnswerOptions, _ := buildSdkAnswerOptions(answerQuestions) + sdkAnswerOptions := buildSdkAnswerOptions(answerQuestions) sdkQuestion := platformclientv2.Surveyquestion{ Text: &text,