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 resources: azurerm_lighthouse_definition and 'azurerm_lighthouse_assignment' #6560

Merged
merged 36 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d462cb1
Added resource azurerm_registration_definition
Apr 14, 2020
74f3b75
Cleaned up api surface
Apr 14, 2020
b647f2f
Cleaned up api surface
Apr 14, 2020
b1b82eb
Added data source for registration definition
Apr 14, 2020
7c53adb
Tested code for definition
Apr 15, 2020
5000f02
Both definition and assignment works
Apr 15, 2020
14d5c8a
Data source works
Apr 16, 2020
c8488dd
code clean up and formatting
Apr 16, 2020
f6066ef
Added ForceNew to the Id of both assignment and regisration
Apr 16, 2020
dcb5389
Set ForceNew to correct attributes and put sleep after assignment delete
Apr 17, 2020
57e37aa
Added code to accept role_name in definition
Apr 17, 2020
19202cc
Removed extraction of RoleId based on RoleName
Apr 18, 2020
743da7e
Added tests
Apr 18, 2020
aff25a9
Added tests
Apr 19, 2020
d99e40f
Added sample docs
Apr 19, 2020
033bc75
Updated docs to fix typos
Apr 20, 2020
ab758fd
Updated tests to include second tenant name
Apr 20, 2020
7eef2ee
Fixed all tests and updated docs
Apr 21, 2020
05dece3
Added comments for multiple tenants
Apr 21, 2020
ecd2094
Formatted files, updated env variable and updated docs format
Apr 21, 2020
7795290
ran terrafmt fmt
Apr 21, 2020
727cf67
Removed scope from definition and formatted the code
Apr 22, 2020
a908d73
Changed the resources from registration_* to lighthouse_*
May 9, 2020
7cba3be
resolved build failure
May 20, 2020
906e19b
Fixed the failing test
May 20, 2020
5a1fc40
Address code review comments
Jun 8, 2020
d98ec09
post merge cleanup
katbyte May 26, 2020
d2ff592
Added tests for parse and cleaned up azurerm.erb
Jun 8, 2020
c242505
updated for removal of ShouldResourcesBeImported
jackofallops Sep 16, 2020
4fffbfc
added validation and removed unnecessary API flag from schema
jackofallops Sep 16, 2020
d3a9f2b
schema reordering
jackofallops Sep 16, 2020
fcdcad5
updated docs
jackofallops Sep 16, 2020
7e99601
update docs, remove data source
jackofallops Sep 16, 2020
dd01f1c
set scope to forcenew, added validation for definition id
jackofallops Sep 16, 2020
c457ec2
adressed review feedback
jackofallops Sep 16, 2020
b44dfd7
missed review comment
jackofallops Sep 16, 2020
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
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