diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5e6ad2..3965576b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed - Problem with `schema_change_handling` validation for SAP connectors +- Issue with `local_processing_agent_id` in `fivetran_connector` and `fivetran_destination` resources ## [1.4.0](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.3.2...v1.4.0) diff --git a/fivetran/framework/core/model/connector.go b/fivetran/framework/core/model/connector.go index aa0146a2..dbc829fb 100644 --- a/fivetran/framework/core/model/connector.go +++ b/fivetran/framework/core/model/connector.go @@ -206,7 +206,7 @@ func (d *ConnectorResourceModel) ReadFromContainer(c ConnectorModelContainer, fo d.GroupId = types.StringValue(c.GroupId) d.Service = types.StringValue(c.Service) - if c.LocalProcessingAgentId != "" { + if c.LocalProcessingAgentId != "" && !d.LocalProcessingAgentId.IsUnknown() && !d.LocalProcessingAgentId.IsNull(){ d.LocalProcessingAgentId = types.StringValue(c.HybridDeploymentAgentId) } else { d.LocalProcessingAgentId = types.StringNull() @@ -251,12 +251,6 @@ func (d *ConnectorDatasourceModel) ReadFromContainer(c ConnectorModelContainer) d.GroupId = types.StringValue(c.GroupId) d.Service = types.StringValue(c.Service) - if c.LocalProcessingAgentId != "" { - d.LocalProcessingAgentId = types.StringValue(c.LocalProcessingAgentId) - } else { - d.LocalProcessingAgentId = types.StringNull() - } - d.DestinationSchema = getDestinationSchemaValue(c.Service, c.Schema) if c.PrivateLinkId != "" { @@ -341,7 +335,7 @@ func (c *ConnectorModelContainer) ReadFromResponseData(data connectors.DetailsRe c.PrivateLinkId = data.PrivateLinkId } - if data.HybridDeploymentAgentId != "" { + if data.HybridDeploymentAgentId != "" && c.LocalProcessingAgentId != "" { c.LocalProcessingAgentId = data.HybridDeploymentAgentId } diff --git a/fivetran/framework/core/model/destination_resource_model.go b/fivetran/framework/core/model/destination_resource_model.go index 2781fffe..a60f508f 100644 --- a/fivetran/framework/core/model/destination_resource_model.go +++ b/fivetran/framework/core/model/destination_resource_model.go @@ -52,7 +52,7 @@ func (d *DestinationResourceModel) SetDaylightSavingTimeEnabled(value bool) { d.DaylightSavingTimeEnabled = types.BoolValue(value) } func (d *DestinationResourceModel) SetLocalProcessingAgentId(value string) { - if value != "" { + if value != "" && !d.LocalProcessingAgentId.IsUnknown() && !d.LocalProcessingAgentId.IsNull() { d.LocalProcessingAgentId = types.StringValue(value) } else { d.LocalProcessingAgentId = types.StringNull() diff --git a/fivetran/tests/e2e/fivetran_test.go b/fivetran/tests/e2e/fivetran_test.go index 2880411a..539e8377 100644 --- a/fivetran/tests/e2e/fivetran_test.go +++ b/fivetran/tests/e2e/fivetran_test.go @@ -93,7 +93,6 @@ func cleanupAccount() { cleanupTeams() cleanupProxyAgents() cleanupPrivateLinks() - cleanupHybridDeploymentAgents() } func isPredefinedUserExist() bool { @@ -297,20 +296,3 @@ func cleanupPrivateLinks() { cleanupPrivateLinks() } } - -func cleanupHybridDeploymentAgents() { - lpaList, err := client.NewHybridDeploymentAgentList().Do(context.Background()) - if err != nil { - log.Fatal(err) - } - for _, lpa := range lpaList.Data.Items { - _, err := client.NewHybridDeploymentAgentDelete().AgentId(lpa.Id).Do(context.Background()) - if err != nil { - log.Fatal(err) - } - } - - if lpaList.Data.NextCursor != "" { - cleanupHybridDeploymentAgents() - } -} diff --git a/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go b/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go index e91ae00a..e9285995 100644 --- a/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go +++ b/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go @@ -6,34 +6,72 @@ import ( "fmt" "strings" "testing" + "regexp" + "strconv" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" ) -func TestResourceHybridDeploymentAgentE2E(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() {}, - ProtoV6ProviderFactories: ProtoV6ProviderFactories, - CheckDestroy: testFivetranHybridDeploymentAgentResourceDestroy, - Steps: []resource.TestStep{ - { - Config: ` +var hdaResourceConfig = ` resource "fivetran_group" "testgroup" { provider = fivetran-provider - name = "TestResourceHybridDeploymentAgentE2E" + name = "%v" } resource "fivetran_hybrid_deployment_agent" "test_lpa" { provider = fivetran-provider - display_name = "TestResourceHybridDeploymentAgentE2E" + display_name = "%v" group_id = fivetran_group.testgroup.id auth_type = "AUTO" - }`, + }` + +var connectorWithHdaResourceConfig = ` + resource "fivetran_group" "test_group" { + provider = fivetran-provider + name = "%v" + } + + resource "fivetran_hybrid_deployment_agent" "test_hda" { + provider = fivetran-provider + + display_name = "%v" + group_id = fivetran_group.test_group.id + auth_type = "AUTO" + } + + resource "fivetran_connector" "test_connector" { + provider = fivetran-provider + group_id = fivetran_group.test_group.id + service = "fivetran_log" + hybrid_deployment_agent_id = fivetran_hybrid_deployment_agent.test_hda.id + destination_schema { + name = "fivetran_log_schema" + } + + trust_certificates = false + trust_fingerprints = false + run_setup_tests = false + } + ` + +func TestResourceHybridDeploymentAgentE2E(t *testing.T) { + hdaName := strconv.Itoa(seededRand.Int()) + groupName := "group" + strconv.Itoa(seededRand.Int()) + + resourceConfig := fmt.Sprintf(hdaResourceConfig, groupName, hdaName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() {}, + ProtoV6ProviderFactories: ProtoV6ProviderFactories, + CheckDestroy: testFivetranHybridDeploymentAgentResourceDestroy, + Steps: []resource.TestStep{ + { + Config:resourceConfig, Check: resource.ComposeAggregateTestCheckFunc( testFivetranHybridDeploymentAgentResourceCreate(t, "fivetran_hybrid_deployment_agent.test_lpa"), - resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "display_name", "TestResourceHybridDeploymentAgentE2E"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "display_name", hdaName), resource.TestCheckResourceAttrSet("fivetran_hybrid_deployment_agent.test_lpa", "token"), ), }, @@ -41,13 +79,41 @@ func TestResourceHybridDeploymentAgentE2E(t *testing.T) { }) } +func TestResourceConnectorWithHybridDeploymentAgentE2E(t *testing.T) { + regexp, _ := regexp.Compile("[a-z]*_[a-z]*") + + hdaName := strconv.Itoa(seededRand.Int()) + groupName := "group" + strconv.Itoa(seededRand.Int()) + + resourceConfig := fmt.Sprintf(connectorWithHdaResourceConfig, groupName, hdaName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() {}, + ProtoV6ProviderFactories: ProtoV6ProviderFactories, + CheckDestroy: testFivetranConnectorResourceDestroy, + Steps: []resource.TestStep{ + { + Config: resourceConfig, + Check: resource.ComposeAggregateTestCheckFunc( + testFivetranConnectorResourceCreate(t, "fivetran_connector.test_connector"), + resource.TestCheckResourceAttr("fivetran_connector.test_connector", "service", "fivetran_log"), + resource.TestCheckResourceAttr("fivetran_connector.test_connector", "name", "fivetran_log_schema"), + resource.TestCheckResourceAttr("fivetran_connector.test_connector", "trust_certificates", "false"), + resource.TestCheckResourceAttr("fivetran_connector.test_connector", "trust_fingerprints", "false"), + resource.TestCheckResourceAttr("fivetran_connector.test_connector", "run_setup_tests", "false"), + resource.TestMatchResourceAttr("fivetran_connector.test_connector", "hybrid_deployment_agent_id", regexp), + ), + }, + }, + }) +} + func testFivetranHybridDeploymentAgentResourceCreate(t *testing.T, resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs := GetResource(t, s, resourceName) _, err := client.NewHybridDeploymentAgentDetails().AgentId(rs.Primary.ID).Do(context.Background()) if err != nil { - fmt.Println(err) return err } //todo: check response _ fields if needed diff --git a/fivetran/tests/e2e/resource_private_link_e2e_test.go b/fivetran/tests/e2e/resource_private_link_e2e_test.go index 4b362e98..dcd41250 100644 --- a/fivetran/tests/e2e/resource_private_link_e2e_test.go +++ b/fivetran/tests/e2e/resource_private_link_e2e_test.go @@ -25,7 +25,7 @@ var privateLinkResourceConfig = ` }` func TestResourcePrivateLinkE2E(t *testing.T) { - //t.Skip("Private links have a strict limit on the number of entities created. This test should only be used for intermediate tests when changes are made directly to Private links.") + t.Skip("Private links have a strict limit on the number of entities created. This test should only be used for intermediate tests when changes are made directly to Private links.") suffix := strconv.Itoa(seededRand.Int()) privateLinkName := suffix privateLinkCfgValue := "privatelink_" + suffix