Skip to content

Commit

Permalink
Merge branch 'main' into as-use-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
zemberdotnet committed Aug 4, 2023
2 parents 8d325ac + 8c6d415 commit 9485e29
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/resources/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ resource "jupiterone_question" "unencrypted_critical_data_stores" {
- `compliance` (Block List) (see [below for nested schema](#nestedblock--compliance))
- `polling_interval` (String) Frequency of automated question evaluation. Defaults to ONE_DAY.
- `query` (Block List) (see [below for nested schema](#nestedblock--query))
- `show_trend` (Boolean) Whether to enable trend data collection. Defaults to false.
- `tags` (List of String)

### Read-Only
Expand Down
3 changes: 3 additions & 0 deletions jupiterone/cassettes/TestQuestion_Config_Errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
version: 2
interactions: []
6 changes: 4 additions & 2 deletions jupiterone/internal/client/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions jupiterone/internal/client/question.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ query GetQuestionById($id: ID!) {
id
title
description
showTrend
pollingInterval
# @genqlient(typename: QuestionQuery)
queries {
Expand Down
11 changes: 11 additions & 0 deletions jupiterone/resource_question.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type QuestionModel struct {
Id types.String `json:"id,omitempty" tfsdk:"id"`
Title types.String `json:"title,omitempty" tfsdk:"title"`
Description types.String `json:"description,omitempty" tfsdk:"description"`
ShowTrend types.Bool `json:"show_trend,omitempty" tfsdk:"show_trend"`
PollingInterval types.String `json:"polling_interval,omitempty" tfsdk:"polling_interval"`
Tags []string `json:"tags,omitempty" tfsdk:"tags"`
Query []*QuestionQueryModel `json:"query,omitempty" tfsdk:"query"`
Expand Down Expand Up @@ -99,6 +100,14 @@ func (*QuestionResource) Schema(ctx context.Context, req resource.SchemaRequest,
"description": schema.StringAttribute{
Required: true,
},
"show_trend": schema.BoolAttribute{
Description: "Whether to enable daily trend data collection. Defaults to false.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
BoolDefaultValuePlanModifier(false),
},
},
"polling_interval": schema.StringAttribute{
Description: "Frequency of automated question evaluation. Defaults to ONE_DAY.",
Computed: true,
Expand Down Expand Up @@ -324,6 +333,7 @@ func (qm *QuestionModel) BuildQuestion() client.QuestionUpdate {
Title: qm.Title.ValueString(),
Description: qm.Description.ValueString(),
Tags: qm.Tags,
ShowTrend: qm.ShowTrend.ValueBool(),
PollingInterval: client.SchedulerPollingInterval(qm.PollingInterval.ValueString()),
}

Expand Down Expand Up @@ -355,6 +365,7 @@ func (qm *QuestionModel) BuildCreateQuestionInput() client.CreateQuestionInput {
Title: qm.Title.ValueString(),
Description: qm.Description.ValueString(),
PollingInterval: client.SchedulerPollingInterval(qm.PollingInterval.ValueString()),
ShowTrend: qm.ShowTrend.ValueBool(),
Tags: qm.Tags,
}

Expand Down
42 changes: 42 additions & 0 deletions jupiterone/resource_question_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package jupiterone
import (
"context"
"fmt"
"regexp"
"strings"
"testing"
"time"

"github.com/Khan/genqlient/graphql"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand All @@ -34,6 +36,7 @@ func TestQuestion_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "title", questionTitle),
resource.TestCheckResourceAttr(resourceName, "description", "Test"),
resource.TestCheckResourceAttr(resourceName, "show_trend", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tf_acc:1"),
resource.TestCheckResourceAttr(resourceName, "query.#", "1"),
Expand All @@ -49,6 +52,7 @@ func TestQuestion_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "title", questionTitle),
resource.TestCheckResourceAttr(resourceName, "description", "Test"),
resource.TestCheckResourceAttr(resourceName, "show_trend", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tf_acc:2"),
resource.TestCheckResourceAttr(resourceName, "query.#", "1"),
Expand Down Expand Up @@ -85,6 +89,7 @@ func TestQuestion_BasicImport(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "title", questionTitle),
resource.TestCheckResourceAttr(resourceName, "description", "Test"),
resource.TestCheckResourceAttr(resourceName, "show_trend", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tf_acc:1"),
resource.TestCheckResourceAttr(resourceName, "query.#", "1"),
Expand All @@ -97,6 +102,25 @@ func TestQuestion_BasicImport(t *testing.T) {
})
}

func TestQuestion_Config_Errors(t *testing.T) {
ctx := context.TODO()

recordingClient, _, cleanup := setupTestClients(ctx, t)
defer cleanup(t)

questionTitle := acctest.RandomWithPrefix("tf-provider-test-question")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(recordingClient),
Steps: []resource.TestStep{
{
Config: testQuestionBasicConfigWithShowTrend(questionTitle, "INVALID_SHOW_TREND"),
ExpectError: regexp.MustCompile(`Inappropriate value for attribute "show_trend"`),
},
},
})
}

// createTestQuestion directly calls the client to create a question directly
// for import or other tests. Because the id must be returned, this must
// called with the recorder client.
Expand Down Expand Up @@ -200,6 +224,24 @@ func questionDestroyHelper(ctx context.Context, s *terraform.State, qlient graph
return nil
}

func testQuestionBasicConfigWithShowTrend(rName string, showTrend string) string {
return fmt.Sprintf(`
provider "jupiterone" {}
resource "jupiterone_question" "test" {
title = %q
description = "Test"
show_trend = %q
query {
name = "query0"
query = "Find DataStore with classification=('critical' or 'sensitive' or 'confidential' or 'restricted') and encrypted!=true"
version = "v1"
}
}
`, rName, showTrend)
}

func testQuestionBasicConfigWithTags(rName string, tag string) string {
return fmt.Sprintf(`
provider "jupiterone" {}
Expand Down

0 comments on commit 9485e29

Please sign in to comment.