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 4 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
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
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"
datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datamigration/client"
devspace "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/devspace/client"
devtestlabs "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/devtestlabs/client"
dns "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/client"
Expand Down Expand Up @@ -89,6 +90,7 @@ type Client struct {
DataBricks *databricks.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DataMigration *datamigration.Client
DevSpace *devspace.Client
DevTestLabs *devtestlabs.Client
Dns *dns.Client
Expand Down Expand Up @@ -157,6 +159,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.DataBricks = databricks.NewClient(o)
client.DataFactory = datafactory.NewClient(o)
client.Datalake = datalake.NewClient(o)
client.DataMigration = datamigration.NewClient(o)
client.DevSpace = devspace.NewClient(o)
client.DevTestLabs = devtestlabs.NewClient(o)
client.Dns = dns.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 @@ -18,6 +18,7 @@ import (
"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"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datamigration"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/devspace"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/devtestlabs"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns"
Expand Down Expand Up @@ -82,6 +83,7 @@ func SupportedServices() []common.ServiceRegistration {
databricks.Registration{},
datafactory.Registration{},
datalake.Registration{},
datamigration.Registration{},
devspace.Registration{},
devtestlabs.Registration{},
dns.Registration{},
Expand Down
18 changes: 18 additions & 0 deletions azurerm/internal/services/datamigration/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,88 @@
package datamigration

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 dataSourceArmDataMigrationService() *schema.Resource {
katbyte marked this conversation as resolved.
Show resolved Hide resolved
return &schema.Resource{
Read: dataSourceArmDataMigrationServiceRead,

katbyte marked this conversation as resolved.
Show resolved Hide resolved
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
katbyte marked this conversation as resolved.
Show resolved Hide resolved

"location": azure.SchemaLocationForDataSource(),

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

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

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

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

func dataSourceArmDataMigrationServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataMigration.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)

d.Set("id", 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 && resp.Sku.Name != nil {
magodo marked this conversation as resolved.
Show resolved Hide resolved
d.Set("sku_name", resp.Sku.Name)
}
d.Set("kind", resp.Kind)

return tags.FlattenAndSet(d, resp.Tags)
}
28 changes: 28 additions & 0 deletions azurerm/internal/services/datamigration/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package datamigration

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "Data Migration"
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_data_migration_service": dataSourceArmDataMigrationService(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
resources := map[string]*schema.Resource{
"azurerm_data_migration_service": resourceArmDataMigrationService(),
}

return resources
}
Loading