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

azurerm_stack_hci_cluster - add a new property automanange_configuration_id #22857

Merged
merged 11 commits into from
Aug 14, 2023
19 changes: 17 additions & 2 deletions internal/services/automanage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ import (
)

type Client struct {
ConfigurationClient *automanage.ConfigurationProfilesClient
ConfigurationClient *automanage.ConfigurationProfilesClient
HCIAssignmentClient *automanage.ConfigurationProfileHCIAssignmentsClient
HCRPAssignmentClient *automanage.ConfigurationProfileHCRPAssignmentsClient
VMAssignmentClient *automanage.ConfigurationProfileAssignmentsClient
}

func NewClient(o *common.ClientOptions) *Client {
configurationProfileClient := automanage.NewConfigurationProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&configurationProfileClient.Client, o.ResourceManagerAuthorizer)

hciAssignmentClient := automanage.NewConfigurationProfileHCIAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&hciAssignmentClient.Client, o.ResourceManagerAuthorizer)

hcrpAssignmentClient := automanage.NewConfigurationProfileHCRPAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&hcrpAssignmentClient.Client, o.ResourceManagerAuthorizer)

vmAssignmentClient := automanage.NewConfigurationProfileAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmAssignmentClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ConfigurationClient: &configurationProfileClient,
ConfigurationClient: &configurationProfileClient,
HCIAssignmentClient: &hciAssignmentClient,
HCRPAssignmentClient: &hcrpAssignmentClient,
VMAssignmentClient: &vmAssignmentClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type AutomanageConfigurationHCIAssignmentId struct {
SubscriptionId string
ResourceGroup string
ClusterName string
ConfigurationProfileAssignmentName string
}

func NewAutomanageConfigurationHCIAssignmentID(subscriptionId, resourceGroup, clusterName, configurationProfileAssignmentName string) AutomanageConfigurationHCIAssignmentId {
return AutomanageConfigurationHCIAssignmentId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
ClusterName: clusterName,
ConfigurationProfileAssignmentName: configurationProfileAssignmentName,
}
}

func (id AutomanageConfigurationHCIAssignmentId) String() string {
segments := []string{
fmt.Sprintf("Configuration Profile Assignment Name %q", id.ConfigurationProfileAssignmentName),
fmt.Sprintf("Cluster Name %q", id.ClusterName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Automanage Configuration H C I Assignment", segmentsStr)
}

func (id AutomanageConfigurationHCIAssignmentId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AzureStackHci/clusters/%s/providers/Microsoft.Automanage/configurationProfileAssignments/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ClusterName, id.ConfigurationProfileAssignmentName)
}

// AutomanageConfigurationHCIAssignmentID parses a AutomanageConfigurationHCIAssignment ID into an AutomanageConfigurationHCIAssignmentId struct
func AutomanageConfigurationHCIAssignmentID(input string) (*AutomanageConfigurationHCIAssignmentId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("parsing %q as an AutomanageConfigurationHCIAssignment ID: %+v", input, err)
}

resourceId := AutomanageConfigurationHCIAssignmentId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.ClusterName, err = id.PopSegment("clusters"); err != nil {
return nil, err
}
if resourceId.ConfigurationProfileAssignmentName, err = id.PopSegment("configurationProfileAssignments"); err != nil {
return nil, err
}

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

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = AutomanageConfigurationHCIAssignmentId{}

func TestAutomanageConfigurationHCIAssignmentIDFormatter(t *testing.T) {
actual := NewAutomanageConfigurationHCIAssignmentID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "clusterName1", "configurationProfile1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/configurationProfile1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestAutomanageConfigurationHCIAssignmentID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *AutomanageConfigurationHCIAssignmentId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing ClusterName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/",
Error: true,
},

{
// missing value for ClusterName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/",
Error: true,
},

{
// missing ConfigurationProfileAssignmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/",
Error: true,
},

{
// missing value for ConfigurationProfileAssignmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/configurationProfile1",
Expected: &AutomanageConfigurationHCIAssignmentId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resourceGroup1",
ClusterName: "clusterName1",
ConfigurationProfileAssignmentName: "configurationProfile1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESOURCEGROUP1/PROVIDERS/MICROSOFT.AZURESTACKHCI/CLUSTERS/CLUSTERNAME1/PROVIDERS/MICROSOFT.AUTOMANAGE/CONFIGURATIONPROFILEASSIGNMENTS/CONFIGURATIONPROFILE1",
Error: true,
},
}

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

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

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.ClusterName != v.Expected.ClusterName {
t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName)
}
if actual.ConfigurationProfileAssignmentName != v.Expected.ConfigurationProfileAssignmentName {
t.Fatalf("Expected %q but got %q for ConfigurationProfileAssignmentName", v.Expected.ConfigurationProfileAssignmentName, actual.ConfigurationProfileAssignmentName)
}
}
}
2 changes: 2 additions & 0 deletions internal/services/automanage/resourceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ package automanage

// leaving the Automanage prefix here to avoid stuttering the property name for now
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutomanageConfiguration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutomanageConfigurationHCIAssignment -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/configurationProfile1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse"
)

func AutomanageConfigurationHCIAssignmentID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if _, err := parse.AutomanageConfigurationHCIAssignmentID(v); err != nil {
errors = append(errors, err)
}

return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import "testing"

func TestAutomanageConfigurationHCIAssignmentID(t *testing.T) {
cases := []struct {
Input string
Valid bool
}{

{
// empty
Input: "",
Valid: false,
},

{
// missing SubscriptionId
Input: "/",
Valid: false,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Valid: false,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Valid: false,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Valid: false,
},

{
// missing ClusterName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/",
Valid: false,
},

{
// missing value for ClusterName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/",
Valid: false,
},

{
// missing ConfigurationProfileAssignmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/",
Valid: false,
},

{
// missing value for ConfigurationProfileAssignmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/",
Valid: false,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AzureStackHci/clusters/clusterName1/providers/Microsoft.Automanage/configurationProfileAssignments/configurationProfile1",
Valid: true,
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESOURCEGROUP1/PROVIDERS/MICROSOFT.AZURESTACKHCI/CLUSTERS/CLUSTERNAME1/PROVIDERS/MICROSOFT.AUTOMANAGE/CONFIGURATIONPROFILEASSIGNMENTS/CONFIGURATIONPROFILE1",
Valid: false,
},
}
for _, tc := range cases {
t.Logf("[DEBUG] Testing Value %s", tc.Input)
_, errors := AutomanageConfigurationHCIAssignmentID(tc.Input, "test")
valid := len(errors) == 0

if tc.Valid != valid {
t.Fatalf("Expected %t but got %t", tc.Valid, valid)
}
}
}
Loading