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_databox_edge_order and azurerm_databox_edge_device #10392

Closed
wants to merge 14 commits into from
Closed
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var services = mapOf(
"datashare" to "Data Share",
"databricks" to "DataBricks",
"databasemigration" to "Database Migration",
"databoxedge" to "Databox Edge",
"desktopvirtualization" to "Desktop Virtualization",
"devtestlabs" to "Dev Test",
"digitaltwins" to "Digital Twins",
Expand Down
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
costmanagement "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement/client"
customproviders "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders/client"
datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/client"
databoxedge "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databoxedge/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 @@ -123,6 +124,7 @@ type Client struct {
CustomProviders *customproviders.Client
DatabaseMigration *datamigration.Client
DataBricks *databricks.Client
DataboxEdge *databoxedge.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DataShare *datashare.Client
Expand Down Expand Up @@ -220,6 +222,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.CustomProviders = customproviders.NewClient(o)
client.DatabaseMigration = datamigration.NewClient(o)
client.DataBricks = databricks.NewClient(o)
client.DataboxEdge = databoxedge.NewClient(o)
client.DataFactory = datafactory.NewClient(o)
client.Datalake = datalake.NewClient(o)
client.DataShare = datashare.NewClient(o)
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 @@ -22,6 +22,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databoxedge"
"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 @@ -120,6 +121,7 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
cosmos.Registration{},
costmanagement.Registration{},
customproviders.Registration{},
databoxedge.Registration{},
databricks.Registration{},
datafactory.Registration{},
datalake.Registration{},
Expand Down
24 changes: 24 additions & 0 deletions azurerm/internal/services/databoxedge/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/databoxedge/mgmt/2019-08-01/databoxedge"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
DeviceClient *databoxedge.DevicesClient
OrderClient *databoxedge.OrdersClient
}

func NewClient(o *common.ClientOptions) *Client {
deviceClient := databoxedge.NewDevicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&deviceClient.Client, o.ResourceManagerAuthorizer)

orderClient := databoxedge.NewOrdersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&orderClient.Client, o.ResourceManagerAuthorizer)

return &Client{
DeviceClient: &deviceClient,
OrderClient: &orderClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package databoxedge

import (
"fmt"
"time"

"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/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location"
"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 dataSourceDataboxEdgeDevice() *schema.Resource {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think there is much a reason to include a datasource here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

return &schema.Resource{
Read: dataSourceDataboxEdgeDeviceRead,

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

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

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

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

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

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

resp, err := client.Get(ctx, name, resourceGroup)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Databox Edge Device %q does not exist", name)
}
return fmt.Errorf("retrieving Databox Edge Device %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("empty or nil ID returned for Databox Edge Device %q (Resource Group %q) ID", name, resourceGroup)
}

d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))

return tags.FlattenAndSet(d, resp.Tags)
}
Loading