diff --git a/Makefile b/Makefile index 4b4433c4..1ab95a96 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ NAMESPACE=debug NAME=coralogix BINARY=terraform-provider-${NAME} VERSION=1.5 -OS_ARCH=darwin_arm64 +OS_ARCH=linux_amd64 BUILD_ARGS=-ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" default: install @@ -52,4 +52,4 @@ testacc: TF_ACC=1 go test ${BUILD_ARGS} $(TEST) -v $(TESTARGS) -timeout 120m generate: - go generate ${BUILD_ARGS} \ No newline at end of file + go generate ${BUILD_ARGS} diff --git a/coralogix/data_source_coralogix_integration.go b/coralogix/data_source_coralogix_integration.go index 853008c4..8172e243 100644 --- a/coralogix/data_source_coralogix_integration.go +++ b/coralogix/data_source_coralogix_integration.go @@ -97,12 +97,12 @@ func (d *IntegrationDataSource) Read(ctx context.Context, req datasource.ReadReq resp.Diagnostics.Append(diags...) return } - data, diags = integrationDetail(getIntegrationResp, keys) - if diags.HasError() { + state, e := integrationDetail(getIntegrationResp, keys) + if e.HasError() { resp.Diagnostics.Append(diags...) return } // Set state to fully populated data - diags = resp.State.Set(ctx, &data) + diags = resp.State.Set(ctx, state) resp.Diagnostics.Append(diags...) } diff --git a/coralogix/resource_coralogix_integration.go b/coralogix/resource_coralogix_integration.go index 9e43be40..03409675 100644 --- a/coralogix/resource_coralogix_integration.go +++ b/coralogix/resource_coralogix_integration.go @@ -185,6 +185,7 @@ func (r *IntegrationResource) Create(ctx context.Context, req resource.CreateReq log.Printf("[INFO] Received Integration: %s", protojson.Format(getIntegrationResp)) state, e := integrationDetail(getIntegrationResp, keys) + state.Parameters = plan.Parameters if e.HasError() { resp.Diagnostics.Append(e...) return @@ -397,6 +398,7 @@ func (r *IntegrationResource) Read(ctx context.Context, req resource.ReadRequest return } state, e := integrationDetail(getIntegrationResp, keys) + state.Parameters = plan.Parameters if e.HasError() { resp.Diagnostics.Append(e...) return @@ -460,6 +462,7 @@ func (r *IntegrationResource) Update(ctx context.Context, req resource.UpdateReq } log.Printf("[INFO] Received Integration: %s", protojson.Format(getIntegrationResp)) state, e := integrationDetail(getIntegrationResp, keys) + state.Parameters = plan.Parameters if e.HasError() { resp.Diagnostics.Append(e...) return diff --git a/coralogix/resource_coralogix_integration_test.go b/coralogix/resource_coralogix_integration_test.go index 7106003f..94e19d04 100644 --- a/coralogix/resource_coralogix_integration_test.go +++ b/coralogix/resource_coralogix_integration_test.go @@ -14,34 +14,59 @@ import ( "google.golang.org/protobuf/types/known/wrapperspb" ) -var integrationResourceName = "aws-metrics-collector" +var integrationWithoutSensitiveDataName = "aws-metrics-collector" +var integrationWithSensitiveDataName = "gcp-metrics-collector" var testRoleArn = os.Getenv("AWS_TEST_ROLE") +var testGoogleServiceAccountKey = os.Getenv("GOOGLE_SERVICE_ACCOUNT_KEY") -func TestAccCoralogixResourceIntegration(t *testing.T) { +func TestAccCoralogixResourceIntegrationWithoutSensitiveData(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: testAccCheckIntegrationDestroy, Steps: []resource.TestStep{ { - Config: testAccCoralogixResourceIntegration(), + Config: testAccCoralogixResourceIntegrationWithoutSensitiveData(), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttrSet("coralogix_integration.test", "id"), - resource.TestCheckResourceAttr("coralogix_integration.test", "integration_key", integrationResourceName), - resource.TestCheckResourceAttr("coralogix_integration.test", "version", "0.1.0"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.ApplicationName", "cxsdk"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.SubsystemName", integrationResourceName), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.AwsRegion", "eu-north-1"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.WithAggregations", "false"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.EnrichWithTags", "true"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.IntegrationName", "sdk-integration-setup"), - resource.TestCheckResourceAttr("coralogix_integration.test", "parameters.AwsRoleArn", testRoleArn), + resource.TestCheckResourceAttrSet("coralogix_integration.no_sensitive_data_test", "id"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "integration_key", integrationWithoutSensitiveDataName), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "version", "0.1.0"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.ApplicationName", "cxsdk"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.SubsystemName", integrationWithoutSensitiveDataName), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.AwsRegion", "eu-north-1"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.WithAggregations", "false"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.EnrichWithTags", "true"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.IntegrationName", "sdk-integration-no-sensitive-data-setup"), + resource.TestCheckResourceAttr("coralogix_integration.no_sensitive_data_test", "parameters.AwsRoleArn", testRoleArn), ), }, }, }) } + +func TestAccCoralogixResourceIntegrationWithSensitiveData(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + CheckDestroy: testAccCheckIntegrationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCoralogixResourceIntegrationWithSensitiveData(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrSet("coralogix_integration.sensitive_data_test", "id"), + resource.TestCheckResourceAttr("coralogix_integration.sensitive_data_test", "integration_key", integrationWithSensitiveDataName), + resource.TestCheckResourceAttr("coralogix_integration.sensitive_data_test", "version", "1.0.0"), + resource.TestCheckResourceAttr("coralogix_integration.sensitive_data_test", "parameters.ApplicationName", "cxsdk"), + resource.TestCheckResourceAttr("coralogix_integration.sensitive_data_test", "parameters.SubsystemName", integrationWithSensitiveDataName), + resource.TestCheckResourceAttr("coralogix_integration.sensitive_data_test", "parameters.IntegrationName", "sdk-integration-with-sensitive-data-setup"), + ), + }, + }, + }) +} + + func testAccCheckIntegrationDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*clientset.ClientSet).Integrations() ctx := context.TODO() @@ -61,8 +86,8 @@ func testAccCheckIntegrationDestroy(s *terraform.State) error { return nil } -func testAccCoralogixResourceIntegration() string { - return fmt.Sprintf(`resource "coralogix_integration" "test" { +func testAccCoralogixResourceIntegrationWithoutSensitiveData() string { + return fmt.Sprintf(`resource "coralogix_integration" "no_sensitive_data_test" { integration_key = "%v" version = "0.1.0" # Note that the attribute casing is important here @@ -82,11 +107,41 @@ func testAccCoralogixResourceIntegration() string { "AWS/EC2" ] AwsRoleArn = "%v" - IntegrationName = "sdk-integration-setup" + IntegrationName = "sdk-integration-no-sensitive-data-setup" AwsRegion = "eu-north-1" WithAggregations = false EnrichWithTags = true } } - `, integrationResourceName, integrationResourceName, testRoleArn) + `, integrationWithoutSensitiveDataName, integrationWithoutSensitiveDataName, testRoleArn) } + + +func testAccCoralogixResourceIntegrationWithSensitiveData() string { + return fmt.Sprintf(`resource "coralogix_integration" "sensitive_data_test" { + integration_key = "%v" + version = "1.0.0" + # Note that the attribute casing is important here + parameters = { + ApplicationName = "cxsdk" + SubsystemName = "%v" + MetricPrefixes = [ + "appengine.googleapis.com", + "cloudfunctions.googleapis.com", + "cloudkms.googleapis.com", + "cloudsql.googleapis.com", + "compute.googleapis.com", + "container.googleapis.com", + "datastream.googleapis.com", + "firestore.googleapis.com", + "loadbalancing.googleapis.com", + "network.googleapis.com", + "run.googleapis.com", + "storage.googleapis.com", + ] + IntegrationName = "sdk-integration-with-sensitive-data-setup" + ServiceAccountKey = "%v" + } + } + `, integrationWithSensitiveDataName, integrationWithSensitiveDataName, testGoogleServiceAccountKey) +} \ No newline at end of file