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_iot_time_series_insights_standard_environment #7012

Merged
merged 10 commits into from May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Expand Up @@ -75,6 +75,7 @@ import (
storage "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/client"
streamAnalytics "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/streamanalytics/client"
subscription "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription/client"
timeseriesinsights "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/timeseriesinsights/client"
trafficManager "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/trafficmanager/client"
web "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/client"
)
Expand Down Expand Up @@ -155,6 +156,7 @@ type Client struct {
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
TimeSeriesInsights *timeseriesinsights.Client
TrafficManager *trafficManager.Client
Web *web.Client
}
Expand Down Expand Up @@ -236,6 +238,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Storage = storage.NewClient(o)
client.StreamAnalytics = streamAnalytics.NewClient(o)
client.Subscription = subscription.NewClient(o)
client.TimeSeriesInsights = timeseriesinsights.NewClient(o)
client.TrafficManager = trafficManager.NewClient(o)
client.Web = web.NewClient(o)

Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/provider/required_resource_providers.go
Expand Up @@ -74,6 +74,7 @@ func RequiredResourceProviders() map[string]struct{} {
"Microsoft.Storage": {},
"Microsoft.StorageCache": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.TimeSeriesInsights": {},
"Microsoft.Web": {},
}
}
Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/provider/services.go
Expand Up @@ -71,6 +71,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/streamanalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/subscription"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/timeseriesinsights"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/trafficmanager"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web"
)
Expand Down Expand Up @@ -148,6 +149,7 @@ func SupportedServices() []common.ServiceRegistration {
storage.Registration{},
streamanalytics.Registration{},
subscription.Registration{},
timeseriesinsights.Registration{},
trafficmanager.Registration{},
web.Registration{},
}
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/timeseriesinsights/client/client.go
@@ -0,0 +1,19 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/timeseriesinsights/mgmt/2018-08-15-preview/timeseriesinsights"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
EnvironmentsClient *timeseriesinsights.EnvironmentsClient
}

func NewClient(o *common.ClientOptions) *Client {
EnvironmentsClient := timeseriesinsights.NewEnvironmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&EnvironmentsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
EnvironmentsClient: &EnvironmentsClient,
}
}
@@ -0,0 +1,33 @@
package parse

import (
"fmt"

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

type TimeSeriesInsightsEnvironmentId struct {
ResourceGroup string
Name string
}

func TimeSeriesInsightsEnvironmentID(input string) (*TimeSeriesInsightsEnvironmentId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("parsing Time Series Insights Environment ID %q: %+v", input, err)
}

service := TimeSeriesInsightsEnvironmentId{
ResourceGroup: id.ResourceGroup,
}

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

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

return &service, nil
}
@@ -0,0 +1,73 @@
package parse

import (
"testing"
)

func TestTimeSeriesInsightsEnvironmentId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *TimeSeriesInsightsEnvironmentId
}{
{
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: "Time Series Insight Environment Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.TimeSeriesInsights/environments/",
Expected: nil,
},
{
Name: "Time Series Insight Environment ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.TimeSeriesInsights/environments/Environment1",
Expected: &TimeSeriesInsightsEnvironmentId{
Name: "Environment1",
ResourceGroup: "resGroup1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.TimeSeriesInsights/Environments/Environment1",
Expected: nil,
},
}

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

actual, err := TimeSeriesInsightsEnvironmentID(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/timeseriesinsights/registration.go
@@ -0,0 +1,31 @@
package timeseriesinsights

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 "Time Series Insights"
}

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

// 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_time_series_insights_standard_environment": resourceArmTimeSeriesInsightsStandardEnvironment(),
}
}