From 192ee5b7dc350cb710b681e6ce29e90b3370c56b Mon Sep 17 00:00:00 2001 From: Aleksandr Boldyrev Date: Thu, 31 Oct 2024 23:56:20 +0100 Subject: [PATCH] fixes --- fivetran/framework/core/model/connector.go | 4 +-- .../model/destination_datasource_model.go | 2 +- .../core/model/destination_resource_model.go | 2 +- .../hybrid_deployment_agent_test.go | 14 +++------- .../hybrid_deployment_agents_test.go | 27 +++++-------------- .../resources/connector_migrations.go | 4 +-- fivetran/framework/resources/destination.go | 5 ++++ .../resources/destination_migrations.go | 9 +++---- .../resources/hybrid_deployment_agent_test.go | 14 +++++----- ...ource_hybrid_deployment_agent_e2e_test.go} | 8 +++--- 10 files changed, 37 insertions(+), 52 deletions(-) rename fivetran/tests/e2e/{resource_local_processing_agent_e2e_test.go => resource_hybrid_deployment_agent_e2e_test.go} (86%) diff --git a/fivetran/framework/core/model/connector.go b/fivetran/framework/core/model/connector.go index a0044367..bed6e82f 100644 --- a/fivetran/framework/core/model/connector.go +++ b/fivetran/framework/core/model/connector.go @@ -35,7 +35,7 @@ type ConnectorDatasourceModel struct { ProxyAgentId types.String `tfsdk:"proxy_agent_id"` NetworkingMethod types.String `tfsdk:"networking_method"` - HybridDeploymentAgentId types.String `tfsdk:"local_processing_agent_id"` + HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"` PrivateLinkId types.String `tfsdk:"private_link_id"` Status types.Object `tfsdk:"status"` @@ -126,7 +126,7 @@ type ConnectorResourceModel struct { ProxyAgentId types.String `tfsdk:"proxy_agent_id"` NetworkingMethod types.String `tfsdk:"networking_method"` - HybridDeploymentAgentId types.String `tfsdk:"local_processing_agent_id"` + HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"` PrivateLinkId types.String `tfsdk:"private_link_id"` Config types.Object `tfsdk:"config"` diff --git a/fivetran/framework/core/model/destination_datasource_model.go b/fivetran/framework/core/model/destination_datasource_model.go index ac2a533c..ce43cfaa 100644 --- a/fivetran/framework/core/model/destination_datasource_model.go +++ b/fivetran/framework/core/model/destination_datasource_model.go @@ -15,7 +15,7 @@ type DestinationDatasourceModel struct { TimeZoneOffset types.String `tfsdk:"time_zone_offset"` SetupStatus types.String `tfsdk:"setup_status"` DaylightSavingTimeEnabled types.Bool `tfsdk:"daylight_saving_time_enabled"` - HybridDeploymentAgentId types.String `tfsdk:"local_processing_agent_id"` + HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"` NetworkingMethod types.String `tfsdk:"networking_method"` PrivateLinkId types.String `tfsdk:"private_link_id"` Config types.Object `tfsdk:"config"` diff --git a/fivetran/framework/core/model/destination_resource_model.go b/fivetran/framework/core/model/destination_resource_model.go index 9c3d3572..a9738e62 100644 --- a/fivetran/framework/core/model/destination_resource_model.go +++ b/fivetran/framework/core/model/destination_resource_model.go @@ -18,7 +18,7 @@ type DestinationResourceModel struct { DaylightSavingTimeEnabled types.Bool `tfsdk:"daylight_saving_time_enabled"` Config types.Object `tfsdk:"config"` Timeouts timeouts.Value `tfsdk:"timeouts"` - HybridDeploymentAgentId types.String `tfsdk:"local_processing_agent_id"` + HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"` NetworkingMethod types.String `tfsdk:"networking_method"` PrivateLinkId types.String `tfsdk:"private_link_id"` diff --git a/fivetran/framework/datasources/hybrid_deployment_agent_test.go b/fivetran/framework/datasources/hybrid_deployment_agent_test.go index 1a0e1146..1ce6d5f6 100644 --- a/fivetran/framework/datasources/hybrid_deployment_agent_test.go +++ b/fivetran/framework/datasources/hybrid_deployment_agent_test.go @@ -52,7 +52,7 @@ func setupMockClientHybridDeploymentAgentDataSourceConfigMapping(t *testing.T) { func TestDataSourceHybridDeploymentAgentMappingMock(t *testing.T) { step1 := resource.TestStep{ Config: ` - data "fivetran_local_processing_agent" "test_lpa" { + data "fivetran_hybrid_deployment_agent" "test_lpa" { provider = fivetran-provider id = "lpa_id" }`, @@ -63,15 +63,9 @@ func TestDataSourceHybridDeploymentAgentMappingMock(t *testing.T) { tfmock.AssertNotEmpty(t, hdaDataSourceMockData) return nil }, - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "display_name", "display_name"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "group_id", "group_id"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "registered_at", "registered_at"), - /*resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.0.connection_id", "connection_id1"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.0.schema", "schema1"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.0.service", "service1"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.1.connection_id", "connection_id2"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.1.schema", "schema2"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agent.test_lpa", "usage.1.service", "service2"),*/ + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agent.test_lpa", "display_name", "display_name"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agent.test_lpa", "group_id", "group_id"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agent.test_lpa", "registered_at", "registered_at"), ), } diff --git a/fivetran/framework/datasources/hybrid_deployment_agents_test.go b/fivetran/framework/datasources/hybrid_deployment_agents_test.go index 554893cd..6ee7b68c 100644 --- a/fivetran/framework/datasources/hybrid_deployment_agents_test.go +++ b/fivetran/framework/datasources/hybrid_deployment_agents_test.go @@ -74,7 +74,7 @@ func setupMockClientHybridDeploymentAgentsDataSourceConfigMapping(t *testing.T) func TestDataSourceHybridDeploymentAgentsMappingMock(t *testing.T) { step1 := resource.TestStep{ Config: ` - data "fivetran_local_processing_agents" "test_lpa" { + data "fivetran_hybrid_deployment_agents" "test_lpa" { provider = fivetran-provider }`, @@ -84,25 +84,12 @@ func TestDataSourceHybridDeploymentAgentsMappingMock(t *testing.T) { tfmock.AssertNotEmpty(t, hybridDeploymentAgentsDataSourceMockData) return nil }, - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.display_name", "display_name1"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.group_id", "group_id1"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.registered_at", "registered_at1"), - /*resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.0.connection_id", "connection_id11"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.0.schema", "schema11"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.0.service", "service11"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.1.connection_id", "connection_id12"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.1.schema", "schema12"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.0.usage.1.service", "service12"),*/ - - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.display_name", "display_name2"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.group_id", "group_id2"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.registered_at", "registered_at2"), - /*resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.0.connection_id", "connection_id21"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.0.schema", "schema21"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.0.service", "service21"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.1.connection_id", "connection_id22"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.1.schema", "schema22"), - resource.TestCheckResourceAttr("data.fivetran_local_processing_agents.test_lpa", "items.1.usage.1.service", "service22"),*/ + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.0.display_name", "display_name1"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.0.group_id", "group_id1"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.0.registered_at", "registered_at1"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.1.display_name", "display_name2"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.1.group_id", "group_id2"), + resource.TestCheckResourceAttr("data.fivetran_hybrid_deployment_agents.test_lpa", "items.1.registered_at", "registered_at2"), ), } diff --git a/fivetran/framework/resources/connector_migrations.go b/fivetran/framework/resources/connector_migrations.go index 9a999910..a2fe091e 100644 --- a/fivetran/framework/resources/connector_migrations.go +++ b/fivetran/framework/resources/connector_migrations.go @@ -47,7 +47,7 @@ func upgradeConnectorState(ctx context.Context, req resource.UpgradeStateRequest "timeouts": rawState["timeouts"], "networking_method": tftypes.NewValue(tftypes.String, nil), "proxy_agent_id": tftypes.NewValue(tftypes.String, nil), - "local_processing_agent_id": tftypes.NewValue(tftypes.String, nil), + "hybrid_deployment_agent_id": rawState["local_processing_agent_id"], "run_setup_tests": convertStringStateValueToBool("run_setup_tests", rawState["run_setup_tests"], resp.Diagnostics), "trust_fingerprints": convertStringStateValueToBool("trust_fingerprints", rawState["trust_fingerprints"], resp.Diagnostics), @@ -96,7 +96,7 @@ func getConnectorStateModel(version int) tftypes.Type { }, }, } - if version == 3 { + if version == 3 || version == 4 { base["destination_schema"] = dsObj base["run_setup_tests"] = tftypes.Bool base["trust_certificates"] = tftypes.Bool diff --git a/fivetran/framework/resources/destination.go b/fivetran/framework/resources/destination.go index e4fb53aa..820847cb 100644 --- a/fivetran/framework/resources/destination.go +++ b/fivetran/framework/resources/destination.go @@ -49,6 +49,11 @@ func (r *destination) UpgradeState(ctx context.Context) map[int64]resource.State upgradeDestinationState(ctx, req, resp, 0) }, }, + 1: { + StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { + upgradeDestinationState(ctx, req, resp, 1) + }, + }, } } diff --git a/fivetran/framework/resources/destination_migrations.go b/fivetran/framework/resources/destination_migrations.go index c49c0354..c4f492c4 100644 --- a/fivetran/framework/resources/destination_migrations.go +++ b/fivetran/framework/resources/destination_migrations.go @@ -32,8 +32,8 @@ func upgradeDestinationState(ctx context.Context, req resource.UpgradeStateReque } dynamicValue, err := tfprotov6.NewDynamicValue( - getDestinationStateModel(1), - tftypes.NewValue(getDestinationStateModel(1), map[string]tftypes.Value{ + getDestinationStateModel(2), + tftypes.NewValue(getDestinationStateModel(2), map[string]tftypes.Value{ "id": rawState["id"], "group_id": rawState["group_id"], "service": rawState["service"], @@ -42,8 +42,7 @@ func upgradeDestinationState(ctx context.Context, req resource.UpgradeStateReque "time_zone_offset": rawState["time_zone_offset"], "setup_status": rawState["setup_status"], "daylight_saving_time_enabled": tftypes.NewValue(tftypes.Bool, nil), - "local_processing_agent_id": tftypes.NewValue(tftypes.String, nil), - "networking_method": tftypes.NewValue(tftypes.String, nil), + "hybrid_deployment_agent_id": rawState["local_processing_agent_id"], "run_setup_tests": convertStringStateValueToBool("run_setup_tests", rawState["run_setup_tests"], resp.Diagnostics), "trust_fingerprints": convertStringStateValueToBool("trust_fingerprints", rawState["trust_fingerprints"], resp.Diagnostics), @@ -75,7 +74,7 @@ func getDestinationStateModel(version int) tftypes.Type { }, }, } - if version == 1 { + if version == 1 || version == 2 { base["run_setup_tests"] = tftypes.Bool base["trust_certificates"] = tftypes.Bool base["trust_fingerprints"] = tftypes.Bool diff --git a/fivetran/framework/resources/hybrid_deployment_agent_test.go b/fivetran/framework/resources/hybrid_deployment_agent_test.go index 721af431..e5bc0ef9 100644 --- a/fivetran/framework/resources/hybrid_deployment_agent_test.go +++ b/fivetran/framework/resources/hybrid_deployment_agent_test.go @@ -54,7 +54,7 @@ func setupMockClientHybridDeploymentAgentResource(t *testing.T) { func TestResourceHybridDeploymentAgentMock(t *testing.T) { step1 := resource.TestStep{ Config: ` - resource "fivetran_local_processing_agent" "test_lpa" { + resource "fivetran_hybrid_deployment_agent" "test_lpa" { provider = fivetran-provider display_name = "display_name" @@ -66,12 +66,12 @@ func TestResourceHybridDeploymentAgentMock(t *testing.T) { tfmock.AssertEqual(t, hybridDeploymentAgentPostHandler.Interactions, 1) return nil }, - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "display_name", "display_name"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "group_id", "group_id"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "registered_at", "registered_at"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "config_json", "config_json"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "auth_json", "auth_json"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "docker_compose_yaml", "docker_compose_yaml"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "display_name", "display_name"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "group_id", "group_id"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "registered_at", "registered_at"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "config_json", "config_json"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "auth_json", "auth_json"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "docker_compose_yaml", "docker_compose_yaml"), ), } diff --git a/fivetran/tests/e2e/resource_local_processing_agent_e2e_test.go b/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go similarity index 86% rename from fivetran/tests/e2e/resource_local_processing_agent_e2e_test.go rename to fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go index 810e6d20..14df6aa2 100644 --- a/fivetran/tests/e2e/resource_local_processing_agent_e2e_test.go +++ b/fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go @@ -24,15 +24,15 @@ func TestResourceHybridDeploymentAgentE2E(t *testing.T) { name = "TestResourceHybridDeploymentAgentE2E" } - resource "fivetran_local_processing_agent" "test_lpa" { + resource "fivetran_hybrid_deployment_agent" "test_lpa" { provider = fivetran-provider display_name = "TestResourceHybridDeploymentAgentE2E" group_id = fivetran_group.testgroup.id }`, Check: resource.ComposeAggregateTestCheckFunc( - testFivetranHybridDeploymentAgentResourceCreate(t, "fivetran_local_processing_agent.test_lpa"), - resource.TestCheckResourceAttr("fivetran_local_processing_agent.test_lpa", "display_name", "TestResourceHybridDeploymentAgentE2E"), + testFivetranHybridDeploymentAgentResourceCreate(t, "fivetran_hybrid_deployment_agent.test_lpa"), + resource.TestCheckResourceAttr("fivetran_hybrid_deployment_agent.test_lpa", "display_name", "TestResourceHybridDeploymentAgentE2E"), ), }, }, @@ -55,7 +55,7 @@ func testFivetranHybridDeploymentAgentResourceCreate(t *testing.T, resourceName func testFivetranHybridDeploymentAgentResourceDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { - if rs.Type != "fivetran_local_processing_agent" { + if rs.Type != "fivetran_hybrid_deployment_agent" { continue }