diff --git a/examples/test-upgrade/v100/design-id-reference/alert-configuration/main.tf b/examples/test-upgrade/v100/design-id-reference/alert-configuration/main.tf new file mode 100644 index 0000000000..3f4ee4aa28 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/alert-configuration/main.tf @@ -0,0 +1,43 @@ +data "mongodbatlas_project" "test" { + name = var.project_name +} + +resource "mongodbatlas_alert_configuration" "test" { + project_id = data.mongodbatlas_project.test.id + event_type = "OUTSIDE_METRIC_THRESHOLD" + enabled = true + + notification { + type_name = "GROUP" + interval_min = 5 + delay_min = 0 + sms_enabled = false + email_enabled = true + } + + matcher { + field_name = "HOSTNAME_AND_PORT" + operator = "EQUALS" + value = "SECONDARY" + } + + metric_threshold = { + metric_name = "ASSERT_REGULAR" + operator = "LESS_THAN" + threshold = 99.0 + units = "RAW" + mode = "AVERAGE" + } +} + +data "mongodbatlas_alert_configuration" "test" { + project_id = mongodbatlas_alert_configuration.test.project_id + alert_configuration_id = mongodbatlas_alert_configuration.test.id +} + +output "alert_id_state" { + value = mongodbatlas_alert_configuration.test.id +} +output "alert_configuration_id" { + value = mongodbatlas_alert_configuration.test.alert_configuration_id +} diff --git a/examples/test-upgrade/v100/design-id-reference/alert-configuration/variables.tf b/examples/test-upgrade/v100/design-id-reference/alert-configuration/variables.tf new file mode 100644 index 0000000000..fcc3d4db7f --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/alert-configuration/variables.tf @@ -0,0 +1,12 @@ +variable "public_key" { + description = "The public API key for MongoDB Atlas" + default = "" +} +variable "private_key" { + description = "The private API key for MongoDB Atlas" + default = "" +} +variable "project_name" { + description = "Atlas project name" + default = "" +} diff --git a/examples/test-upgrade/v100/design-id-reference/alert-configuration/versions.tf b/examples/test-upgrade/v100/design-id-reference/alert-configuration/versions.tf new file mode 100644 index 0000000000..7335622507 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/alert-configuration/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "0.1.0-dev" + } + } + required_version = ">= 0.13" +} diff --git a/examples/test-upgrade/v100/design-id-reference/network/main.tf b/examples/test-upgrade/v100/design-id-reference/network/main.tf new file mode 100644 index 0000000000..f941dd391e --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/network/main.tf @@ -0,0 +1,38 @@ +data "mongodbatlas_project" "test" { + name = var.project_name +} + +resource "mongodbatlas_network_container" "test" { + project_id = data.mongodbatlas_project.test.id + atlas_cidr_block = "192.168.208.0/21" + provider_name = "AWS" + region_name = var.region_name +} + +resource "mongodbatlas_network_peering" "test" { + accepter_region_name = lower(replace(var.region_name, "_", "-")) + project_id = data.mongodbatlas_project.test.id + container_id = mongodbatlas_network_container.test.id + provider_name = "AWS" + route_table_cidr_block = var.route_table_cidr_block + vpc_id = var.vpc_id + aws_account_id = var.aws_account_id +} + +data "mongodbatlas_network_peering" "test" { + project_id = data.mongodbatlas_project.test.id + peering_id = mongodbatlas_network_peering.test.peer_id +} + +output "container_id_state" { + value = mongodbatlas_network_container.test.id +} +output "container_id" { + value = mongodbatlas_network_container.test.container_id +} +output "peering_id_state" { + value = mongodbatlas_network_peering.test.id +} +output "peer_id" { + value = mongodbatlas_network_peering.test.peer_id +} diff --git a/examples/test-upgrade/v100/design-id-reference/network/variables.tf b/examples/test-upgrade/v100/design-id-reference/network/variables.tf new file mode 100644 index 0000000000..5e157f4301 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/network/variables.tf @@ -0,0 +1,30 @@ +variable "public_key" { + description = "The public API key for MongoDB Atlas" + default = "" +} +variable "private_key" { + description = "The private API key for MongoDB Atlas" + default = "" +} +variable "project_name" { + description = "Atlas project name" + default = "" +} +variable "region_name" { + description = "AWS region " + default = "" +} +variable "route_table_cidr_block" { + description = "CIDR Block" + default = "" +} +variable "vpc_id" { + description = "AWS VPC ID" + default = "" +} +variable "aws_account_id" { + description = "AWS account id" + default = "" +} + + diff --git a/examples/test-upgrade/v100/design-id-reference/network/versions.tf b/examples/test-upgrade/v100/design-id-reference/network/versions.tf new file mode 100644 index 0000000000..7335622507 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/network/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "0.1.0-dev" + } + } + required_version = ">= 0.13" +} diff --git a/examples/test-upgrade/v100/design-id-reference/privatelink/main.tf b/examples/test-upgrade/v100/design-id-reference/privatelink/main.tf new file mode 100644 index 0000000000..6b7800e042 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/privatelink/main.tf @@ -0,0 +1,56 @@ +data "mongodbatlas_project" "test" { + name = var.project_name +} + +provider "aws" { + region = "us-west-1" + access_key = var.aws_access_key + secret_key = var.aws_secret_key +} + +resource "mongodbatlas_privatelink_endpoint" "test" { + project_id = data.mongodbatlas_project.test.id + provider_name = "AWS" + region = "us-west-1" +} + +resource "aws_vpc_endpoint" "ptfe_service" { + vpc_id = var.aws_vpc_id + service_name = mongodbatlas_privatelink_endpoint.test.endpoint_service_name + vpc_endpoint_type = "Interface" + subnet_ids = [var.aws_subnet_ids] + security_group_ids = [var.aws_sg_ids] +} + +resource "mongodbatlas_privatelink_endpoint_service" "test" { + project_id = data.mongodbatlas_project.test.id + private_link_id = mongodbatlas_privatelink_endpoint.test.id + endpoint_service_id = aws_vpc_endpoint.ptfe_service.id + provider_name = "AWS" +} + +data "mongodbatlas_privatelink_endpoint" "test" { + project_id = data.mongodbatlas_project.test.id + private_link_id = mongodbatlas_privatelink_endpoint.test.id + provider_name = "AWS" +} + +data "mongodbatlas_privatelink_endpoint_service" "test" { + project_id = data.mongodbatlas_project.test.id + private_link_id = mongodbatlas_privatelink_endpoint_service.test.id + endpoint_service_id = mongodbatlas_privatelink_endpoint_service.test.endpoint_service_id + provider_name = "AWS" +} + +output "privatelink_id_state" { + value = mongodbatlas_privatelink_endpoint.test.id +} +output "private_link_id" { + value = mongodbatlas_privatelink_endpoint.test.private_link_id +} +output "privatelink_endpoint_service_state" { + value = mongodbatlas_privatelink_endpoint_service.test.id +} +output "endpoint_service_id" { + value = mongodbatlas_privatelink_endpoint_service.test.endpoint_service_id +} \ No newline at end of file diff --git a/examples/test-upgrade/v100/design-id-reference/privatelink/variables.tf b/examples/test-upgrade/v100/design-id-reference/privatelink/variables.tf new file mode 100644 index 0000000000..2447e6ec89 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/privatelink/variables.tf @@ -0,0 +1,41 @@ +variable "public_key" { + description = "The public API key for MongoDB Atlas" + default = "" +} +variable "private_key" { + description = "The private API key for MongoDB Atlas" + default = "" +} +variable "project_name" { + description = "Atlas project name" + default = "" +} +variable "org_id" { + description = "The organization ID" + default = "" +} +variable "role_name" { + description = "The role name" + default = "" +} +variable "aws_access_key" { + description = "The access key for AWS Account" + default = "" +} +variable "aws_secret_key" { + description = "The secret key for AWS Account" + default = "" +} +variable "aws_vpc_id" { + description = "The secret key for AWS Account" + default = "" +} +variable "aws_subnet_ids" { + description = "The secret key for AWS Account" + default = "" +} +variable "aws_sg_ids" { + description = "The secret key for AWS Account" + default = "" +} + diff --git a/examples/test-upgrade/v100/design-id-reference/privatelink/versions.tf b/examples/test-upgrade/v100/design-id-reference/privatelink/versions.tf new file mode 100644 index 0000000000..15f108145c --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/privatelink/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "0.1.0-dev" + } + } + required_version = ">= 0.13" +} + diff --git a/examples/test-upgrade/v100/design-id-reference/project/main.tf b/examples/test-upgrade/v100/design-id-reference/project/main.tf new file mode 100644 index 0000000000..ddd07ca25e --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/project/main.tf @@ -0,0 +1,8 @@ +resource "mongodbatlas_project" "test" { + name = var.project_name + org_id = var.org_id +} + +output "project_id" { + value = mongodbatlas_project.test.id +} diff --git a/examples/test-upgrade/v100/design-id-reference/project/variables.tf b/examples/test-upgrade/v100/design-id-reference/project/variables.tf new file mode 100644 index 0000000000..0d51b6472c --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/project/variables.tf @@ -0,0 +1,16 @@ +variable "public_key" { + description = "The public API key for MongoDB Atlas" + default = "" +} +variable "private_key" { + description = "The private API key for MongoDB Atlas" + default = "" +} +variable "project_name" { + description = "Atlas project name" + default = "" +} +variable "org_id" { + description = "The organization ID" + default = "" +} \ No newline at end of file diff --git a/examples/test-upgrade/v100/design-id-reference/project/versions.tf b/examples/test-upgrade/v100/design-id-reference/project/versions.tf new file mode 100644 index 0000000000..7335622507 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/project/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "0.1.0-dev" + } + } + required_version = ">= 0.13" +} diff --git a/examples/test-upgrade/v100/design-id-reference/snapshot-restore/main.tf b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/main.tf new file mode 100644 index 0000000000..326255eb3a --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/main.tf @@ -0,0 +1,51 @@ +data "mongodbatlas_project" "test" { + name = var.project_name +} + +resource "mongodbatlas_cluster" "my_cluster" { + project_id = data.mongodbatlas_project.test.id + name = var.cluster_name + disk_size_gb = 5 + + // Provider Settings "block" + provider_name = "AWS" + provider_region_name = "US_EAST_1" + provider_instance_size_name = "M10" + provider_backup_enabled = true //enable cloud provider snapshots + provider_encrypt_ebs_volume = false +} + +resource "mongodbatlas_cloud_provider_snapshot" "test" { + project_id = data.mongodbatlas_project.test.id + cluster_name = mongodbatlas_cluster.my_cluster.name + description = var.description + retention_in_days = var.retention_in_days +} + +resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { + project_id = data.mongodbatlas_project.test.id + cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name + snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id + delivery_type = { + download = true + } +} + +data "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { + project_id = data.mongodbatlas_project.test.id + cluster_name = mongodbatlas_cloud_provider_snapshot_restore_job.test.cluster_name + job_id = mongodbatlas_cloud_provider_snapshot_restore_job.test.id +} + +output "snapshot_id_state" { + value = mongodbatlas_cloud_provider_snapshot.test.id +} +output "snapshot_id" { + value = mongodbatlas_cloud_provider_snapshot.test.snapshot_id +} +output "snapshot_restore_id_state" { + value = mongodbatlas_cloud_provider_snapshot_restore_job.test.id +} +output "snapshot_restore_job_id" { + value = mongodbatlas_cloud_provider_snapshot_restore_job.test.snapshot_restore_job_id +} \ No newline at end of file diff --git a/examples/test-upgrade/v100/design-id-reference/snapshot-restore/variables.tf b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/variables.tf new file mode 100644 index 0000000000..cc9cf8dea0 --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/variables.tf @@ -0,0 +1,24 @@ +variable "public_key" { + description = "The public API key for MongoDB Atlas" + default = "" +} +variable "private_key" { + description = "The private API key for MongoDB Atlas" + default = "" +} +variable "project_name" { + description = "Atlas project name" + default = "" +} +variable "cluster_name" { + description = "Cluster name" + default = "" +} +variable "description" { + description = "Description" + default = "" +} +variable "retention_in_days" { + description = "Retention in days" + default = "" +} \ No newline at end of file diff --git a/examples/test-upgrade/v100/design-id-reference/snapshot-restore/versions.tf b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/versions.tf new file mode 100644 index 0000000000..15f108145c --- /dev/null +++ b/examples/test-upgrade/v100/design-id-reference/snapshot-restore/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "0.1.0-dev" + } + } + required_version = ">= 0.13" +} + diff --git a/integration-testing/test-upgrades_test.go b/integration-testing/test-upgrades_test.go index 67b9a290bf..3a2d629fd8 100644 --- a/integration-testing/test-upgrades_test.go +++ b/integration-testing/test-upgrades_test.go @@ -337,6 +337,135 @@ func TestUpgradeProjectIPWhitelistDeprecation(t *testing.T) { } +func TestUpgradeDesignIDState(t *testing.T) { + t.Parallel() + mongoSecrets := GetCredentialsFromEnv() + awsSecrets := GetAWSCredentialsFromEnv() + + var ( + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + clusterName = acctest.RandomWithPrefix("test-acc") + description = fmt.Sprintf("My description in %s", clusterName) + retentionInDays = "1" + publicKey = mongoSecrets.PublicKey + privateKey = mongoSecrets.PrivateKey + awsAccess = awsSecrets.AccessKey + awsSecret = awsSecrets.SecretKey + awsVPC = os.Getenv("AWS_VPC_ID") + awsSubnets = os.Getenv("AWS_SUBNET_ID") + awsSG = os.Getenv("AWS_SECURITY_GROUP_ID") + vpcCIDRBlock = os.Getenv("AWS_VPC_CIDR_BLOCK") + awsAccountID = os.Getenv("AWS_ACCOUNT_ID") + awsRegion = awsSecrets.AwsRegion + ) + // Construct the terraform options with default retryable errors to handle the most common + // retryable errors in terraform testing. + terraformOptionsProject := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../examples/test-upgrade/v100/design-id-reference/project", + Vars: map[string]interface{}{ + "project_name": projectName, + "org_id": orgID, + "public_key": publicKey, + "private_key": privateKey, + }, + }) + + // At the end of the test, run `terraform destroy` to clean up any resources that were created. + defer terraform.Destroy(t, terraformOptionsProject) + + // Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.RunTerraformCommand(t, terraformOptionsProject, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath)) + terraform.Apply(t, terraformOptionsProject) + + terraform.Plan(t, terraformOptionsProject) + + // Alert Configuration + + terraformOptionsAlertConfiguration := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../examples/test-upgrade/v100/design-id-reference/alert-configuration", + Vars: map[string]interface{}{ + "project_name": projectName, + }, + }) + // At the end of the test, run `terraform destroy` to clean up any resources that were created. + defer terraform.Destroy(t, terraformOptionsAlertConfiguration) + + // Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.RunTerraformCommand(t, terraformOptionsAlertConfiguration, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath)) + terraform.Apply(t, terraformOptionsAlertConfiguration) + + terraform.Plan(t, terraformOptionsAlertConfiguration) + + // Network container/peering + + terraformOptionsNetwork := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../examples/test-upgrade/v100/design-id-reference/network", + Vars: map[string]interface{}{ + "project_name": projectName, + "region_name": awsRegion, + "route_table_cidr_block": vpcCIDRBlock, + "vpc_id": awsVPC, + "aws_account_id": awsAccountID, + }, + }) + // At the end of the test, run `terraform destroy` to clean up any resources that were created. + defer terraform.Destroy(t, terraformOptionsNetwork) + + // Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.RunTerraformCommand(t, terraformOptionsNetwork, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath)) + terraform.Apply(t, terraformOptionsNetwork) + + terraform.Plan(t, terraformOptionsNetwork) + + // PrivateLink + + terraformOptionsPrivateLink := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../examples/test-upgrade/v100/design-id-reference/privatelink", + Vars: map[string]interface{}{ + "project_name": projectName, + "aws_access_key": awsAccess, + "aws_secret_key": awsSecret, + "aws_vpc_id": awsVPC, + "aws_subnet_ids": awsSubnets, + "aws_sg_ids": awsSG, + }, + }) + // At the end of the test, run `terraform destroy` to clean up any resources that were created. + defer terraform.Destroy(t, terraformOptionsPrivateLink) + + // Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.RunTerraformCommand(t, terraformOptionsPrivateLink, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath)) + terraform.Apply(t, terraformOptionsPrivateLink) + + terraform.Plan(t, terraformOptionsPrivateLink) + + // Snapshot Restore + + terraformOptionsSnapshotRestore := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../examples/test-upgrade/v100/design-id-reference/snapshot-restore", + Vars: map[string]interface{}{ + "project_name": projectName, + "cluster_name": clusterName, + "description": description, + "retention_in_days": retentionInDays, + }, + }) + // At the end of the test, run `terraform destroy` to clean up any resources that were created. + defer terraform.Destroy(t, terraformOptionsSnapshotRestore) + + // Run `terraform init` and `terraform apply`. Fail the test if there are any errors. + terraform.RunTerraformCommand(t, terraformOptionsSnapshotRestore, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath)) + terraform.Apply(t, terraformOptionsSnapshotRestore) + + terraform.Plan(t, terraformOptionsSnapshotRestore) +} + // This func means that the terraform state will be always clean to avoid error about resource already used func CleanUpState(t *testing.T, path string) string { // Root folder where terraform files should be (relative to the test folder) diff --git a/mongodbatlas/data_source_mongodbatlas_alert_configuration.go b/mongodbatlas/data_source_mongodbatlas_alert_configuration.go index cbfbf46e42..05c7af1bb0 100644 --- a/mongodbatlas/data_source_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/data_source_mongodbatlas_alert_configuration.go @@ -221,7 +221,7 @@ func dataSourceMongoDBAtlasAlertConfigurationRead(d *schema.ResourceData, meta i // Get client connection. conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - alertID := d.Get("alert_configuration_id").(string) + alertID := getEncodedID(d.Get("alert_configuration_id").(string), "id") alert, _, err := conn.AlertConfigurations.GetAnAlertConfig(context.Background(), projectID, alertID) if err != nil { diff --git a/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go b/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go index ca61bb6ffb..58a53a4adb 100644 --- a/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go @@ -87,7 +87,7 @@ func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string { data "mongodbatlas_alert_configuration" "test" { project_id = "${mongodbatlas_alert_configuration.test.project_id}" - alert_configuration_id = "${mongodbatlas_alert_configuration.test.alert_configuration_id}" + alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}" } `, projectID) } @@ -123,7 +123,7 @@ func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string data "mongodbatlas_alert_configuration" "test" { project_id = "${mongodbatlas_alert_configuration.test.project_id}" - alert_configuration_id = "${mongodbatlas_alert_configuration.test.alert_configuration_id}" + alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}" } `, projectID, enabled, threshold) } diff --git a/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job.go b/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job.go index fba8242b97..cb454d3989 100644 --- a/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job.go +++ b/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job.go @@ -95,7 +95,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobRead(d *schema.Resourc conn := meta.(*matlas.Client) requestParameters := &matlas.SnapshotReqPathParameters{ - JobID: d.Get("job_id").(string), + JobID: getEncodedID(d.Get("job_id").(string), "snapshot_restore_job_id"), GroupID: d.Get("project_id").(string), ClusterName: d.Get("cluster_name").(string), } diff --git a/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job_test.go b/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job_test.go index 01af954e80..6fa974be43 100644 --- a/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job_test.go +++ b/mongodbatlas/data_source_mongodbatlas_cloud_provider_snapshot_restore_job_test.go @@ -62,7 +62,7 @@ func testAccMongoDBAtlasDataSourceCloudProviderSnapshotRestoreJobConfig(projectI resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_provider_snapshot.test.project_id cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_provider_snapshot.test.snapshot_id + snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id delivery_type = { download = true } @@ -72,7 +72,7 @@ func testAccMongoDBAtlasDataSourceCloudProviderSnapshotRestoreJobConfig(projectI data "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_provider_snapshot_restore_job.test.project_id cluster_name = mongodbatlas_cloud_provider_snapshot_restore_job.test.cluster_name - job_id = mongodbatlas_cloud_provider_snapshot_restore_job.test.snapshot_restore_job_id + job_id = mongodbatlas_cloud_provider_snapshot_restore_job.test.id } `, projectID, clusterName, description, retentionInDays) } diff --git a/mongodbatlas/data_source_mongodbatlas_network_container.go b/mongodbatlas/data_source_mongodbatlas_network_container.go index 6aab0bcab8..f41f9120e4 100644 --- a/mongodbatlas/data_source_mongodbatlas_network_container.go +++ b/mongodbatlas/data_source_mongodbatlas_network_container.go @@ -76,7 +76,7 @@ func dataSourceMongoDBAtlasNetworkContainerRead(d *schema.ResourceData, meta int // Get client connection. conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - containerID := d.Get("container_id").(string) + containerID := getEncodedID(d.Get("container_id").(string), "container_id") container, resp, err := conn.Containers.Get(context.Background(), projectID, containerID) if err != nil { diff --git a/mongodbatlas/data_source_mongodbatlas_network_container_test.go b/mongodbatlas/data_source_mongodbatlas_network_container_test.go index 9ea87f3d10..04ddcfa7dd 100644 --- a/mongodbatlas/data_source_mongodbatlas_network_container_test.go +++ b/mongodbatlas/data_source_mongodbatlas_network_container_test.go @@ -94,7 +94,7 @@ func testAccMongoDBAtlasNetworkContainerDSConfig(projectName, orgID, cidrBlock s data "mongodbatlas_network_container" "test_ds" { project_id = mongodbatlas_network_container.test_ds.project_id - container_id = mongodbatlas_network_container.test_ds.container_id + container_id = mongodbatlas_network_container.test_ds.id } `, projectName, orgID, cidrBlock) } @@ -115,7 +115,7 @@ func testAccMongoDBAtlasNetworkContainerDSWithGCPRegionsConfig(projectName, orgI data "mongodbatlas_network_container" "test_ds" { project_id = mongodbatlas_network_container.test_ds.project_id - container_id = mongodbatlas_network_container.test_ds.container_id + container_id = mongodbatlas_network_container.test_ds.id } `, projectName, orgID, cidrBlock) } diff --git a/mongodbatlas/data_source_mongodbatlas_network_peering.go b/mongodbatlas/data_source_mongodbatlas_network_peering.go index aef66b8df8..e8088f4789 100644 --- a/mongodbatlas/data_source_mongodbatlas_network_peering.go +++ b/mongodbatlas/data_source_mongodbatlas_network_peering.go @@ -112,7 +112,7 @@ func dataSourceMongoDBAtlasNetworkPeeringRead(d *schema.ResourceData, meta inter // Get client connection. conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - peerID := d.Get("peering_id").(string) + peerID := getEncodedID(d.Get("peering_id").(string), "peer_id") peer, resp, err := conn.Peers.Get(context.Background(), projectID, peerID) if err != nil { @@ -213,7 +213,11 @@ func dataSourceMongoDBAtlasNetworkPeeringRead(d *schema.ResourceData, meta inter return fmt.Errorf("[WARN] Error setting provider_name for (%s): %s", d.Id(), err) } - d.SetId(peer.ID) + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "peer_id": peer.ID, + "provider_name": provider, + })) return nil } diff --git a/mongodbatlas/data_source_mongodbatlas_network_peering_test.go b/mongodbatlas/data_source_mongodbatlas_network_peering_test.go index c572f56f7c..d030415a74 100644 --- a/mongodbatlas/data_source_mongodbatlas_network_peering_test.go +++ b/mongodbatlas/data_source_mongodbatlas_network_peering_test.go @@ -56,7 +56,7 @@ func testAccDSMongoDBAtlasNetworkPeeringConfig(projectID, vpcID, awsAccountID, v } resource "mongodbatlas_network_peering" "basic" { - accepter_region_name = "us-east-1" + accepter_region_name = lower(replace("%[5]s", "_", "-")) project_id = "%[1]s" container_id = mongodbatlas_network_container.test.id provider_name = "AWS" @@ -67,7 +67,7 @@ func testAccDSMongoDBAtlasNetworkPeeringConfig(projectID, vpcID, awsAccountID, v data "mongodbatlas_network_peering" "test" { project_id = "%[1]s" - peering_id = mongodbatlas_network_peering.basic.id + peering_id = mongodbatlas_network_peering.basic.peer_id } `, projectID, vpcID, awsAccountID, vpcCIDRBlock, awsRegion) } diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint.go index 44322ac952..da123334a6 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint.go @@ -71,7 +71,7 @@ func dataSourceMongoDBAtlasPrivateLinkEndpointRead(d *schema.ResourceData, meta conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - privateLinkID := d.Get("private_link_id").(string) + privateLinkID := getEncodedID(d.Get("private_link_id").(string), "private_link_id") providerName := d.Get("provider_name").(string) privateEndpoint, _, err := conn.PrivateEndpoints.Get(context.Background(), projectID, providerName, privateLinkID) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go index 1d0fef2e62..a6c6d5a5ec 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go @@ -75,8 +75,8 @@ func dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - privateLinkID := d.Get("private_link_id").(string) - endpointServiceID := d.Get("endpoint_service_id").(string) + privateLinkID := getEncodedID(d.Get("private_link_id").(string), "private_link_id") + endpointServiceID := getEncodedID(d.Get("endpoint_service_id").(string), "endpoint_service_id") providerName := d.Get("provider_name").(string) serviceEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, endpointServiceID) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_test.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_test.go index 49e95aeb31..267caba69e 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_test.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_test.go @@ -41,7 +41,7 @@ func testAccMongoDBAtlasPrivateLinkEndpointDataSourceConfig(projectID, providerN data "mongodbatlas_privatelink_endpoint" "test" { project_id = mongodbatlas_privatelink_endpoint.test.project_id - private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id + private_link_id = mongodbatlas_privatelink_endpoint.test.id provider_name = "%[2]s" } `, projectID, providerName, region) diff --git a/mongodbatlas/provider.go b/mongodbatlas/provider.go index 18fc6c583e..f57f606e81 100644 --- a/mongodbatlas/provider.go +++ b/mongodbatlas/provider.go @@ -255,3 +255,23 @@ func expandStringList(list []interface{}) (res []string) { return } + +func getEncodedID(stateID, keyPosition string) string { + id := "" + if !hasMultipleValues(stateID) { + return stateID + } + + decoded := decodeStateID(stateID) + id = decoded[keyPosition] + + return id +} + +func hasMultipleValues(value string) bool { + if strings.Contains(value, "-") && strings.Contains(value, ":") { + return true + } + + return false +} diff --git a/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job.go b/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job.go index a9f147d3f0..1b16cfcb0d 100644 --- a/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job.go +++ b/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job.go @@ -189,7 +189,7 @@ func resourceMongoDBAtlasCloudProviderSnapshotRestoreJobCreate(d *schema.Resourc } snapshotReq := &matlas.CloudProviderSnapshotRestoreJob{ - SnapshotID: d.Get("snapshot_id").(string), + SnapshotID: getEncodedID(d.Get("snapshot_id").(string), "snapshot_id"), DeliveryType: deliveryType, TargetClusterName: d.Get("delivery_type.target_cluster_name").(string), TargetGroupID: d.Get("delivery_type.target_project_id").(string), diff --git a/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job_test.go b/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job_test.go index a80b476831..385be761aa 100644 --- a/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job_test.go +++ b/mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot_restore_job_test.go @@ -75,7 +75,7 @@ func TestAccResourceMongoDBAtlasCloudProviderSnapshotRestoreJob_importBasic(t *t ImportStateIdFunc: testAccCheckMongoDBAtlasCloudProviderSnapshotRestoreJobImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"retention_in_days"}, + ImportStateVerifyIgnore: []string{"retention_in_days", "snapshot_id"}, }, }, }) @@ -209,7 +209,7 @@ func testAccMongoDBAtlasCloudProviderSnapshotRestoreJobConfigAutomated(projectID resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_provider_snapshot.test.project_id cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_provider_snapshot.test.snapshot_id + snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id delivery_type = { automated = true target_cluster_name = "%s" @@ -244,7 +244,7 @@ func testAccMongoDBAtlasCloudProviderSnapshotRestoreJobConfigDownload(projectID, resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_provider_snapshot.test.project_id cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_provider_snapshot.test.snapshot_id + snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id delivery_type = { download = true } @@ -291,7 +291,7 @@ func testAccMongoDBAtlasCloudProviderSnapshotRestoreJobConfigPointInTime(project resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_provider_snapshot.test.project_id cluster_name = mongodbatlas_cloud_provider_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_provider_snapshot.test.snapshot_id + snapshot_id = mongodbatlas_cloud_provider_snapshot.test.id delivery_type = { point_in_time = true diff --git a/mongodbatlas/resource_mongodbatlas_network_peering.go b/mongodbatlas/resource_mongodbatlas_network_peering.go index cc5a3e0803..fe7a497340 100644 --- a/mongodbatlas/resource_mongodbatlas_network_peering.go +++ b/mongodbatlas/resource_mongodbatlas_network_peering.go @@ -58,7 +58,6 @@ func resourceMongoDBAtlasNetworkPeering() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "provider_name": { Type: schema.TypeString, Required: true, @@ -161,7 +160,7 @@ func resourceMongoDBAtlasNetworkPeeringCreate(d *schema.ResourceData, meta inter // Get the required ones peerRequest := &matlas.Peer{ - ContainerID: d.Get("container_id").(string), + ContainerID: getEncodedID(d.Get("container_id").(string), "container_id"), ProviderName: providerName, } @@ -405,7 +404,7 @@ func resourceMongoDBAtlasNetworkPeeringUpdate(d *schema.ResourceData, meta inter // All the request to update the peer require the ProviderName and ContainerID attribute. peer := &matlas.Peer{ ProviderName: ids["provider_name"], - ContainerID: d.Get("container_id").(string), + ContainerID: getEncodedID(d.Get("container_id").(string), "container_id"), } // Depending of the Provider name the request will be set diff --git a/mongodbatlas/resource_mongodbatlas_network_peering_test.go b/mongodbatlas/resource_mongodbatlas_network_peering_test.go index fcb921cd3a..3d5001f915 100644 --- a/mongodbatlas/resource_mongodbatlas_network_peering_test.go +++ b/mongodbatlas/resource_mongodbatlas_network_peering_test.go @@ -48,7 +48,7 @@ func TestAccResourceMongoDBAtlasNetworkPeering_basicAWS(t *testing.T) { ImportStateIdFunc: testAccCheckMongoDBAtlasNetworkPeeringImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"accepter_region_name"}, + ImportStateVerifyIgnore: []string{"accepter_region_name", "container_id"}, }, }, }) @@ -88,7 +88,7 @@ func TestAccResourceMongoDBAtlasNetworkPeering_basicAzure(t *testing.T) { ImportStateIdFunc: testAccCheckMongoDBAtlasNetworkPeeringImportStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"atlas_cidr_block"}, + ImportStateVerifyIgnore: []string{"atlas_cidr_block", "container_id"}, }, }, }) @@ -268,7 +268,7 @@ func testAccMongoDBAtlasNetworkPeeringConfigAWS(projectID, providerName, vpcID, resource "mongodbatlas_network_peering" "test" { accepter_region_name = lower(replace("%[6]s", "_", "-")) project_id = "%[1]s" - container_id = mongodbatlas_network_container.test.container_id + container_id = mongodbatlas_network_container.test.id provider_name = "%[2]s" route_table_cidr_block = "%[5]s" vpc_id = "%[3]s" diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go index e13dd62826..5017cdf96c 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go @@ -93,7 +93,7 @@ func resourceMongoDBAtlasPrivateEndpointServiceLink() *schema.Resource { func resourceMongoDBAtlasPrivateEndpointServiceLinkCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*matlas.Client) projectID := d.Get("project_id").(string) - privateLinkID := d.Get("private_link_id").(string) + privateLinkID := getEncodedID(d.Get("private_link_id").(string), "private_link_id") providerName := d.Get("provider_name").(string) endpointServiceID := d.Get("endpoint_service_id").(string) @@ -181,10 +181,6 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData, return fmt.Errorf(errorEndpointSetting, "endpoint_service_id", endpointServiceID, err) } - if err := d.Set("private_link_id", privateLinkID); err != nil { - return fmt.Errorf(errorEndpointSetting, "private_link_id", endpointServiceID, err) - } - return nil } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go index f6c7da2d91..899035d6d6 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go @@ -80,10 +80,11 @@ func TestAccResourceMongoDBAtlasPrivateLinkEndpointServiceAWS_import(t *testing. ), }, { - ResourceName: resourceName, - ImportStateIdFunc: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceImportStateIDFunc(resourceName), - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportStateIdFunc: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceImportStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"private_link_id"}, }, }, }) @@ -170,7 +171,7 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(awsAccessKey resource "mongodbatlas_privatelink_endpoint_service" "test" { project_id = mongodbatlas_privatelink_endpoint.test.project_id endpoint_service_id = aws_vpc_endpoint.ptfe_service.id - private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id + private_link_id = mongodbatlas_privatelink_endpoint.test.id provider_name = "%[4]s" } `, awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID)