-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resources:
azurerm_lighthouse_definition
and 'azurerm_lighthous…
…e_assignment' (#6560) Co-authored-by: Hussain <[email protected]> Co-authored-by: kt <[email protected]> Co-authored-by: jackofallops <[email protected]>
- Loading branch information
1 parent
01307b6
commit 3c5e729
Showing
29 changed files
with
3,073 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
azurerm/internal/services/lighthouse/parse/lighthouse_assignment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
57 changes: 57 additions & 0 deletions
57
azurerm/internal/services/lighthouse/parse/lighthouse_assignment_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
azurerm/internal/services/lighthouse/parse/lighthouse_definition.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
58 changes: 58 additions & 0 deletions
58
azurerm/internal/services/lighthouse/parse/lighthouse_definition_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} |
Oops, something went wrong.