-
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.
azurerm_stack_hci_cluster
- add a new property `automanange_configu…
…ration_id` (#22857) * new resource `azurerm_automanage_configuration_hci_assignment` * update testcase * add document * add new property to azurerm_stack_hci_cluster * remove assignment resource * remove unnecessary imports * update code quality based on review comments * update code quality based on review comments * Update internal/services/azurestackhci/stack_hci_cluster_resource.go Co-authored-by: stephybun <steph@hashicorp.com> * update code quality based on review comments --------- Co-authored-by: stephybun <steph@hashicorp.com>
- Loading branch information
1 parent
9f11f6c
commit fd0d618
Showing
9 changed files
with
551 additions
and
2 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
78 changes: 78 additions & 0 deletions
78
internal/services/automanage/parse/automanage_configuration_hci_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,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 | ||
} |
131 changes: 131 additions & 0 deletions
131
internal/services/automanage/parse/automanage_configuration_hci_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,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) | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
internal/services/automanage/validate/automanage_configuration_hci_assignment_id.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 @@ | ||
// 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 | ||
} |
91 changes: 91 additions & 0 deletions
91
internal/services/automanage/validate/automanage_configuration_hci_assignment_id_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,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) | ||
} | ||
} | ||
} |
Oops, something went wrong.