Skip to content

Commit

Permalink
🧹 update query pack upload and assignment example (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Feb 3, 2024
1 parent fe8cbfd commit c6b6b35
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
18 changes: 12 additions & 6 deletions docs/resources/custom_querypack.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,33 @@ provider "mondoo" {
region = "us"
}
variable "mondoo_org" {
description = "Mondoo Organization"
type = string
}
resource "mondoo_space" "my_space" {
name = "My Space Name"
org_id = "your-org-1234567"
org_id = var.mondoo_org
}
variable "my_custom_querypack" {
type = string
default = "/path/to/my-custom-policy.mql.yml"
default = "querypack.mql.yaml"
}
resource "mondoo_custom_querypack" "my_query_pack" {
space_id = mondoo_space.my_space.id
source = var.my_custom_querypack
}
resource "mondoo_querypack_assignments" "space" {
resource "mondoo_querypack_assignment" "space" {
space_id = mondoo_space.my_space.id
policies = [
mondoo_custom_querypack.my_query_pack.mrn # use a uploaded policy mrn
]
querypacks = concat(
mondoo_custom_querypack.my_query_pack.mrns,
[],
)
state = "enabled"
Expand Down
24 changes: 24 additions & 0 deletions examples/resources/mondoo_custom_querypack/querypack.mql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Mondoo, Inc.
# SPDX-License-Identifier: BUSL-1.1

packs:
- uid: terraform-linux
name: Terraform Uploaded Linux Pack
filters:
- asset.family.contains("unix")

queries:
- title: Find all SSH packages that are installed
uid: ssh-packages
mql: |
packages.
where(name == /ssh/)
- title: Get SSH services
uid: ssh-services
mql: |
services.
where(name == /ssh/)
- title: All the SSH config
uid: ssh-config
mql: |
sshd.config.params
18 changes: 12 additions & 6 deletions examples/resources/mondoo_custom_querypack/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ provider "mondoo" {
region = "us"
}

variable "mondoo_org" {
description = "Mondoo Organization"
type = string
}

resource "mondoo_space" "my_space" {
name = "My Space Name"
org_id = "your-org-1234567"
org_id = var.mondoo_org
}

variable "my_custom_querypack" {
type = string
default = "/path/to/my-custom-policy.mql.yml"
default = "querypack.mql.yaml"
}

resource "mondoo_custom_querypack" "my_query_pack" {
space_id = mondoo_space.my_space.id
source = var.my_custom_querypack
}

resource "mondoo_querypack_assignments" "space" {
resource "mondoo_querypack_assignment" "space" {
space_id = mondoo_space.my_space.id

policies = [
mondoo_custom_querypack.my_query_pack.mrn # use a uploaded policy mrn
]
querypacks = concat(
mondoo_custom_querypack.my_query_pack.mrns,
[],
)

state = "enabled"

Expand Down
5 changes: 3 additions & 2 deletions internal/provider/querypack_assignment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
mondoov1 "go.mondoo.com/mondoo-go"
"strings"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (r *queryPackAssignmentResource) Create(ctx context.Context, req resource.C
if err != nil {
resp.Diagnostics.AddError(
"Error creating query pack assignment",
fmt.Sprintf("Error creating query pack assignment: %s", err),
fmt.Sprintf("Error creating query pack assignment: %s\nSpace: %s\nQueryPacks: %s", err, scopeMrn, strings.Join(queryPackMrns, "\n")),
)
return
}
Expand Down Expand Up @@ -200,7 +201,7 @@ func (r *queryPackAssignmentResource) Update(ctx context.Context, req resource.U
if err != nil {
resp.Diagnostics.AddError(
"Error creating query pack assignment",
fmt.Sprintf("Error creating query pack assignment: %s", err),
fmt.Sprintf("Error creating query pack assignment: %s\nSpace: %s\nQueryPacks: %s", err, scopeMrn, strings.Join(queryPackMrns, "\n")),
)
return
}
Expand Down

0 comments on commit c6b6b35

Please sign in to comment.