88 "strings"
99 "testing"
1010
11+ "github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
1112 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1213 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1314)
@@ -22,14 +23,15 @@ func TestAccSumologicGcpMetricsSource_create(t *testing.T) {
2223 var collector Collector
2324 cName , cDescription , cCategory := getRandomizedParams ()
2425 sName , sDescription , sCategory := getRandomizedParams ()
26+ customServicePrefix := acctest .RandomWithPrefix ("compute.googleapis.com" )
2527 GcpMetricsResourceName := "sumologic_gcp_metrics_source.gcp_metrics_source"
2628 resource .Test (t , resource.TestCase {
2729 PreCheck : func () { getServiceAccountCreds (t ) },
2830 Providers : testAccProviders ,
2931 CheckDestroy : testAccCheckGcpMetricsSourceDestroy ,
3032 Steps : []resource.TestStep {
3133 {
32- Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sName , sDescription , sCategory ),
34+ Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sName , sDescription , sCategory , customServicePrefix ),
3335 Check : resource .ComposeTestCheckFunc (
3436 testAccCheckGcpMetricsSourceExists (GcpMetricsResourceName , & GcpMetricsSource ),
3537 testAccCheckGcpMetricsSourceValues (& GcpMetricsSource , sName , sDescription , sCategory ),
@@ -41,6 +43,9 @@ func TestAccSumologicGcpMetricsSource_create(t *testing.T) {
4143 resource .TestCheckResourceAttr (GcpMetricsResourceName , "category" , sCategory ),
4244 resource .TestCheckResourceAttr (GcpMetricsResourceName , "content_type" , "GcpMetrics" ),
4345 resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.type" , "GcpMetricsPath" ),
46+ resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.custom_services.1.service_name" , "compute_instance_and_guests" ),
47+ resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.custom_services.1.prefixes.0" , customServicePrefix ),
48+ resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.custom_services.1.prefixes.1" , "compute.googleapis.com/guest/" ),
4449 ),
4550 },
4651 },
@@ -54,14 +59,16 @@ func TestAccSumologicGcpMetricsSource_update(t *testing.T) {
5459 cName , cDescription , cCategory := getRandomizedParams ()
5560 sName , sDescription , sCategory := getRandomizedParams ()
5661 sNameUpdated , sDescriptionUpdated , sCategoryUpdated := getRandomizedParams ()
62+ customServicePrefix := acctest .RandomWithPrefix ("compute.googleapis.com" )
63+ updatedCustomServicePrefix := acctest .RandomWithPrefix ("compute.googleapis.com" )
5764 GcpMetricsResourceName := "sumologic_gcp_metrics_source.gcp_metrics_source"
5865 resource .Test (t , resource.TestCase {
5966 PreCheck : func () { getServiceAccountCreds (t ) },
6067 Providers : testAccProviders ,
6168 CheckDestroy : testAccCheckHTTPSourceDestroy ,
6269 Steps : []resource.TestStep {
6370 {
64- Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sName , sDescription , sCategory ),
71+ Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sName , sDescription , sCategory , customServicePrefix ),
6572 Check : resource .ComposeTestCheckFunc (
6673 testAccCheckGcpMetricsSourceExists (GcpMetricsResourceName , & GcpMetricsSource ),
6774 testAccCheckGcpMetricsSourceValues (& GcpMetricsSource , sName , sDescription , sCategory ),
@@ -71,10 +78,11 @@ func TestAccSumologicGcpMetricsSource_update(t *testing.T) {
7178 resource .TestCheckResourceAttr (GcpMetricsResourceName , "category" , sCategory ),
7279 resource .TestCheckResourceAttr (GcpMetricsResourceName , "content_type" , "GcpMetrics" ),
7380 resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.type" , "GcpMetricsPath" ),
81+ resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.custom_services.1.prefixes.0" , customServicePrefix ),
7482 ),
7583 },
7684 {
77- Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sNameUpdated , sDescriptionUpdated , sCategoryUpdated ),
85+ Config : testAccSumologicGcpMetricsSourceConfig (t , cName , cDescription , cCategory , sNameUpdated , sDescriptionUpdated , sCategoryUpdated , updatedCustomServicePrefix ),
7886 Check : resource .ComposeTestCheckFunc (
7987 testAccCheckGcpMetricsSourceExists (GcpMetricsResourceName , & GcpMetricsSource ),
8088 testAccCheckGcpMetricsSourceValues (& GcpMetricsSource , sNameUpdated , sDescriptionUpdated , sCategoryUpdated ),
@@ -84,6 +92,7 @@ func TestAccSumologicGcpMetricsSource_update(t *testing.T) {
8492 resource .TestCheckResourceAttr (GcpMetricsResourceName , "category" , sCategoryUpdated ),
8593 resource .TestCheckResourceAttr (GcpMetricsResourceName , "content_type" , "GcpMetrics" ),
8694 resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.type" , "GcpMetricsPath" ),
95+ resource .TestCheckResourceAttr (GcpMetricsResourceName , "path.0.custom_services.1.prefixes.0" , updatedCustomServicePrefix ),
8796 ),
8897 },
8998 },
@@ -195,7 +204,7 @@ func getServiceAccountCreds(t *testing.T) ServiceAccountCreds {
195204 return serviceAccountCreds
196205}
197206
198- func testAccSumologicGcpMetricsSourceConfig (t * testing.T , cName , cDescription , cCategory , sName , sDescription , sCategory string ) string {
207+ func testAccSumologicGcpMetricsSourceConfig (t * testing.T , cName , cDescription , cCategory , sName , sDescription , sCategory , customServicePrefix string ) string {
199208 cred := getServiceAccountCreds (t )
200209 srcStr := fmt .Sprintf (`
201210 resource "sumologic_collector" "test" {
@@ -207,33 +216,46 @@ func testAccSumologicGcpMetricsSourceConfig(t *testing.T, cName, cDescription, c
207216 name = "%s"
208217 description = "%s"
209218 category = "%s"
210- content_type = "GcpMetrics"
219+ content_type = "GcpMetrics"
211220 scan_interval = 300000
212- paused = false
221+ paused = false
213222 collector_id = "${sumologic_collector.test.id}"
223+ filters {
224+ name = "Exclude Comments"
225+ filter_type = "Exclude"
226+ regexp = "#.*"
227+ }
214228 authentication {
215- type = "%s"
216- project_id = "%s"
217- private_key_id = "%s"
218- private_key = <<EOPK
229+ type = "%s"
230+ project_id = "%s"
231+ private_key_id = "%s"
232+ private_key = <<EOPK
219233%sEOPK
220- client_email = "%s"
221- client_id = "%s"
222- auth_uri = "%s"
223- token_uri = "%s"
224- auth_provider_x509_cert_url = "%s"
225- client_x509_cert_url = "%s"
226- }
227- path {
234+ client_email = "%s"
235+ client_id = "%s"
236+ auth_uri = "%s"
237+ token_uri = "%s"
238+ auth_provider_x509_cert_url = "%s"
239+ client_x509_cert_url = "%s"
240+ }
241+ path {
228242 type = "GcpMetricsPath"
229- limit_to_regions = ["asia-south1"]
230- limit_to_services = ["Compute Engine", "CloudSQL"]
231- }
232- lifecycle {
243+ limit_to_regions = ["asia-south1"]
244+ limit_to_services = ["Compute Engine", "CloudSQL"]
245+ custom_services {
246+ service_name = "mysql"
247+ prefixes = ["cloudsql.googleapis.com/database/mysql/","cloudsql.googleapis.com/database/memory/","cloudsql.googleapis.com/database/cpu","cloudsql.googleapis.com/database/disk"]
248+ }
249+ custom_services {
250+ service_name = "compute_instance_and_guests"
251+ prefixes = ["%s" ,"compute.googleapis.com/guest/", "compute.googleapis.com/instance/"]
252+ }
253+ }
254+ lifecycle {
233255 ignore_changes = [authentication[0].private_key]
234- }
235256 }
257+ }
236258 ` , cName , cDescription , cCategory , sName , sDescription , sCategory ,
237- cred .Type , cred .ProjectId , cred .PrivateKeyId , cred .PrivateKey , cred .ClientEmail , cred .ClientId , cred .AuthUri , cred .TokenUri , cred .AuthProviderX509CertUrl , cred .ClientX509CertUrl )
259+ cred .Type , cred .ProjectId , cred .PrivateKeyId , cred .PrivateKey , cred .ClientEmail , cred .ClientId , cred .AuthUri , cred .TokenUri , cred .AuthProviderX509CertUrl , cred .ClientX509CertUrl , customServicePrefix )
238260 return srcStr
239261}
0 commit comments