Skip to content

Commit

Permalink
New resources: azurerm_lighthouse_definition and 'azurerm_lighthous…
Browse files Browse the repository at this point in the history
…e_assignment' (#6560)

Co-authored-by: Hussain <[email protected]>
Co-authored-by: kt <[email protected]>
Co-authored-by: jackofallops <[email protected]>
  • Loading branch information
4 people authored Sep 16, 2020
1 parent 01307b6 commit 3c5e729
Show file tree
Hide file tree
Showing 29 changed files with 3,073 additions and 3 deletions.
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var services = mapOf(
"machinelearning" to "Machine Learning",
"maintenance" to "Maintenance",
"managedapplications" to "Managed Applications",
"lighthouse" to "Lighthouse",
"managementgroup" to "Management Group",
"maps" to "Maps",
"mariadb" to "MariaDB",
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 @@ -44,6 +44,7 @@ import (
timeseriesinsights "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iottimeseriesinsights/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"
lighthouse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/lighthouse/client"
loganalytics "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/client"
logic "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic/client"
machinelearning "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning/client"
Expand Down Expand Up @@ -130,6 +131,7 @@ type Client struct {
IoTTimeSeriesInsights *timeseriesinsights.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
Lighthouse *lighthouse.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
MachineLearning *machinelearning.Client
Expand Down Expand Up @@ -217,6 +219,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.IoTTimeSeriesInsights = timeseriesinsights.NewClient(o)
client.KeyVault = keyvault.NewClient(o)
client.Kusto = kusto.NewClient(o)
client.Lighthouse = lighthouse.NewClient(o)
client.LogAnalytics = loganalytics.NewClient(o)
client.Logic = logic.NewClient(o)
client.MachineLearning = machinelearning.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 @@ -40,6 +40,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iottimeseriesinsights"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/lighthouse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning"
Expand Down Expand Up @@ -127,6 +128,7 @@ func SupportedServices() []common.ServiceRegistration {
machinelearning.Registration{},
maintenance.Registration{},
managedapplications.Registration{},
lighthouse.Registration{},
managementgroup.Registration{},
maps.Registration{},
mariadb.Registration{},
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/resourceproviders/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func Required() map[string]struct{} {
"Microsoft.MachineLearningServices": {},
"Microsoft.Maintenance": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.ManagedServices": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
Expand Down
24 changes: 24 additions & 0 deletions azurerm/internal/services/lighthouse/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/managedservices/mgmt/2019-06-01/managedservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
DefinitionsClient *managedservices.RegistrationDefinitionsClient
AssignmentsClient *managedservices.RegistrationAssignmentsClient
}

func NewClient(o *common.ClientOptions) *Client {
DefinitionsClient := managedservices.NewRegistrationDefinitionsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&DefinitionsClient.Client, o.ResourceManagerAuthorizer)

AssignmentsClient := managedservices.NewRegistrationAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&AssignmentsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
DefinitionsClient: &DefinitionsClient,
AssignmentsClient: &AssignmentsClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package parse

import (
"fmt"
"strings"
)

type LighthouseAssignmentId struct {
Scope string
Name string
}

func LighthouseAssignmentID(id string) (*LighthouseAssignmentId, error) {
segments := strings.Split(id, "/providers/Microsoft.ManagedServices/registrationAssignments/")
if len(segments) != 2 {
return nil, fmt.Errorf("Expected ID to be in the format `{scope}/providers/Microsoft.ManagedServices/registrationAssignments/{name} - got %d segments", len(segments))
}

lighthouseAssignmentId := LighthouseAssignmentId{
Scope: segments[0],
Name: segments[1],
}

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

import (
"testing"
)

func TestLighthouseAssignmentID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *LighthouseAssignmentId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing Scope",
Input: "providers/Microsoft.ManagedServices/registrationAssignments/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "Missing Name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ManagedServices/registrationAssignments",
Expected: nil,
},
{
Name: "Lighthouse assignment ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ManagedServices/registrationAssignments/00000000-0000-0000-0000-000000000000",
Expected: &LighthouseAssignmentId{
Name: "00000000-0000-0000-0000-000000000000",
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000",
},
},
}

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

actual, err := LighthouseAssignmentID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}

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

if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package parse

import (
"fmt"
"strings"
)

type LighthouseDefinitionId struct {
Scope string
LighthouseDefinitionID string
}

func LighthouseDefinitionID(id string) (*LighthouseDefinitionId, error) {
segments := strings.Split(id, "/providers/Microsoft.ManagedServices/registrationDefinitions/")

if len(segments) != 2 {
return nil, fmt.Errorf("Expected ID to be in the format `{scope}/providers/Microsoft.ManagedServices/registrationDefinitions/{name} - got %d segments", len(segments))
}

lighthouseDefinitionId := LighthouseDefinitionId{
Scope: segments[0],
LighthouseDefinitionID: segments[1],
}

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

import (
"testing"
)

func TestLighthouseDefinitionID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *LighthouseDefinitionId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "Missing Scope",
Input: "providers/Microsoft.ManagedServices/registrationDefinitions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "Missing LighthouseDefinitionID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ManagedServices/registrationDefinitions",
Expected: nil,
},
{
Name: "Lighthouse Definition ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.ManagedServices/registrationDefinitions/00000000-0000-0000-0000-000000000000",
Expected: &LighthouseDefinitionId{
LighthouseDefinitionID: "00000000-0000-0000-0000-000000000000",
Scope: "/subscriptions/00000000-0000-0000-0000-000000000000",
},
},
}

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

actual, err := LighthouseDefinitionID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}

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

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

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 "Lighthouse"
}

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

// 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_lighthouse_definition": resourceArmLighthouseDefinition(),
"azurerm_lighthouse_assignment": resourceArmLighthouseAssignment(),
}
}
Loading

0 comments on commit 3c5e729

Please sign in to comment.