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

APP-15799 - Add resourceGroupId to integration and dashboard resources #226

Merged
merged 5 commits into from
Nov 27, 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ scripts/get_current_schema.bash
make generate-client
```

**NOTE**: If you are getting errors like this: `for is only applicable to operations and arguments`, check whether formatting has changed in the gql file in question. If the formatting has changed, you may be running into the issue documented in this thread: https://github.com/Khan/genqlient/issues/149#issuecomment-958150171

---

### Testing

In order to test the provider, you can simply run `make testacc`. Pre-recorded
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ resource "jupiterone_widget" "plot-compliance-per-control" {
- `name` (String) The name of the dashboard.
- `type` (String) The type of the dashboard.

### Optional

- `resource_group_id` (String) The ID of the resource group that the dashboard belongs to.

### Read-Only

- `id` (String) The ID of this resource.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ resource "jupiterone_integration" "example_custom_integration" {
- `description` (String) The description of the integration instance.
- `ingestion_sources_overrides` (List of Object) Overrides for ingestion sources. (see [below for nested schema](#nestedatt--ingestion_sources_overrides))
- `polling_interval_cron_expression` (String) The cron expression for the polling interval as a JSON string.
- `resource_group_id` (String) The ID of the resource group to which the integration instance belongs.
- `source_integration_instance_id` (String) The ID of the source integration instance.

### Read-Only
Expand Down
24 changes: 12 additions & 12 deletions jupiterone/cassettes/TestDashboard_Basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ interactions:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 380
content_length: 410
transfer_encoding: []
trailer: {}
host: graphql.us.jupiterone.io
remote_addr: ""
request_uri: ""
body: '{"query":"\nmutation CreateDashboard ($input: CreateInsightsDashboardInput!) {\n\tcreateDashboard(input: $input) {\n\t\tname\n\t\tid\n\t}\n}\n","variables":{"input":{"name":"tf-provider-test-dashboard","type":"Account","userIds":null,"groupIds":null,"widgets":null,"published":false,"publishedToUserIds":null,"publishedToGroupIds":null,"ttd":0}},"operationName":"CreateDashboard"}'
body: '{"query":"\nmutation CreateDashboard ($input: CreateInsightsDashboardInput!) {\n\tcreateDashboard(input: $input) {\n\t\tname\n\t\tid\n\t}\n}\n","variables":{"input":{"name":"tf-provider-test-dashboard","type":"Account","userIds":null,"groupIds":null,"widgets":null,"published":false,"publishedToUserIds":null,"publishedToGroupIds":null,"ttd":0,"resourceGroupId":"rg-123456"}},"operationName":"CreateDashboard"}'
form: {}
headers:
Cache-Control:
Expand All @@ -30,7 +30,7 @@ interactions:
content_length: 111
uncompressed: false
body: |
{"data":{"createDashboard":{"name":"tf-provider-test-dashboard","id":"86a338a3-7783-4fdb-8c68-347aa4d811fb"}}}
{"data":{"createDashboard":{"name":"tf-provider-test-dashboard","id":"bed628b8-6c68-4f0d-9f6d-b8bbb4580ef3"}}}
headers:
Access-Control-Allow-Credentials:
- "true"
Expand Down Expand Up @@ -78,19 +78,19 @@ interactions:
- "0"
status: 200 OK
code: 200
duration: 662.687334ms
duration: 714.17575ms
- id: 1
request:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 229
content_length: 250
transfer_encoding: []
trailer: {}
host: graphql.us.jupiterone.io
remote_addr: ""
request_uri: ""
body: '{"query":"\nquery GetDashboard ($dashboardId: String!) {\n\tgetDashboard(dashboardId: $dashboardId) {\n\t\tid\n\t\tname\n\t}\n}\n","variables":{"dashboardId":"86a338a3-7783-4fdb-8c68-347aa4d811fb"},"operationName":"GetDashboard"}'
body: '{"query":"\nquery GetDashboard ($dashboardId: String!) {\n\tgetDashboard(dashboardId: $dashboardId) {\n\t\tid\n\t\tname\n\t\tresourceGroupId\n\t}\n}\n","variables":{"dashboardId":"bed628b8-6c68-4f0d-9f6d-b8bbb4580ef3"},"operationName":"GetDashboard"}'
form: {}
headers:
Cache-Control:
Expand All @@ -105,15 +105,15 @@ interactions:
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 108
content_length: 138
uncompressed: false
body: |
{"data":{"getDashboard":{"id":"86a338a3-7783-4fdb-8c68-347aa4d811fb","name":"tf-provider-test-dashboard"}}}
{"data":{"getDashboard":{"id":"bed628b8-6c68-4f0d-9f6d-b8bbb4580ef3","name":"tf-provider-test-dashboard","resourceGroupId":"rg-123456"}}}
headers:
Access-Control-Allow-Credentials:
- "true"
Content-Length:
- "108"
- "138"
Content-Security-Policy:
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
Content-Type:
Expand Down Expand Up @@ -156,7 +156,7 @@ interactions:
- "0"
status: 200 OK
code: 200
duration: 662.471625ms
duration: 408.778792ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -168,7 +168,7 @@ interactions:
host: graphql.us.jupiterone.io
remote_addr: ""
request_uri: ""
body: '{"query":"\nmutation DeleteDashboard ($dashboardId: String!) {\n\tdeleteDashboard(dashboardId: $dashboardId) {\n\t\tsuccess\n\t}\n}\n","variables":{"dashboardId":"86a338a3-7783-4fdb-8c68-347aa4d811fb"},"operationName":"DeleteDashboard"}'
body: '{"query":"\nmutation DeleteDashboard ($dashboardId: String!) {\n\tdeleteDashboard(dashboardId: $dashboardId) {\n\t\tsuccess\n\t}\n}\n","variables":{"dashboardId":"bed628b8-6c68-4f0d-9f6d-b8bbb4580ef3"},"operationName":"DeleteDashboard"}'
form: {}
headers:
Cache-Control:
Expand Down Expand Up @@ -234,4 +234,4 @@ interactions:
- "0"
status: 200 OK
code: 200
duration: 729.556542ms
duration: 455.243375ms
22 changes: 11 additions & 11 deletions jupiterone/internal/client/dashboard.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ query GetDashboard($dashboardId: String!) {
getDashboard(dashboardId: $dashboardId) {
id
name
resourceGroupId
}
}

# @genqlient(for: "CreateInsightsDashboardInput.layouts", omitempty: true, pointer:true)
# @genqlient(for: "CreateInsightsDashboardInput.category", omitempty: true)
# @genqlient(for: "CreateInsightsDashboardInput.dashboardId", omitempty: true)
# @genqlient(for: "CreateInsightsDashboardInput.resourceGroupId", omitempty: true)
mutation CreateDashboard(
$input: CreateInsightsDashboardInput!
) {
createDashboard(
input: $input
) {
name
id
}
$input: CreateInsightsDashboardInput!
) {
createDashboard(input: $input) {
name
id
}
}

mutation DeleteDashboard($dashboardId: String!) {
Expand All @@ -28,10 +28,10 @@ mutation DeleteDashboard($dashboardId: String!) {
# @genqlient(for: "PatchInsightsDashboardInput.layouts", omitempty: true, pointer:true)
# @genqlient(for: "PatchInsightsDashboardInput.category", omitempty: true)
mutation UpdateDashboard(
$input: PatchInsightsDashboardInput!
) {
$input: PatchInsightsDashboardInput!
) {
patchDashboard(input: $input) {
id
name
}
}
}
34 changes: 32 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.

11 changes: 6 additions & 5 deletions jupiterone/internal/client/integration.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ query GetIntegrationInstance($id: String!) {
}
sourceIntegrationInstanceId
collectorPoolId
resourceGroupId
pollingIntervalCronExpression {
hour
dayOfWeek
Expand All @@ -26,7 +27,8 @@ query GetIntegrationInstance($id: String!) {
# @genqlient(for: "CreateIntegrationInstanceInput.offsiteComplete", omitempty: true)
# @genqlient(for: "CreateIntegrationInstanceInput.ingestionSourcesOverrides", omitempty: true)
mutation CreateIntegrationInstance(
$instance: CreateIntegrationInstanceInput!) {
$instance: CreateIntegrationInstanceInput!
) {
createIntegrationInstance(instance: $instance) {
id
name
Expand Down Expand Up @@ -54,8 +56,9 @@ mutation CreateIntegrationInstance(
# @genqlient(for: "UpdateIntegrationInstanceInput.offsiteComplete", omitempty: true)
# @genqlient(for: "UpdateIntegrationInstanceInput.ingestionSourcesOverrides", omitempty: true)
mutation UpdateIntegrationInstance(
$id: String!,
$update: UpdateIntegrationInstanceInput!) {
$id: String!
$update: UpdateIntegrationInstanceInput!
) {
updateIntegrationInstance(id: $id, update: $update) {
id
name
Expand All @@ -82,5 +85,3 @@ mutation DeleteIntegrationInstance($id: String!) {
success
}
}


21 changes: 14 additions & 7 deletions jupiterone/resource_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func NewDashboard() resource.Resource {
}

type DashboardModel struct {
Id types.String `json:"id,omitempty" tfsdk:"id"`
Name types.String `json:"name,omitempty" tfsdk:"name"`
Type types.String `json:"type,omitempty" tfsdk:"type"`
Id types.String `json:"id,omitempty" tfsdk:"id"`
Name types.String `json:"name,omitempty" tfsdk:"name"`
Type types.String `json:"type,omitempty" tfsdk:"type"`
ResourceGroupId types.String `json:"resource_group_id" tfsdk:"resource_group_id"`
}

func NewDashboardResource() resource.Resource {
Expand Down Expand Up @@ -176,6 +177,10 @@ func (*DashboardResource) Schema(ctx context.Context, req resource.SchemaRequest
stringvalidator.OneOf(DashboardTypes...),
},
},
"resource_group_id": schema.StringAttribute{
Optional: true,
Description: "The ID of the resource group that the dashboard belongs to.",
},
},
}
}
Expand Down Expand Up @@ -216,17 +221,19 @@ func (r *DashboardResource) Update(ctx context.Context, req resource.UpdateReque

func (r *DashboardModel) BuildCreateInsightsDashboardInput() (client.CreateInsightsDashboardInput, error) {
dashboard := client.CreateInsightsDashboardInput{
Name: r.Name.ValueString(),
Type: client.BoardType(r.Type.ValueString()),
Name: r.Name.ValueString(),
Type: client.BoardType(r.Type.ValueString()),
ResourceGroupId: r.ResourceGroupId.ValueString(),
}

return dashboard, nil
}

func (r *DashboardModel) BuildPatchInsightsDashboardInput() (client.PatchInsightsDashboardInput, error) {
dashboard := client.PatchInsightsDashboardInput{
Name: r.Name.ValueString(),
DashboardId: r.Id.ValueString(),
Name: r.Name.ValueString(),
DashboardId: r.Id.ValueString(),
ResourceGroupId: r.ResourceGroupId.ValueString(),
}

return dashboard, nil
Expand Down
2 changes: 2 additions & 0 deletions jupiterone/resource_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestDashboard_BasicImport(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "name", dashboardName),
resource.TestCheckResourceAttr(resourceName, "type", string(dashboardType)),
resource.TestCheckResourceAttr(resourceName, "resource_group_id", "rg-123456"),
),
},
},
Expand Down Expand Up @@ -172,6 +173,7 @@ func testDashboardBasicConfig(rName string) string {
resource "jupiterone_dashboard" "test" {
name = %q
type = "Account"
resource_group_id = "rg-123456"
}
`, rName)
}
Loading
Loading