Skip to content

Commit

Permalink
Adapt to backend api changes (#21)
Browse files Browse the repository at this point in the history
* context question option renamed to answer option

* go gen

* address comment

* change unset
  • Loading branch information
carlhejiayu authored Sep 29, 2023
1 parent b92e4d5 commit a26d73c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions docs/data-sources/context_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ A resourcely ContextQuestion

### Read-Only

- `answer_choices` (Attributes Set) (see [below for nested schema](#nestedatt--answer_choices))
- `answer_format` (String)
- `blueprint_categories` (Set of String) Resource categories the context question applies to
- `context_question_options` (Attributes Set) (see [below for nested schema](#nestedatt--context_question_options))
- `excluded_blueprint_series` (Set of String) series_id for Blueprints exempt from this context question even though those blueprints belong to the context question's blueprint_categories
- `id` (String) UUID for this version.
- `label` (String)
Expand All @@ -33,8 +33,8 @@ A resourcely ContextQuestion
- `scope` (String)
- `version` (Number) Specific version of the global context

<a id="nestedatt--context_question_options"></a>
### Nested Schema for `context_question_options`
<a id="nestedatt--answer_choices"></a>
### Nested Schema for `answer_choices`

Read-Only:

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/context_question.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ A Resourcely Context Question

### Optional

- `answer_choices` (Attributes Set) (see [below for nested schema](#nestedatt--answer_choices))
- `answer_format` (String)
- `blueprint_categories` (Set of String)
- `context_question_options` (Attributes Set) (see [below for nested schema](#nestedatt--context_question_options))
- `excluded_blueprint_series` (Set of String) series_id for Blueprints exempt from this context question even though those blueprints belong to the context question's blueprint_categories
- `label` (String)
- `regex_pattern` (String) Regex validation for the acceptable answers to the context question
Expand All @@ -36,8 +36,8 @@ A Resourcely Context Question
- `series_id` (String) UUID for the Context Question
- `version` (Number) Specific version of the Global Context

<a id="nestedatt--context_question_options"></a>
### Nested Schema for `context_question_options`
<a id="nestedatt--answer_choices"></a>
### Nested Schema for `answer_choices`

Required:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package client

type ContextQuestionOption struct {
type AnswerChoice struct {
Label string `json:"label"`
}
18 changes: 9 additions & 9 deletions internal/client/context_question.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ type UpdatedContextQuestion struct {
}

type CommonContextQuestionFields struct {
Label string `json:"label"`
Prompt string `json:"prompt"`
Qtype string `json:"qtype"`
AnswerFormat string `json:"answer_format,omit_empty"`
Scope string `json:"scope"`
ContextQuestionOptions []ContextQuestionOption `json:"context_question_options"`
BlueprintCategories []string `json:"blueprint_categories"`
RegexPattern string `json:"regex_pattern"`
ExcludedBlueprintSeries []string `json:"excluded_blueprint_series"`
Label string `json:"label"`
Prompt string `json:"prompt"`
Qtype string `json:"qtype"`
AnswerFormat string `json:"answer_format,omit_empty"`
Scope string `json:"scope"`
AnswerChoices []AnswerChoice `json:"answer_choices"`
BlueprintCategories []string `json:"blueprint_categories"`
RegexPattern string `json:"regex_pattern"`
ExcludedBlueprintSeries []string `json:"excluded_blueprint_series"`
}

type ContextQuestion struct {
Expand Down
28 changes: 14 additions & 14 deletions internal/provider/context_question_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type ContextQuestionOption struct {
type AnswerChoices struct {
Label types.String `tfsdk:"label"`
}

Expand All @@ -18,15 +18,15 @@ type ContextQuestionResourceModel struct {
SeriesId types.String `tfsdk:"series_id"`
Version types.Int64 `tfsdk:"version"`

Label types.String `tfsdk:"label"`
Prompt types.String `tfsdk:"prompt"`
Qtype types.String `tfsdk:"qtype"`
AnswerFormat types.String `tfsdk:"answer_format"`
Scope types.String `tfsdk:"scope"`
ContextQuestionOptions []ContextQuestionOption `tfsdk:"context_question_options"`
BlueprintCategories types.Set `tfsdk:"blueprint_categories"`
RegexPattern types.String `tfsdk:"regex_pattern"`
ExcludedBlueprintSeries types.Set `tfsdk:"excluded_blueprint_series"`
Label types.String `tfsdk:"label"`
Prompt types.String `tfsdk:"prompt"`
Qtype types.String `tfsdk:"qtype"`
AnswerFormat types.String `tfsdk:"answer_format"`
Scope types.String `tfsdk:"scope"`
AnswerChoices []AnswerChoices `tfsdk:"answer_choices"`
BlueprintCategories types.Set `tfsdk:"blueprint_categories"`
RegexPattern types.String `tfsdk:"regex_pattern"`
ExcludedBlueprintSeries types.Set `tfsdk:"excluded_blueprint_series"`
}

func FlattenContextQuestion(contextQuestion *client.ContextQuestion) ContextQuestionResourceModel {
Expand All @@ -41,11 +41,11 @@ func FlattenContextQuestion(contextQuestion *client.ContextQuestion) ContextQues
data.AnswerFormat = types.StringValue(contextQuestion.AnswerFormat)
data.Scope = types.StringValue(contextQuestion.Scope)

var contextQuestionOptions = make([]ContextQuestionOption, 0)
for _, contextQuestionOption := range contextQuestion.ContextQuestionOptions {
contextQuestionOptions = append(contextQuestionOptions, ContextQuestionOption{Label: basetypes.NewStringValue(contextQuestionOption.Label)})
var answerChoices = make([]AnswerChoices, 0)
for _, answerChoice := range contextQuestion.AnswerChoices {
answerChoices = append(answerChoices, AnswerChoices{Label: basetypes.NewStringValue(answerChoice.Label)})
}
data.ContextQuestionOptions = contextQuestionOptions
data.AnswerChoices = answerChoices

var blueprintCategories []attr.Value
for _, blueprintCategory := range contextQuestion.BlueprintCategories {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/context_question_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d *ContextQuestionDataSource) Schema(_ context.Context, _ datasource.Schem
MarkdownDescription: "",
Computed: true,
},
"context_question_options": schema.SetNestedAttribute{
"answer_choices": schema.SetNestedAttribute{
MarkdownDescription: "",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/context_question_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccContextQuestionDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "prompt", "what is your prompt?"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "qtype", "QTYPE_SINGLE_SELECT"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "blueprint_categories.0", "BLUEPRINT_BLOB_STORAGE"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "context_question_options.0.label", "tenant-context Option 1"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "answer_choices.0.label", "tenant-context Option 1"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "label", "marketing"),
resource.TestCheckResourceAttr("data.resourcely_context_question.by_series_id", "regex_pattern", "regex"),
),
Expand All @@ -36,7 +36,7 @@ resource "resourcely_context_question" "basic" {
qtype = "QTYPE_SINGLE_SELECT"
scope = "SCOPE_TENANT"
blueprint_categories = ["BLUEPRINT_BLOB_STORAGE"]
context_question_options = [{label: "tenant-context Option 1"}]
answer_choices = [{label: "tenant-context Option 1"}]
label = "marketing"
regex_pattern = "regex"
excluded_blueprint_series = []
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/context_question_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *ContextQuestionResource) Schema(_ context.Context, _ resource.SchemaReq
},
"answer_format": schema.StringAttribute{
MarkdownDescription: "",
Default: stringdefault.StaticString("ANSWER_UNSET"),
Default: stringdefault.StaticString("ANSWER_TEXT"),
Optional: true,
Computed: true,
Validators: []validator.String{
Expand All @@ -104,7 +104,7 @@ func (r *ContextQuestionResource) Schema(_ context.Context, _ resource.SchemaReq
),
},
},
"context_question_options": schema.SetNestedAttribute{
"answer_choices": schema.SetNestedAttribute{
MarkdownDescription: "",
Default: setdefault.StaticValue(types.SetValueMust(types.ObjectType{AttrTypes: map[string]attr.Type{"label": types.StringType}}, nil)),
Optional: true,
Expand Down Expand Up @@ -295,17 +295,17 @@ func (r *ContextQuestionResource) buildCommonFields(ctx context.Context, plan Co
Qtype: plan.Qtype.ValueString(),
AnswerFormat: plan.AnswerFormat.ValueString(),
Scope: plan.Scope.ValueString(),
ContextQuestionOptions: nil,
AnswerChoices: nil,
BlueprintCategories: nil,
RegexPattern: plan.RegexPattern.ValueString(),
ExcludedBlueprintSeries: nil,
}

var contextQuestionOptions []client.ContextQuestionOption
for _, option := range plan.ContextQuestionOptions {
contextQuestionOptions = append(contextQuestionOptions, client.ContextQuestionOption{Label: option.Label.ValueString()})
var answerChoices []client.AnswerChoice
for _, choice := range plan.AnswerChoices {
answerChoices = append(answerChoices, client.AnswerChoice{Label: choice.Label.ValueString()})
}
commonFields.ContextQuestionOptions = contextQuestionOptions
commonFields.AnswerChoices = answerChoices

var blueprintCategories []types.String
_ = plan.BlueprintCategories.ElementsAs(ctx, &blueprintCategories, false)
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/context_question_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccContextQuestionResource_basic(t *testing.T) {
resource.TestCheckResourceAttr("resourcely_context_question.basic", "prompt", "what is your prompt?"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "qtype", "QTYPE_SINGLE_SELECT"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "blueprint_categories.0", "BLUEPRINT_BLOB_STORAGE"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "context_question_options.0.label", "tenant-context Option 1"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "answer_choices.0.label", "tenant-context Option 1"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "label", "marketing"),
resource.TestCheckResourceAttr("resourcely_context_question.basic", "regex_pattern", `regex`),
),
Expand Down Expand Up @@ -89,7 +89,7 @@ resource "resourcely_context_question" "basic" {
qtype = "QTYPE_SINGLE_SELECT"
scope = "SCOPE_TENANT"
blueprint_categories = ["BLUEPRINT_BLOB_STORAGE"]
context_question_options = [{label: "tenant-context Option 1"}]
answer_choices = [{label: "tenant-context Option 1"}]
label = "marketing"
regex_pattern = "regex"
excluded_blueprint_series = []
Expand Down

0 comments on commit a26d73c

Please sign in to comment.