Skip to content

Commit

Permalink
Update databasemigration API version from 2018-04-19 to `2021-06-…
Browse files Browse the repository at this point in the history
…30` (#25997)

* Update `databasemigration` to use API version `2021-06-30`

* add test for MongoDb

* Update website documentation
  • Loading branch information
sebastiean authored May 16, 2024
1 parent 705db55 commit f9e5674
Show file tree
Hide file tree
Showing 59 changed files with 308 additions and 79 deletions.
4 changes: 2 additions & 2 deletions internal/services/databasemigration/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/projectresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/serviceresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/projectresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/serviceresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/projectresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/projectresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/databasemigration/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ data "azurerm_database_migration_project" "test" {
service_name = azurerm_database_migration_project.test.service_name
resource_group_name = azurerm_database_migration_project.test.resource_group_name
}
`, DatabaseMigrationProjectResource{}.basic(data))
`, DatabaseMigrationProjectResource{}.basic(data, "SQL", "SQLDB"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/projectresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/projectresource"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -66,8 +66,11 @@ func resourceDatabaseMigrationProject() *pluginsdk.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
// Now that go sdk only export SQL as source platform type, we only allow it here.
string(projectresource.ProjectSourcePlatformMongoDb),
string(projectresource.ProjectSourcePlatformMySQL),
string(projectresource.ProjectSourcePlatformPostgreSql),
string(projectresource.ProjectSourcePlatformSQL),
string(projectresource.ProjectSourcePlatformUnknown),
}, false),
},

Expand All @@ -76,8 +79,12 @@ func resourceDatabaseMigrationProject() *pluginsdk.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
// Now that go sdk only export SQL as source platform type, we only allow it here.
string(projectresource.ProjectTargetPlatformAzureDbForMySql),
string(projectresource.ProjectTargetPlatformAzureDbForPostgreSql),
string(projectresource.ProjectTargetPlatformMongoDb),
string(projectresource.ProjectTargetPlatformSQLDB),
string(projectresource.ProjectTargetPlatformSQLMI),
string(projectresource.ProjectTargetPlatformUnknown),
}, false),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/projectresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/projectresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand All @@ -18,12 +18,12 @@ import (

type DatabaseMigrationProjectResource struct{}

func TestAccDatabaseMigrationProject_basic(t *testing.T) {
func TestAccDatabaseMigrationProject_basicSQLToSQLDB(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test")
r := DatabaseMigrationProjectResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, "SQL", "SQLDB"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("source_platform").HasValue("SQL"),
Expand All @@ -34,6 +34,54 @@ func TestAccDatabaseMigrationProject_basic(t *testing.T) {
})
}

func TestAccDatabaseMigrationProject_basicPostgreSqlToAzureDbForPostgreSql(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test")
r := DatabaseMigrationProjectResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, "PostgreSql", "AzureDbForPostgreSql"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("source_platform").HasValue("PostgreSql"),
check.That(data.ResourceName).Key("target_platform").HasValue("AzureDbForPostgreSql"),
),
},
data.ImportStep(),
})
}

func TestAccDatabaseMigrationProject_basicMySQLToAzureDbForMySql(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test")
r := DatabaseMigrationProjectResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, "MySQL", "AzureDbForMySql"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("source_platform").HasValue("MySQL"),
check.That(data.ResourceName).Key("target_platform").HasValue("AzureDbForMySql"),
),
},
data.ImportStep(),
})
}

func TestAccDatabaseMigrationProject_basicMongoDbToMongoDb(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test")
r := DatabaseMigrationProjectResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, "MongoDb", "MongoDb"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("source_platform").HasValue("MongoDb"),
check.That(data.ResourceName).Key("target_platform").HasValue("MongoDb"),
),
},
data.ImportStep(),
})
}

func TestAccDatabaseMigrationProject_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test")
r := DatabaseMigrationProjectResource{}
Expand All @@ -58,7 +106,7 @@ func TestAccDatabaseMigrationProject_requiresImport(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, "SQL", "SQLDB"),
},
data.RequiresImportErrorStep(r.requiresImport),
})
Expand All @@ -70,7 +118,7 @@ func TestAccDatabaseMigrationProject_update(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, "SQL", "SQLDB"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -85,7 +133,7 @@ func TestAccDatabaseMigrationProject_update(t *testing.T) {
},
data.ImportStep(),
{
Config: r.basic(data),
Config: r.basic(data, "SQL", "SQLDB"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -108,7 +156,7 @@ func (t DatabaseMigrationProjectResource) Exists(ctx context.Context, clients *c
return utils.Bool(resp.Model != nil), nil
}

func (DatabaseMigrationProjectResource) basic(data acceptance.TestData) string {
func (DatabaseMigrationProjectResource) basic(data acceptance.TestData, sourcePlatform string, targetPlatform string) string {
return fmt.Sprintf(`
%s
Expand All @@ -117,10 +165,10 @@ resource "azurerm_database_migration_project" "test" {
service_name = azurerm_database_migration_service.test.name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
source_platform = "SQL"
target_platform = "SQLDB"
source_platform = "%s"
target_platform = "%s"
}
`, DatabaseMigrationServiceResource{}.basic(data), data.RandomInteger)
`, DatabaseMigrationServiceResource{}.basic(data), data.RandomInteger, sourcePlatform, targetPlatform)
}

func (DatabaseMigrationProjectResource) complete(data acceptance.TestData) string {
Expand All @@ -142,7 +190,7 @@ resource "azurerm_database_migration_project" "test" {
}

func (DatabaseMigrationProjectResource) requiresImport(data acceptance.TestData) string {
template := DatabaseMigrationProjectResource{}.basic(data)
template := DatabaseMigrationProjectResource{}.basic(data, "SQL", "SQLDB")
return fmt.Sprintf(`
%s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/serviceresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/serviceresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/databasemigration/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/serviceresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/serviceresource"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2018-04-19/serviceresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datamigration/2021-06-30/serviceresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f9e5674

Please sign in to comment.