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: azurerm_iotcentral_application #5446

Merged
merged 17 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -30,6 +30,7 @@ import (
frontdoor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor/client"
hdinsight "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight/client"
healthcare "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare/client"
iotcentral "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral/client"
iothub "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub/client"
keyvault "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/client"
kusto "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto/client"
Expand Down Expand Up @@ -100,6 +101,7 @@ type Client struct {
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTHub *iothub.Client
IoTCentral *iotcentral.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Expand Down Expand Up @@ -168,6 +170,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.HDInsight = hdinsight.NewClient(o)
client.HealthCare = healthcare.NewClient(o)
client.IoTHub = iothub.NewClient(o)
client.IoTCentral = iotcentral.NewClient(o)
client.KeyVault = keyvault.NewClient(o)
client.Kusto = kusto.NewClient(o)
client.LogAnalytics = loganalytics.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 @@ -27,6 +27,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto"
Expand Down Expand Up @@ -94,6 +95,7 @@ func SupportedServices() []common.ServiceRegistration {
hdinsight.Registration{},
healthcare.Registration{},
iothub.Registration{},
iotcentral.Registration{},
keyvault.Registration{},
kusto.Registration{},
loganalytics.Registration{},
Expand Down
18 changes: 18 additions & 0 deletions azurerm/internal/services/iotcentral/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/iotcentral/mgmt/2018-09-01/iotcentral"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
AppsClient *iotcentral.AppsClient
}

func NewClient(o *common.ClientOptions) *Client {
AppsClient := iotcentral.NewAppsClient(o.SubscriptionId)
o.ConfigureClient(&AppsClient.Client, o.ResourceManagerAuthorizer)
return &Client{
AppsClient: &AppsClient,
}
}
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 IoTCentralApplicationId struct {
ResourceGroup string
Name string
}

func IoTCentralApplicationID(input string) (*IoTCentralApplicationId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse IoT Central Application ID %q: %+v", input, err)
}

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

if server.Name, err = id.PopSegment("IoTApps"); 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,73 @@
package parse

import (
"testing"
)

func TestIotCentralApplicationID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *IoTCentralApplicationId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing IoT Central Application Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IoTApps/",
Expected: nil,
},
{
Name: "IoT Central Application ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IoTApps/App1",
Expected: &IoTCentralApplicationId{
Name: "App1",
ResourceGroup: "resGroup1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IotApps/App1",
Expected: nil,
},
}

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

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

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

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

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
31 changes: 31 additions & 0 deletions azurerm/internal/services/iotcentral/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package iotcentral

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 "IoT Central"
}

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

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_iotcentral_application": resourceArmIotCentralApplication(),
}
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
func (r Registration) WebsiteCategories() []string {
return []string{
"IoT Central",
}
}
Loading