Skip to content

Commit

Permalink
Set integration parameters to match terraform plan
Browse files Browse the repository at this point in the history
  • Loading branch information
lootag committed Nov 18, 2024
1 parent 3cc38ad commit 3d289a4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,4 +52,4 @@ testacc:
TF_ACC=1 go test ${BUILD_ARGS} $(TEST) -v $(TESTARGS) -timeout 120m

generate:
go generate ${BUILD_ARGS}
go generate ${BUILD_ARGS}
6 changes: 3 additions & 3 deletions coralogix/data_source_coralogix_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
3 changes: 3 additions & 0 deletions coralogix/resource_coralogix_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
89 changes: 72 additions & 17 deletions coralogix/resource_coralogix_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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)
}

0 comments on commit 3d289a4

Please sign in to comment.