fivetran / terraform-provider-fivetran

Terraform Provider for Fivetran
https://fivetran.com
Apache License 2.0
41 stars 22 forks source link

Imported Connectors and Destinations Missing Various Configs #271

Closed codybswaney closed 4 months ago

codybswaney commented 4 months ago

Describe the bug When importing a connector via terraform import fivetran_connector.example ${CONNECTOR_ID} or importing a destination via terraform import fivetran_destination.example ${DESTINATION_ID}, the config values are not populated into the state. However, when looking at data sources I am able to see these configurations.

To Reproduce

First, define an empty connector (or destination)

resource "fivetran_connector" "example" {}

Now import via terraform import fivetran_connector.example ${CONNECTOR_ID}

On a terraform show, the config is missing:

resource "fivetran_connector" "example" {
    connected_by = "land_disputing"
    created_at   = "2022-09-10 00:12:15.20883 +0000 UTC"
    group_id     = "perusal_furiously"
    id           = "planned_placate"
    name         = "rds_postgres"
    service      = "postgres_rds"

    destination_schema {
        prefix = "rds_postgres"
    }
}

However, data sources show the config value. Given the following data resource....

data "fivetran_connector" "example" {
  id = "planned_placate"
}

A terraform show has config values

data "fivetran_connector" "example" {
    connected_by      = "land_disputing"
    created_at        = "2022-09-10 00:12:15.20883 +0000 UTC"
    failed_at         = "2023-11-18 09:10:10.287 +0000 UTC"
    group_id          = "perusal_furiously"
    id                = "planned_placate"
    name              = "rds_postgres"
    pause_after_trial = false
    paused            = false
    schedule_type     = "auto"
    service           = "postgres_rds"
    service_version   = "0"
    succeeded_at      = "2024-03-12 09:25:10.867 +0000 UTC"
    sync_frequency    = 1440

    config {
        always_encrypted = true
        connection_type  = "Directly"
        database         = "postgres"
        host             = "{{REDACTED}}"
        password         = (sensitive value)
        port             = 5432
        public_key       = <<-EOT
            {{REDACTED}}
        EOT
        update_method    = "TELEPORT"
        user             = "fivetran_a"
    }

    destination_schema {
        prefix = "rds_postgres"
    }

    status {
        is_historical_sync = false
        setup_state        = "connected"
        sync_state         = "scheduled"
        tasks              = []
        update_state       = "on_schedule"
        warnings           = [
            {
                code    = "p2020_teleport_sync_error"
                message = "Teleport Sync Error"
            },
        ]
    }
}

Expected behavior Imports of existing connectors and destinations contain relevant config that matches what is fetched by data sources.

Logs & Output

Nothing of note when importing... terraform show plans above

$ terraform import fivetran_connector.example planned_placate
fivetran_connector.example: Importing from ID "planned_placate"...
fivetran_connector.example: Import prepared!
  Prepared fivetran_connector for import
fivetran_connector.example: Refreshing state... [id=planned_placate]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Releasing state lock. This may take a few moments...

Plugin version: 1.1.15

Additional context N/A

beevital commented 4 months ago

Hi @codybswaney! We do not read config if it's not managed in .tf configuration - it causes problems because some connectors always have some non-null fields and it produces unwanted changes even is config section is omited. But looks like it's a problem for import operation. We will take a look what could be done.

beevital commented 4 months ago

https://github.com/fivetran/terraform-provider-fivetran/pull/272 for fix

codybswaney commented 4 months ago

Excellent, thank you so much @beevital

codybswaney commented 4 months ago

Just a note @beevital that this doesn't seem to be fixed in either 1.1.16 nor 1.1.17, at least for destinations to BigQuery.

First upgrade to newer backend

$ terraform init -upgrade

Initializing the backend...

Initializing provider plugins...
- Finding fivetran/fivetran versions matching ">= 1.1.16"...
- Installing fivetran/fivetran v1.1.17...
- Installed fivetran/fivetran v1.1.17 (signed by a HashiCorp partner, key ID BD40EF4531102765)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Now import into a record like this

resource "fivetran_destination" "example" {}
$ terraform import fivetran_destination.example perusal_furiously
fivetran_destination.example: Importing from ID "perusal_furiously"...
fivetran_destination.example: Import prepared!
  Prepared fivetran_destination for import
fivetran_destination.example: Refreshing state... [id=perusal_furiously]
data.fivetran_connector.conn: Reading...
data.fivetran_connector.conn: Read complete after 5s [id=planned_placate]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Now terraform show still has an empty config

# fivetran_destination.example:
resource "fivetran_destination" "example" {
    group_id         = "perusal_furiously"
    id               = "perusal_furiously"
    region           = "GCP_US_EAST4"
    service          = "big_query"
    setup_status     = "connected"
    time_zone_offset = "-8"

    config {}
}
codybswaney commented 4 months ago

Note that this is the case even if I specify some parts of config before importing; i.e. with some config block before the import, the state still shows no config

resource "fivetran_destination" "example" {
  config {
    project_id = "my-project-id"
  }
}