Skip to content

Commit 5d9791e

Browse files
feat: implement support for log management resource and data source]
Adds `aquasec_log_management` resource with full CRUD and `aquasec_log_managements` data source, wiring them into the provider with client API, tests, docs, and examples. - **Provider**: - Registers `aquasec_log_management` resource and `aquasec_log_managements` data source in `aquasec/provider.go`. - **Resource: `aquasec_log_management`**: - Implements Create/Read/Update/Delete in `aquasec/resource_log_management.go` for multiple backends (e.g., CloudWatch, Splunk, Syslog, Azure, etc.). - Sets `source` to fixed `"aquasec"`; handles sensitive fields and diff suppression for `key`. - **Data Source: `aquasec_log_managements`**: - Adds read-only lookup by `name` in `aquasec/data_log_management.go` with comprehensive computed attributes. - **Client**: - Introduces `client/log_management.go` with `LogService` model and API methods: `GetLogManagement`, `GetLogManagements`, `CreateLogManagement`, `UpdateLogManagement`, `DeleteLogManagement`. - **Tests**: - Adds acceptance tests for resource and data source (`aquasec/resource_log_management_test.go`, `aquasec/data_log_management_test.go`). - **Docs & Examples**: - Adds docs for resource and data source plus example configurations under `docs/...` and `examples/...`.
1 parent 00abd78 commit 5d9791e

File tree

10 files changed

+1385
-0
lines changed

10 files changed

+1385
-0
lines changed

aquasec/data_log_management.go

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
package aquasec
2+
3+
import (
4+
"context"
5+
6+
"github.com/aquasecurity/terraform-provider-aquasec/client"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
)
10+
11+
func dataLogManagement() *schema.Resource {
12+
return &schema.Resource{
13+
ReadContext: dataLogManagementRead,
14+
Schema: map[string]*schema.Schema{
15+
"name": {
16+
Type: schema.TypeString,
17+
Description: "The name of the log-management configuration to look up.",
18+
Required: true,
19+
},
20+
"enable": {
21+
Type: schema.TypeBool,
22+
Description: "Indicates whether the log-management configuration is enabled (true) or disabled (false).",
23+
Computed: true,
24+
},
25+
"audit_filter": {
26+
Type: schema.TypeString,
27+
Description: "The audit filter expression applied by the log-management service to narrow down logs.",
28+
Computed: true,
29+
},
30+
"url": {
31+
Type: schema.TypeString,
32+
Description: "The endpoint URL of the log-management service, where logs are sent or retrieved from.",
33+
Computed: true,
34+
},
35+
"network": {
36+
Type: schema.TypeString,
37+
Description: "Optional network or connectivity identifier used by the log-management service.",
38+
Computed: true,
39+
},
40+
"user": {
41+
Type: schema.TypeString,
42+
Description: "Username used for authentication with the log-management service (sensitive).",
43+
Computed: true,
44+
},
45+
"password": {
46+
Type: schema.TypeString,
47+
Description: "Password used for authentication with the log-management service (sensitive).",
48+
Computed: true,
49+
Sensitive: true,
50+
},
51+
"token": {
52+
Type: schema.TypeString,
53+
Description: "Bearer token used for authentication with the log-management service (sensitive).",
54+
Computed: true,
55+
Sensitive: true,
56+
},
57+
"workspace": {
58+
Type: schema.TypeString,
59+
Description: "Workspace or tenant identifier within the log-management service.",
60+
Computed: true,
61+
},
62+
"key": {
63+
Type: schema.TypeString,
64+
Description: "API key or secret key generated for this log-management configuration (sensitive, may be generated by the service).",
65+
Computed: true,
66+
Sensitive: true,
67+
},
68+
"verify_cert": {
69+
Type: schema.TypeBool,
70+
Description: "Whether SSL/TLS certificate verification is enabled when connecting to the service.",
71+
Computed: true,
72+
},
73+
"ca_cert": {
74+
Type: schema.TypeString,
75+
Description: "Custom CA certificate used to verify the log-management service’s TLS certificate (sensitive).",
76+
Computed: true,
77+
Sensitive: true,
78+
},
79+
"enable_alphanumeric_sorting": {
80+
Type: schema.TypeBool,
81+
Description: "When enabled, logs are sorted alphanumerically before being processed.",
82+
Computed: true,
83+
},
84+
"index": {
85+
Type: schema.TypeString,
86+
Description: "Index name or bucket name where the logs are stored or retrieved from in the service.",
87+
Computed: true,
88+
},
89+
"source": {
90+
Type: schema.TypeString,
91+
Description: "Fixed source identifier used by the log-management service; always set to “aquasec”.",
92+
Computed: true,
93+
},
94+
"source_type": {
95+
Type: schema.TypeString,
96+
Description: "The type or classification of the log source as recognized by the service.",
97+
Computed: true,
98+
},
99+
"authentication_option": {
100+
Type: schema.TypeString,
101+
Description: "The authentication method chosen for the service (e.g., API key, OAuth).",
102+
Computed: true,
103+
},
104+
"project_id": {
105+
Type: schema.TypeString,
106+
Description: "Cloud project or subscription identifier under which logs are collected.",
107+
Computed: true,
108+
},
109+
"log_name": {
110+
Type: schema.TypeString,
111+
Description: "Name of the log stream or log source in the service.",
112+
Computed: true,
113+
},
114+
"credential_jsons": {
115+
Type: schema.TypeString,
116+
Description: "JSON-encoded credentials for service-account style authentication (sensitive).",
117+
Computed: true,
118+
Sensitive: true,
119+
},
120+
"external_id": {
121+
Type: schema.TypeString,
122+
Description: "External identifier used for cross-account or cross-tenant authentication.",
123+
Computed: true,
124+
},
125+
"role_arn": {
126+
Type: schema.TypeString,
127+
Description: "ARN of the IAM role assumed when interacting with the log-management service.",
128+
Computed: true,
129+
},
130+
"region": {
131+
Type: schema.TypeString,
132+
Description: "Cloud region identifier where log ingestion or retrieval takes place.",
133+
Computed: true,
134+
},
135+
"loggroup": {
136+
Type: schema.TypeString,
137+
Description: "Log-group or collection name within the service where logs are grouped.",
138+
Computed: true,
139+
},
140+
"keyid": {
141+
Type: schema.TypeString,
142+
Description: "Identifier of the key or credential used by the log-management service.",
143+
Computed: true,
144+
},
145+
"event_bridge_arn": {
146+
Type: schema.TypeString,
147+
Description: "ARN of the EventBridge rule used to deliver logs into the service.",
148+
Computed: true,
149+
},
150+
"rule": {
151+
Type: schema.TypeString,
152+
Description: "Routing or processing rule name defined for this log-management configuration.",
153+
Computed: true,
154+
},
155+
"stream_name": {
156+
Type: schema.TypeString,
157+
Description: "Name of the log stream or channel within the service where log events appear.",
158+
Computed: true,
159+
},
160+
"tenant_id": {
161+
Type: schema.TypeString,
162+
Description: "Tenant or directory ID used in multi-tenant log-management environments.",
163+
Computed: true,
164+
},
165+
"client_id": {
166+
Type: schema.TypeString,
167+
Description: "Client ID used in OAuth or service-account authentication with the service.",
168+
Computed: true,
169+
},
170+
"client_secret": {
171+
Type: schema.TypeString,
172+
Description: "Client secret associated with the client ID for authentication (sensitive).",
173+
Computed: true,
174+
Sensitive: true,
175+
},
176+
"cloud": {
177+
Type: schema.TypeString,
178+
Description: "Cloud provider identifier (for example ‘aws’, ‘azure’, ‘gcp’) associated with this log-management configuration.",
179+
Computed: true,
180+
},
181+
},
182+
}
183+
}
184+
185+
func dataLogManagementRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
186+
ac := m.(*client.Client)
187+
var diags diag.Diagnostics
188+
189+
name := d.Get("name").(string)
190+
if name == "" {
191+
return diag.Errorf("attribute \"name\" must be set")
192+
}
193+
194+
logMgmt, err := ac.GetLogManagements()
195+
if err != nil {
196+
return diag.FromErr(err)
197+
}
198+
199+
service, ok := (*logMgmt)[name]
200+
if !ok {
201+
return diag.Errorf("log management %q not found", name)
202+
}
203+
204+
if service.Name == "" {
205+
service.Name = name
206+
}
207+
208+
d.SetId(service.Name)
209+
_ = d.Set("name", service.Name)
210+
_ = d.Set("enable", service.Enable)
211+
_ = d.Set("audit_filter", service.AuditFilter)
212+
_ = d.Set("url", service.Url)
213+
_ = d.Set("network", service.Network)
214+
_ = d.Set("user", service.User)
215+
_ = d.Set("password", service.Password)
216+
_ = d.Set("token", service.Token)
217+
_ = d.Set("workspace", service.Workspace)
218+
_ = d.Set("key", service.Key)
219+
_ = d.Set("verify_cert", service.VerifyCert)
220+
_ = d.Set("ca_cert", service.CaCert)
221+
_ = d.Set("enable_alphanumeric_sorting", service.EnableAlphanumericSorting)
222+
_ = d.Set("index", service.Index)
223+
_ = d.Set("source", service.Source)
224+
_ = d.Set("source_type", service.SourceType)
225+
_ = d.Set("authentication_option", service.AuthenticationOption)
226+
_ = d.Set("project_id", service.ProjectId)
227+
_ = d.Set("log_name", service.LogName)
228+
_ = d.Set("credential_jsons", service.CredentialJsons)
229+
_ = d.Set("external_id", service.ExternalId)
230+
_ = d.Set("role_arn", service.RoleArn)
231+
_ = d.Set("region", service.Region)
232+
_ = d.Set("loggroup", service.LogGroup)
233+
_ = d.Set("keyid", service.KeyId)
234+
_ = d.Set("event_bridge_arn", service.EventBridgeArn)
235+
_ = d.Set("rule", service.Rule)
236+
_ = d.Set("stream_name", service.StreamName)
237+
_ = d.Set("tenant_id", service.TenantId)
238+
_ = d.Set("client_id", service.ClientId)
239+
_ = d.Set("client_secret", service.ClientSecret)
240+
_ = d.Set("cloud", service.Cloud)
241+
242+
return diags
243+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package aquasec
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAquasecDataSourceLogManagement(t *testing.T) {
12+
t.Parallel()
13+
name := "CloudWatch"
14+
key := os.Getenv("AWS_SECRET_ACCESS_KEY")
15+
keyid := os.Getenv("AWS_ACCESS_KEY_ID")
16+
17+
resource.Test(t, resource.TestCase{
18+
PreCheck: func() { testAccPreCheck(t) },
19+
Providers: testAccProviders,
20+
Steps: []resource.TestStep{
21+
{
22+
Config: testAccCheckLogManagementDataSource(name, key, keyid),
23+
Check: resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttr("data.aquasec_log_managements.logmanagement", "name", "CloudWatch"),
25+
resource.TestCheckResourceAttr("data.aquasec_log_managements.logmanagement", "enable", "false"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
func testAccCheckLogManagementDataSource(name, key, keyid string) string {
33+
return fmt.Sprintf(`
34+
resource "aquasec_log_management" "logmanagement" {
35+
name = "%s"
36+
region = "us-west-1"
37+
loggroup = "terraform-provider-log-group"
38+
key = "%s"
39+
keyid = "%s"
40+
enable = true
41+
`, name, key, keyid) + `
42+
}
43+
44+
data "aquasec_log_managements" "logmanagement" {
45+
name = "CloudWatch"
46+
}`
47+
}

aquasec/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func Provider(v string) *schema.Provider {
143143
"aquasec_assurance_custom_script": resourceAssuranceScript(),
144144
"aquasec_aqua_api_key": resourceAPIKey(),
145145
"aquasec_scanner_group": resourceScannerGroup(),
146+
"aquasec_log_management": resourceLogManagement(),
146147
},
147148
DataSourcesMap: map[string]*schema.Resource{
148149
"aquasec_users": dataSourceUsers(),
@@ -178,6 +179,7 @@ func Provider(v string) *schema.Provider {
178179
"aquasec_aqua_api_keys": dataSourceAPIKeys(),
179180
"aquasec_scanner_group": dataSourceScannerGroup(),
180181
"aquasec_vmware_assurance_policy": dataVmwareAssurancePolicy(),
182+
"aquasec_log_managements": dataLogManagement(),
181183
},
182184
ConfigureContextFunc: providerConfigure,
183185
}

0 commit comments

Comments
 (0)