Skip to content

Commit

Permalink
Fix LPA_ID issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-aleksandrboldyrev committed Nov 15, 2024
1 parent 250421a commit 4c03fae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 2 additions & 8 deletions fivetran/framework/core/model/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = types.StringValue(c.HybridDeploymentAgentId)
} else {
d.LocalProcessingAgentId = types.StringNull()
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = types.StringValue(value)
} else {
d.LocalProcessingAgentId = types.StringNull()
Expand Down
3 changes: 3 additions & 0 deletions fivetran/tests/e2e/fivetran_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ func cleanupPrivateLinks() {
}

func cleanupHybridDeploymentAgents() {
// this methods hides under FF
return;

lpaList, err := client.NewHybridDeploymentAgentList().Do(context.Background())
if err != nil {
log.Fatal(err)
Expand Down
56 changes: 55 additions & 1 deletion fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"testing"
"regexp"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand Down Expand Up @@ -41,13 +42,66 @@ func TestResourceHybridDeploymentAgentE2E(t *testing.T) {
})
}

func TestResourceConnectorWithHybridDeploymentAgentE2E(t *testing.T) {
regexp, _ := regexp.Compile("[a-z]*_[a-z]*")
resource.Test(t, resource.TestCase{
PreCheck: func() {},
ProtoV6ProviderFactories: ProtoV6ProviderFactories,
CheckDestroy: testFivetranConnectorResourceDestroy,
Steps: []resource.TestStep{
{
Config: `
resource "fivetran_group" "test_group" {
provider = fivetran-provider
name = "test_group_name"
}
resource "fivetran_hybrid_deployment_agent" "test_hda" {
provider = fivetran-provider
display_name = "TestResourceHybridDeploymentAgentE2E"
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
}
`,
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 {
fmt.Printf("sadasasas")

return func(s *terraform.State) error {
rs := GetResource(t, s, resourceName)
fmt.Printf("sdfsdsdsdf %v", rs.Primary.ID)

_, err := client.NewHybridDeploymentAgentDetails().AgentId(rs.Primary.ID).Do(context.Background())
if err != nil {
fmt.Println(err)
fmt.Printf("sdfsdsdsdf %v %v", rs.Primary.ID, err)
return err
}
//todo: check response _ fields if needed
Expand Down

0 comments on commit 4c03fae

Please sign in to comment.