From df3c808f7b92e60a75dbda022c8b16e21f93752a Mon Sep 17 00:00:00 2001 From: mattJsonar Date: Thu, 23 May 2024 11:42:54 -0700 Subject: [PATCH 1/4] Remove validation for audit_type --- dsfhub/resource_log_aggregator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsfhub/resource_log_aggregator.go b/dsfhub/resource_log_aggregator.go index 0710a05..6026a7b 100644 --- a/dsfhub/resource_log_aggregator.go +++ b/dsfhub/resource_log_aggregator.go @@ -72,7 +72,7 @@ func resourceLogAggregator() *schema.Resource { Required: false, Optional: true, Default: nil, - ValidateFunc: validation.StringInSlice([]string{"BIGQUERY", "BIGTABLE", "BUCKET", "MSSQL", "MYSQL", "POSTGRESQL", "SPANNER"}, false), + // ValidateFunc: validation.StringInSlice([]string{"BIGQUERY", "BIGTABLE", "BUCKET", "MSSQL", "MYSQL", "POSTGRESQL", "SPANNER"}, false), }, "available_regions": { Type: schema.TypeString, From 189b9f85bd129e85e4ccd9493cc0df2ecdf6f262 Mon Sep 17 00:00:00 2001 From: mattJsonar Date: Fri, 24 May 2024 13:51:44 -0700 Subject: [PATCH 2/4] Enable audit directly on slow_query log aggregators --- dsfhub/resource_common.go | 9 ++++ dsfhub/resource_log_aggregator.go | 56 ++++++++++++++++++------ dsfhub/resource_log_aggregator_schema.go | 6 +++ 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/dsfhub/resource_common.go b/dsfhub/resource_common.go index 843e0fc..9ee73dc 100644 --- a/dsfhub/resource_common.go +++ b/dsfhub/resource_common.go @@ -386,6 +386,15 @@ func getSchema() AssetSchema { return assetSchema } +func contains(l []string, x string) bool { + for _, a := range l { + if a == x { + return true + } + } + return false +} + // ConnectionData resource hash functions func resourceConnectionDataAmazonSecretHash(v interface{}) int { var buf bytes.Buffer diff --git a/dsfhub/resource_log_aggregator.go b/dsfhub/resource_log_aggregator.go index 6026a7b..a0d1b69 100644 --- a/dsfhub/resource_log_aggregator.go +++ b/dsfhub/resource_log_aggregator.go @@ -636,23 +636,51 @@ func resourceLogAggregatorCreate(d *schema.ResourceData, m interface{}) error { d.SetId(logAggregatorId) auditPullEnabled := d.Get("audit_pull_enabled").(bool) + auditType := d.Get("audit_type").(string) + assetId := d.Get("asset_id").(string) parentAssetId := d.Get("parent_asset_id") - if parentAssetId != nil && auditPullEnabled == true { + + if auditPullEnabled { wait := 6 * time.Second - parentAssetId := d.Get("parent_asset_id").(string) - log.Printf("[INFO] Disabling and enabling audit for DSF data source parentAssetId: %s \n", parentAssetId) - _, err1 := client.DisableAuditDSFDataSource(parentAssetId) - if err1 != nil { - log.Printf("[INFO] Error disabling audit for parentAssetId: %s\n", parentAssetId) - return err1 - } - time.Sleep(wait) - _, err2 := client.EnableAuditDSFDataSource(parentAssetId) - if err2 != nil { - log.Printf("[INFO] Error enabling audit for parentAssetId: %s\n", parentAssetId) - return err2 + + // if using one of slow_query audit types, enable audit on log aggregator + if contains(slowQueryAuditTypes, auditType) { + log.Printf("[INFO] Disabling and enabling audit for DSF data source assetId: %s \n", assetId) + + _, err1 := client.DisableAuditDSFDataSource(assetId) + if err1 != nil { + log.Printf("[INFO] Error disabling audit for assetId: %s\n", assetId) + return err1 + } + time.Sleep(wait) + + _, err2 := client.EnableAuditDSFDataSource(assetId) + if err2 != nil { + log.Printf("[INFO] Error enabling audit for assetId: %s\n", assetId) + return err2 + } + time.Sleep(wait) + // if not, enable audit against parent + } else if parentAssetId != nil { + parentAssetId := d.Get("parent_asset_id").(string) + + log.Printf("[INFO] Disabling and enabling audit for DSF data source parentAssetId: %s \n", parentAssetId) + _, err1 := client.DisableAuditDSFDataSource(parentAssetId) + if err1 != nil { + log.Printf("[INFO] Error disabling audit for parentAssetId: %s\n", parentAssetId) + return err1 + } + time.Sleep(wait) + + _, err2 := client.EnableAuditDSFDataSource(parentAssetId) + if err2 != nil { + log.Printf("[INFO] Error enabling audit for parentAssetId: %s\n", parentAssetId) + return err2 + } + time.Sleep(wait) } - time.Sleep(wait) + + } // Set the rest of the state from the resource read diff --git a/dsfhub/resource_log_aggregator_schema.go b/dsfhub/resource_log_aggregator_schema.go index 317cd66..06e3074 100644 --- a/dsfhub/resource_log_aggregator_schema.go +++ b/dsfhub/resource_log_aggregator_schema.go @@ -161,3 +161,9 @@ var requiredLogAggregatorJson = `{ } } }` + +var slowQueryAuditTypes = []string{ + "AWS_RDS_AURORA_MYSQL_SLOW", + "AWS_RDS_MYSQL_SLOW", + "AWS_NEPTUNE_SLOW", +}; From a4b0536b758ea575f84bef6405e0e1130b7d56f6 Mon Sep 17 00:00:00 2001 From: mattJsonar Date: Fri, 24 May 2024 14:02:16 -0700 Subject: [PATCH 3/4] formatting --- dsfhub/resource_log_aggregator.go | 17 ++++++++--------- dsfhub/resource_log_aggregator_schema.go | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/dsfhub/resource_log_aggregator.go b/dsfhub/resource_log_aggregator.go index a0d1b69..1226fed 100644 --- a/dsfhub/resource_log_aggregator.go +++ b/dsfhub/resource_log_aggregator.go @@ -67,11 +67,11 @@ func resourceLogAggregator() *schema.Resource { Computed: true, }, "audit_type": { - Type: schema.TypeString, - Description: "Used to indicate what mechanism should be used to fetch logs on systems supporting multiple ways to get logs, see asset specific documentation for details. Example: \"BIGQUERY\",\"BIGTABLE\",\"BUCKET\",\"MSSQL\",\"MYSQL\",\"POSTGRESQL\",\"SPANNER\"", - Required: false, - Optional: true, - Default: nil, + Type: schema.TypeString, + Description: "Used to indicate what mechanism should be used to fetch logs on systems supporting multiple ways to get logs, see asset specific documentation for details. Example: \"BIGQUERY\",\"BIGTABLE\",\"BUCKET\",\"MSSQL\",\"MYSQL\",\"POSTGRESQL\",\"SPANNER\"", + Required: false, + Optional: true, + Default: nil, // ValidateFunc: validation.StringInSlice([]string{"BIGQUERY", "BIGTABLE", "BUCKET", "MSSQL", "MYSQL", "POSTGRESQL", "SPANNER"}, false), }, "available_regions": { @@ -646,21 +646,21 @@ func resourceLogAggregatorCreate(d *schema.ResourceData, m interface{}) error { // if using one of slow_query audit types, enable audit on log aggregator if contains(slowQueryAuditTypes, auditType) { log.Printf("[INFO] Disabling and enabling audit for DSF data source assetId: %s \n", assetId) - + _, err1 := client.DisableAuditDSFDataSource(assetId) if err1 != nil { log.Printf("[INFO] Error disabling audit for assetId: %s\n", assetId) return err1 } time.Sleep(wait) - + _, err2 := client.EnableAuditDSFDataSource(assetId) if err2 != nil { log.Printf("[INFO] Error enabling audit for assetId: %s\n", assetId) return err2 } time.Sleep(wait) - // if not, enable audit against parent + // if not, enable audit against parent } else if parentAssetId != nil { parentAssetId := d.Get("parent_asset_id").(string) @@ -680,7 +680,6 @@ func resourceLogAggregatorCreate(d *schema.ResourceData, m interface{}) error { time.Sleep(wait) } - } // Set the rest of the state from the resource read diff --git a/dsfhub/resource_log_aggregator_schema.go b/dsfhub/resource_log_aggregator_schema.go index 06e3074..ef41650 100644 --- a/dsfhub/resource_log_aggregator_schema.go +++ b/dsfhub/resource_log_aggregator_schema.go @@ -163,7 +163,7 @@ var requiredLogAggregatorJson = `{ }` var slowQueryAuditTypes = []string{ - "AWS_RDS_AURORA_MYSQL_SLOW", + "AWS_RDS_AURORA_MYSQL_SLOW", "AWS_RDS_MYSQL_SLOW", "AWS_NEPTUNE_SLOW", -}; +} From a92c5d9e3b8fa51539722feb50bfa989ce2f027c Mon Sep 17 00:00:00 2001 From: mattJsonar Date: Fri, 24 May 2024 14:15:35 -0700 Subject: [PATCH 4/4] bump version to 1.2.44 --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index bc48ca3..6542d7a 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -5,7 +5,7 @@ HOSTNAME=registry.terraform.io NAMESPACE=terraform-providers PKG_NAME=dsfhub BINARY=terraform-provider-${PKG_NAME} -VERSION=1.2.43 +VERSION=1.2.44 OS_ARCH=darwin_amd64 default: install