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

New Resource & Data Source: azurerm_data_migration_service #5258

Merged
merged 19 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 15 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
121 changes: 62 additions & 59 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
compute "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/client"
containerServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/client"
cosmosdb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/client"
datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/client"
databricks "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/client"
datafactory "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/client"
datalake "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake/client"
Expand Down Expand Up @@ -73,65 +74,66 @@ type Client struct {
Account *ResourceManagerAccount
Features features.UserFeatures

AnalysisServices *analysisServices.Client
ApiManagement *apiManagement.Client
AppConfiguration *appConfiguration.Client
AppInsights *applicationInsights.Client
Authorization *authorization.Client
Automation *automation.Client
Batch *batch.Client
Bot *bot.Client
Cdn *cdn.Client
Cognitive *cognitiveServices.Client
Compute *compute.Client
Containers *containerServices.Client
Cosmos *cosmosdb.Client
DataBricks *databricks.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DevSpace *devspace.Client
DevTestLabs *devtestlabs.Client
Dns *dns.Client
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Frontdoor *frontdoor.Client
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTHub *iothub.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
ManagementGroups *managementgroup.Client
Maps *maps.Client
MariaDB *mariadb.Client
Media *media.Client
Monitor *monitor.Client
MSI *msi.Client
MSSQL *mssql.Client
MySQL *mysql.Client
NetApp *netapp.Client
Network *network.Client
NotificationHubs *notificationhub.Client
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Relay *relay.Client
Resource *resource.Client
Search *search.Client
SecurityCenter *securityCenter.Client
ServiceBus *serviceBus.Client
ServiceFabric *serviceFabric.Client
SignalR *signalr.Client
Storage *storage.Client
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
TrafficManager *trafficManager.Client
Web *web.Client
AnalysisServices *analysisServices.Client
ApiManagement *apiManagement.Client
AppConfiguration *appConfiguration.Client
AppInsights *applicationInsights.Client
Authorization *authorization.Client
Automation *automation.Client
Batch *batch.Client
Bot *bot.Client
Cdn *cdn.Client
Cognitive *cognitiveServices.Client
Compute *compute.Client
Containers *containerServices.Client
Cosmos *cosmosdb.Client
DatabaseMigration *datamigration.Client
DataBricks *databricks.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DevSpace *devspace.Client
DevTestLabs *devtestlabs.Client
Dns *dns.Client
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Frontdoor *frontdoor.Client
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTHub *iothub.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
ManagementGroups *managementgroup.Client
Maps *maps.Client
MariaDB *mariadb.Client
Media *media.Client
Monitor *monitor.Client
MSI *msi.Client
MSSQL *mssql.Client
MySQL *mysql.Client
NetApp *netapp.Client
Network *network.Client
NotificationHubs *notificationhub.Client
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Relay *relay.Client
Resource *resource.Client
Search *search.Client
SecurityCenter *securityCenter.Client
ServiceBus *serviceBus.Client
ServiceFabric *serviceFabric.Client
SignalR *signalr.Client
Storage *storage.Client
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
TrafficManager *trafficManager.Client
Web *web.Client
}

// NOTE: it should be possible for this method to become Private once the top level Client's removed
Expand All @@ -153,6 +155,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Compute = compute.NewClient(o)
client.Containers = containerServices.NewClient(o)
client.Cosmos = cosmosdb.NewClient(o)
client.DatabaseMigration = datamigration.NewClient(o)
client.DataBricks = databricks.NewClient(o)
client.DataFactory = datafactory.NewClient(o)
client.Datalake = datalake.NewClient(o)
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/provider/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func RequiredResourceProviders() map[string]struct{} {
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"Microsoft.DataMigration": {},
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake"
Expand Down Expand Up @@ -81,6 +82,7 @@ func SupportedServices() []common.ServiceRegistration {
databricks.Registration{},
datafactory.Registration{},
datalake.Registration{},
databasemigration.Registration{},
devspace.Registration{},
devtestlabs.Registration{},
dns.Registration{},
Expand Down
18 changes: 18 additions & 0 deletions azurerm/internal/services/databasemigration/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/datamigration/mgmt/2018-04-19/datamigration"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
ServicesClient *datamigration.ServicesClient
}

func NewClient(o *common.ClientOptions) *Client {
servicesClient := datamigration.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&servicesClient.Client, o.ResourceManagerAuthorizer)
return &Client{
ServicesClient: &servicesClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package databasemigration

import (
"fmt"
"time"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmDatabaseMigrationService() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDatabaseMigrationServiceRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateName,
magodo marked this conversation as resolved.
Show resolved Hide resolved
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

"subnet_id": {
Type: schema.TypeString,
Computed: true,
},

"sku_name": {
Type: schema.TypeString,
Computed: true,
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmDatabaseMigrationServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DatabaseMigration.ServicesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Data Migration Service (Service Name %q / Group Name %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error reading Data Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
magodo marked this conversation as resolved.
Show resolved Hide resolved

if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
d.Set("resource_group_name", resourceGroup)
d.Set("name", resp.Name)
if serviceProperties := resp.ServiceProperties; serviceProperties != nil {
d.Set("subnet_id", serviceProperties.VirtualSubnetID)
}
if resp.Sku != nil {
d.Set("sku_name", resp.Sku.Name)
}

return tags.FlattenAndSet(d, resp.Tags)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type DatabaseMigrationServiceId struct {
ResourceGroup string
Name string
}

func DatabaseMigrationServiceID(input string) (*DatabaseMigrationServiceId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse Database Migration Service ID %q: %+v", input, err)
}

server := DatabaseMigrationServiceId{
ResourceGroup: id.ResourceGroup,
}

if server.Name, err = id.PopSegment("services"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &server, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package parse

import (
"testing"
)

func TestDatabaseMigrationServiceID(t *testing.T) {
testData := []struct {
Name string
Input string
Error bool
Expect *DatabaseMigrationServiceId
}{
{
Name: "Empty",
Input: "",
Error: true,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Error: true,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Error: true,
},
{
Name: "No Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Error: true,
},
{
Name: "Missing service name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/services",
Error: true,
},
{
Name: "Service name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/services/service1",
Expect: &DatabaseMigrationServiceId{
ResourceGroup: "resGroup1",
Name: "service1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/Services/service1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Name)

actual, err := DatabaseMigrationServiceID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.ResourceGroup != v.Expect.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup)
}

if actual.Name != v.Expect.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name)
}
}
}
Loading