Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LPA_ID issue #377

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.IsNull(){
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.IsNull() {
d.LocalProcessingAgentId = types.StringValue(value)
} else {
d.LocalProcessingAgentId = types.StringNull()
Expand Down
18 changes: 0 additions & 18 deletions fivetran/tests/e2e/fivetran_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func cleanupAccount() {
cleanupTeams()
cleanupProxyAgents()
cleanupPrivateLinks()
cleanupHybridDeploymentAgents()
}

func isPredefinedUserExist() bool {
Expand Down Expand Up @@ -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()
}
}
92 changes: 79 additions & 13 deletions fivetran/tests/e2e/resource_hybrid_deployment_agent_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,114 @@ 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"),
),
},
},
})
}

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
Expand Down
2 changes: 1 addition & 1 deletion fivetran/tests/e2e/resource_private_link_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading