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

INTMDB-921: [Terraform] Migrate to terraform-plugin-testing #1301

Merged
merged 7 commits into from
Jul 20, 2023

Conversation

andreaangiolillo
Copy link
Collaborator

@andreaangiolillo andreaangiolillo commented Jul 10, 2023

Description

Ticket: INTMDB-921

As a pre-requisite to migration to Terraform Plugin Framework, we need to migrate our provider's acceptance testing dependencies from SDKv2 to the plugin testing module. This link gives more information about the migration steps: https://developer.hashicorp.com/terraform/plugin/testing/migrating

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code

Further comments

@andreaangiolillo andreaangiolillo marked this pull request as ready for review July 19, 2023 09:39
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner July 19, 2023 09:39
@andreaangiolillo
Copy link
Collaborator Author

@maastha this PR is ready for review

@maastha
Copy link
Collaborator

maastha commented Jul 19, 2023

@andreaangiolillo PR LGTM, just one question, did we try testing any resources with this change with an existing/old version TF config just to be sure nothing breaks for users? As per HashiCorp we shouldn't expect any impact on customers but would still be good to know.

@andreaangiolillo
Copy link
Collaborator Author

did we try testing any resources with this change with an existing/old version TF config just to be sure nothing breaks for users? As per HashiCorp we shouldn't expect any impact on customers but would still be good to know.

I haven't updated any TF configuration of our Acceptance Tests so we are confident enough that this is not a breaking changes. In addition, we were already using id.UniqueId() in some resources before this PR so we know it works. Regarding the retry, this has been tested with the cluster acceptance tests. All other changes are on the acceptance tests imports and cannot have any user impact

@maastha
Copy link
Collaborator

maastha commented Jul 19, 2023

did we try testing any resources with this change with an existing/old version TF config just to be sure nothing breaks for users? As per HashiCorp we shouldn't expect any impact on customers but would still be good to know.

I haven't updated any TF configuration of our Acceptance Tests so we are confident enough that this is not a breaking changes. In addition, we were already using id.UniqueId() in some resources before this PR so we know it works. Regarding the retry, this has been tested with the cluster acceptance tests. All other changes are on the acceptance tests imports and cannot have any user impact

Right, but the idea of manually testing with existing configs is so that with user's existing state files, no changes are detected when they re-run their configurations. Acceptance tests create new resources and then read new state files which are created with the updated code.

@andreaangiolillo
Copy link
Collaborator Author

I will add an update once I tested the changes with a resource where I introduced id.UniqueId and another one where I introduced retry

@andreaangiolillo
Copy link
Collaborator Author

This is the configuration file that I used for the local tests: It creates 1 project (testing retry) , 1 advance cluster (testing retry), 2 advance cluster data sources - LIST AND GET (testing id)

resource "mongodbatlas_project" "atlas-project" {
  name   = "Andrea-Test-2"
  org_id = var.atlas_org_id
}

# Create an Atlas Advanced Cluster
resource "mongodbatlas_advanced_cluster" "atlas-cluster" {
  project_id             = mongodbatlas_project.atlas-project.id
  name                   = "Andrea-Test-2"
  cluster_type           = "REPLICASET"
  backup_enabled         = true
  pit_enabled            = true
  mongo_db_major_version = "6.0"
  replication_specs {
    region_configs {
      electable_specs {
        instance_size = "M30"
        node_count    = 3
      }
      auto_scaling {
        compute_enabled            = true
        compute_max_instance_size  = "M30"
        compute_min_instance_size  = "M10"
        compute_scale_down_enabled = true
        disk_gb_enabled            = true
      }
      analytics_specs {
        instance_size = "M30"
        node_count    = 1
      }
      analytics_auto_scaling {
        compute_enabled            = true
        compute_max_instance_size  = "M30"
        compute_min_instance_size  = "M10"
        compute_scale_down_enabled = true
        disk_gb_enabled            = true
      }
      priority      = 7
      provider_name = "AWS"
      region_name   = "US_EAST_1"
    }
  }
}

data "mongodbatlas_advanced_cluster" "cluster" {
  project_id = mongodbatlas_project.atlas-project.id
  name       = "INTMDB-920-Andrea"
}

data "mongodbatlas_advanced_clusters" "clusters" {
  project_id = mongodbatlas_project.atlas-project.id
}

Local test steps:

  1. run terraform init to download v1.10.2
  2. run terraform apply
  3. build the provider with local changes and add TF_CLI_CONFIG_FILE
  4. run terraform init to use local binary
  5. run terraform apply -> no changes were detected
  6. update the name of the cluster
  7. run terraform apply
  8. run terraform state show to see the resources in the state file
terraform state list

data.mongodbatlas_advanced_cluster.cluster
data.mongodbatlas_advanced_clusters.clusters
mongodbatlas_advanced_cluster.atlas-cluster
mongodbatlas_project.atlas-project
terraform state show data.mongodbatlas_advanced_cluster.cluster
# data.mongodbatlas_advanced_cluster.cluster:
data "mongodbatlas_advanced_cluster" "cluster" {
    advanced_configuration         = [
        {
            default_read_concern                 = ""
            default_write_concern                = ""
            fail_index_key_too_long              = false
            javascript_enabled                   = true
            minimum_enabled_tls_protocol         = "TLS1_2"
            no_table_scan                        = false
            oplog_min_retention_hours            = 0
            oplog_size_mb                        = 0
            sample_refresh_interval_bi_connector = 0
            sample_size_bi_connector             = 0
            transaction_lifetime_limit_seconds   = 0
        },
    ]
    backup_enabled                 = true
    bi_connector_config            = [
        {
            enabled         = false
            read_preference = "secondary"
        },
    ]
    cluster_type                   = "REPLICASET"
    connection_strings             = [
        {
            aws_private_link     = {}
            aws_private_link_srv = {}
            private              = ""
            private_endpoint     = []
            private_srv          = ""
            standard             = "mongodb://andrea-test-22-shard-00-00.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-01.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-02.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-03.tfu4f.mongodb-dev.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-xq9g9c-shard-0"
            standard_srv         = "mongodb+srv://andrea-test-22.tfu4f.mongodb-dev.net"
        },
    ]
    create_date                    = "2023-07-20T06:58:06Z"
    disk_size_gb                   = 40
    encryption_at_rest_provider    = "NONE"
    id                             = "64b8dafef5f3b93b108bff53"
    labels                         = []
    mongo_db_major_version         = "6.0"
    mongo_db_version               = "6.0.8"
    name                           = "Andrea-Test-22"
    paused                         = false
    pit_enabled                    = true
    project_id                     = "64b8d3219c4cdc3f9108e318"
    replication_specs              = [
        {
            container_id   = {
                "AWS:US_EAST_1" = "64b8d3243935461255ecb3c4"
            }
            id             = "64b8dafdf5f3b93b108bff4c"
            num_shards     = 1
            region_configs = [
                {
                    analytics_auto_scaling = [
                        {
                            compute_enabled            = true
                            compute_max_instance_size  = "M30"
                            compute_min_instance_size  = "M10"
                            compute_scale_down_enabled = true
                            disk_gb_enabled            = true
                        },
                    ]
                    analytics_specs        = [
                        {
                            disk_iops       = 3000
                            ebs_volume_type = "STANDARD"
                            instance_size   = "M30"
                            node_count      = 1
                        },
                    ]
                    auto_scaling           = [
                        {
                            compute_enabled            = true
                            compute_max_instance_size  = "M30"
                            compute_min_instance_size  = "M10"
                            compute_scale_down_enabled = true
                            disk_gb_enabled            = true
                        },
                    ]
                    backing_provider_name  = ""
                    electable_specs        = [
                        {
                            disk_iops       = 3000
                            ebs_volume_type = "STANDARD"
                            instance_size   = "M30"
                            node_count      = 3
                        },
                    ]
                    priority               = 7
                    provider_name          = "AWS"
                    read_only_specs        = [
                        {
                            disk_iops       = 3000
                            ebs_volume_type = "STANDARD"
                            instance_size   = "M30"
                            node_count      = 0
                        },
                    ]
                    region_name            = "US_EAST_1"
                },
            ]
            zone_name      = "ZoneName managed by Terraform"
        },
    ]
    root_cert_type                 = "ISRGROOTX1"
    state_name                     = "IDLE"
    termination_protection_enabled = false
    version_release_system         = "LTS"
}
terraform state show data.mongodbatlas_advanced_clusters.clusters
# data.mongodbatlas_advanced_clusters.clusters:
data "mongodbatlas_advanced_clusters" "clusters" {
    id         = "terraform-20230720071238396200000001"
    project_id = "64b8d3219c4cdc3f9108e318"
    results    = [
        {
            advanced_configuration         = [
                {
                    default_read_concern                 = ""
                    default_write_concern                = ""
                    fail_index_key_too_long              = false
                    javascript_enabled                   = true
                    minimum_enabled_tls_protocol         = "TLS1_2"
                    no_table_scan                        = false
                    oplog_min_retention_hours            = 0
                    oplog_size_mb                        = 0
                    sample_refresh_interval_bi_connector = 0
                    sample_size_bi_connector             = 0
                    transaction_lifetime_limit_seconds   = 0
                },
            ]
            backup_enabled                 = true
            bi_connector_config            = [
                {
                    enabled         = false
                    read_preference = "secondary"
                },
            ]
            cluster_type                   = "REPLICASET"
            connection_strings             = [
                {
                    aws_private_link     = {}
                    aws_private_link_srv = {}
                    private              = ""
                    private_endpoint     = []
                    private_srv          = ""
                    standard             = "mongodb://andrea-test-22-shard-00-00.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-01.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-02.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-03.tfu4f.mongodb-dev.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-xq9g9c-shard-0"
                    standard_srv         = "mongodb+srv://andrea-test-22.tfu4f.mongodb-dev.net"
                },
            ]
            create_date                    = "2023-07-20T06:58:06Z"
            disk_size_gb                   = 40
            encryption_at_rest_provider    = "NONE"
            labels                         = [
                {
                    key   = "Infrastructure Tool"
                    value = "MongoDB Atlas Terraform Provider"
                },
            ]
            mongo_db_major_version         = "6.0"
            mongo_db_version               = "6.0.8"
            name                           = "Andrea-Test-22"
            paused                         = false
            pit_enabled                    = true
            replication_specs              = [
                {
                    container_id   = {
                        "AWS:US_EAST_1" = "64b8d3243935461255ecb3c4"
                    }
                    id             = "64b8dafdf5f3b93b108bff4c"
                    num_shards     = 1
                    region_configs = [
                        {
                            analytics_auto_scaling = [
                                {
                                    compute_enabled            = true
                                    compute_max_instance_size  = "M30"
                                    compute_min_instance_size  = "M10"
                                    compute_scale_down_enabled = true
                                    disk_gb_enabled            = true
                                },
                            ]
                            analytics_specs        = [
                                {
                                    disk_iops       = 3000
                                    ebs_volume_type = "STANDARD"
                                    instance_size   = "M30"
                                    node_count      = 1
                                },
                            ]
                            auto_scaling           = [
                                {
                                    compute_enabled            = true
                                    compute_max_instance_size  = "M30"
                                    compute_min_instance_size  = "M10"
                                    compute_scale_down_enabled = true
                                    disk_gb_enabled            = true
                                },
                            ]
                            backing_provider_name  = ""
                            electable_specs        = [
                                {
                                    disk_iops       = 3000
                                    ebs_volume_type = "STANDARD"
                                    instance_size   = "M30"
                                    node_count      = 3
                                },
                            ]
                            priority               = 7
                            provider_name          = "AWS"
                            read_only_specs        = [
                                {
                                    disk_iops       = 3000
                                    ebs_volume_type = "STANDARD"
                                    instance_size   = "M30"
                                    node_count      = 0
                                },
                            ]
                            region_name            = "US_EAST_1"
                        },
                    ]
                    zone_name      = "ZoneName managed by Terraform"
                },
            ]
            root_cert_type                 = "ISRGROOTX1"
            state_name                     = "IDLE"
            termination_protection_enabled = false
            version_release_system         = "LTS"
        },
    ]
}
terraform state show mongodbatlas_advanced_cluster.atlas-cluster
# mongodbatlas_advanced_cluster.atlas-cluster:
resource "mongodbatlas_advanced_cluster" "atlas-cluster" {
    backup_enabled                 = true
    cluster_id                     = "64b8dafef5f3b93b108bff53"
    cluster_type                   = "REPLICASET"
    connection_strings             = [
        {
            aws_private_link     = {}
            aws_private_link_srv = {}
            private              = ""
            private_endpoint     = []
            private_srv          = ""
            standard             = "mongodb://andrea-test-22-shard-00-00.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-01.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-02.tfu4f.mongodb-dev.net:27017,andrea-test-22-shard-00-03.tfu4f.mongodb-dev.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-xq9g9c-shard-0"
            standard_srv         = "mongodb+srv://andrea-test-22.tfu4f.mongodb-dev.net"
        },
    ]
    create_date                    = "2023-07-20T06:58:06Z"
    disk_size_gb                   = 40
    encryption_at_rest_provider    = "NONE"
    id                             = "Y2x1c3Rlcl9pZA==:NjRiOGRhZmVmNWYzYjkzYjEwOGJmZjUz-Y2x1c3Rlcl9uYW1l:QW5kcmVhLVRlc3QtMjI=-cHJvamVjdF9pZA==:NjRiOGQzMjE5YzRjZGMzZjkxMDhlMzE4"
    mongo_db_major_version         = "6.0"
    mongo_db_version               = "6.0.8"
    name                           = "Andrea-Test-22"
    paused                         = false
    pit_enabled                    = true
    project_id                     = "64b8d3219c4cdc3f9108e318"
    root_cert_type                 = "ISRGROOTX1"
    state_name                     = "IDLE"
    termination_protection_enabled = false
    version_release_system         = "LTS"

    advanced_configuration {
        fail_index_key_too_long              = false
        javascript_enabled                   = true
        minimum_enabled_tls_protocol         = "TLS1_2"
        no_table_scan                        = false
        oplog_min_retention_hours            = 0
        oplog_size_mb                        = 0
        sample_refresh_interval_bi_connector = 0
        sample_size_bi_connector             = 0
        transaction_lifetime_limit_seconds   = 0
    }

    bi_connector {
        enabled         = false
        read_preference = "secondary"
    }

    bi_connector_config {
        enabled         = false
        read_preference = "secondary"
    }

    replication_specs {
        container_id = {
            "AWS:US_EAST_1" = "64b8d3243935461255ecb3c4"
        }
        id           = "64b8dafdf5f3b93b108bff4c"
        num_shards   = 1
        zone_name    = "ZoneName managed by Terraform"

        region_configs {
            priority      = 7
            provider_name = "AWS"
            region_name   = "US_EAST_1"

            analytics_auto_scaling {
                compute_enabled            = true
                compute_max_instance_size  = "M30"
                compute_min_instance_size  = "M10"
                compute_scale_down_enabled = true
                disk_gb_enabled            = true
            }

            analytics_specs {
                disk_iops     = 0
                instance_size = "M30"
                node_count    = 1
            }

            auto_scaling {
                compute_enabled            = true
                compute_max_instance_size  = "M30"
                compute_min_instance_size  = "M10"
                compute_scale_down_enabled = true
                disk_gb_enabled            = true
            }

            electable_specs {
                disk_iops     = 0
                instance_size = "M30"
                node_count    = 3
            }
        }
    }
}
terraform state show mongodbatlas_project.atlas-project

# mongodbatlas_project.atlas-project:
resource "mongodbatlas_project" "atlas-project" {
    cluster_count                                    = 1
    created                                          = "2023-07-20T06:24:34Z"
    id                                               = "64b8d3219c4cdc3f9108e318"
    is_collect_database_specifics_statistics_enabled = true
    is_data_explorer_enabled                         = true
    is_extended_storage_sizes_enabled                = false
    is_performance_advisor_enabled                   = true
    is_realtime_performance_panel_enabled            = true
    is_schema_advisor_enabled                        = true
    name                                             = "Andrea-Test-2"
    org_id                                           = "60ddf55c27a5a20955a707d7"
    with_default_alerts_settings                     = true

    api_keys {
        api_key_id = "23412312321312312"
        role_names = [
            "GROUP_OWNER",
        ]
    }
}

@andreaangiolillo
Copy link
Collaborator Author

@maastha ready for review

Copy link
Collaborator

@maastha maastha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @andreaangiolillo for this one! LGTM!

@andreaangiolillo andreaangiolillo merged commit 49c07e1 into master Jul 20, 2023
17 checks passed
@andreaangiolillo andreaangiolillo deleted the INTMDB-921_2 branch July 20, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants