From b6dfd0acc8520c56e557b29773aa64645faa7f3a Mon Sep 17 00:00:00 2001 From: trend-lucas-wu <153708950+trend-lucas-wu@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:59:33 +0800 Subject: [PATCH] add create cluster grouping feature (#6) --- docs/resources/container_cluster.md | 2 ++ .../resources/visionone_container_cluster/resource.tf | 1 + .../trendmicro/container_security/resources/cluster.go | 10 +++++++++- pkg/dto/request.go | 1 + pkg/dto/resource.go | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/resources/container_cluster.md b/docs/resources/container_cluster.md index 3db0228..0d46e16 100644 --- a/docs/resources/container_cluster.md +++ b/docs/resources/container_cluster.md @@ -19,6 +19,7 @@ resource "visionone_container_cluster" "example_cluster" { description = "This is a sample cluster" resource_id = "arn:aws:eks:xxx:xxx:cluster/xxx" policy_id = "LogOnlyPolicy-xxx" + group_id = "00000000-0000-0000-0000-000000000000" runtime_security_enabled = true vulnerability_scan_enabled = true namespaces = ["kube-system"] @@ -98,6 +99,7 @@ resource "helm_release" "trendmicro" { ### Required +- `group_id` (String) The ID of the group associated with the cluster. To get the group ID, go to Container Security > Container Inventory on the Trend Vision One console. - `name` (String) The name of the cluster. ### Optional diff --git a/examples/resources/visionone_container_cluster/resource.tf b/examples/resources/visionone_container_cluster/resource.tf index e12fd0d..899dbf5 100644 --- a/examples/resources/visionone_container_cluster/resource.tf +++ b/examples/resources/visionone_container_cluster/resource.tf @@ -3,6 +3,7 @@ resource "visionone_container_cluster" "example_cluster" { description = "This is a sample cluster" resource_id = "arn:aws:eks:xxx:xxx:cluster/xxx" policy_id = "LogOnlyPolicy-xxx" + group_id = "00000000-0000-0000-0000-000000000000" runtime_security_enabled = true vulnerability_scan_enabled = true namespaces = ["kube-system"] diff --git a/internal/trendmicro/container_security/resources/cluster.go b/internal/trendmicro/container_security/resources/cluster.go index ea67732..64a1cb2 100644 --- a/internal/trendmicro/container_security/resources/cluster.go +++ b/internal/trendmicro/container_security/resources/cluster.go @@ -116,6 +116,13 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re MarkdownDescription: "Last time of the cluster was evaluated against the policy rules.", Computed: true, }, + "group_id": schema.StringAttribute{ + MarkdownDescription: "The ID of the group associated with the cluster. To get the group ID, go to Container Security > Container Inventory on the Trend Vision One console.", + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, "namespaces": schema.SetAttribute{ ElementType: types.StringType, MarkdownDescription: "The namespaces of kubernetes you want to exclude from scanning. \nAccepted values: `calico-system`, `istio-system`, `kube-system`, `openshift*` Default value: `kube-system`", @@ -214,7 +221,8 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest tflog.Debug(ctx, fmt.Sprintf("Create new Cluster plan: %+v", plan)) data := dto.CreateClusterRequest{ - Name: plan.Name.ValueString(), + Name: plan.Name.ValueString(), + GroupId: plan.GroupId.ValueString(), } if !plan.Description.IsNull() { data.Description = plan.Description.ValueString() diff --git a/pkg/dto/request.go b/pkg/dto/request.go index 82d7adf..0f9eeba 100644 --- a/pkg/dto/request.go +++ b/pkg/dto/request.go @@ -5,6 +5,7 @@ type CreateClusterRequest struct { Description string `json:"description"` PolicyId string `json:"policyId"` ResourceId string `json:"resourceId"` + GroupId string `json:"groupId"` } type CreateRulesetRequest struct { diff --git a/pkg/dto/resource.go b/pkg/dto/resource.go index a8ff66f..2a0760b 100644 --- a/pkg/dto/resource.go +++ b/pkg/dto/resource.go @@ -2,6 +2,7 @@ package dto import ( "errors" + "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -25,6 +26,7 @@ type ClusterResourceModel struct { CreatedDateTime types.String `tfsdk:"created_date_time"` UpdatedDateTime types.String `tfsdk:"updated_date_time"` LastEvaluatedDateTime types.String `tfsdk:"last_evaluated_date_time"` + GroupId types.String `tfsdk:"group_id"` Namespaces types.Set `tfsdk:"namespaces"` RuntimeSecurityEnabled types.Bool `tfsdk:"runtime_security_enabled"` VulnerabilityScanEnabled types.Bool `tfsdk:"vulnerability_scan_enabled"`