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_storage_account: Support managed HSMs for CMKs #25088

Merged
merged 7 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
merge main
katbyte committed May 2, 2024

Unverified

The email in this signature doesn’t match the committer email.
commit dceb300f21dcc673f98c4a4f0c7c00c0b4a9a771
33 changes: 25 additions & 8 deletions internal/services/managedhsm/parse/data_plane_helpers.go
Original file line number Diff line number Diff line change
@@ -11,18 +11,35 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
)

type dataPlaneEndpoint struct {
managedHsmName string
domainSuffix string
type ManagedHSMDataPlaneEndpoint struct {
ManagedHSMName string
DomainSuffix string
}

func parseDataPlaneEndpoint(input *url.URL, domainSuffix *string) (*dataPlaneEndpoint, error) {
func (e ManagedHSMDataPlaneEndpoint) BaseURI() string {
return fmt.Sprintf("https://%s.%s/", e.ManagedHSMName, e.DomainSuffix)
}

func ManagedHSMEndpoint(input string, domainSuffix *string) (*ManagedHSMDataPlaneEndpoint, error) {
// NOTE: this function can be removed in 4.0
uri, err := url.Parse(input)
if err != nil {
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

return parseDataPlaneEndpoint(uri, domainSuffix)
}

func parseDataPlaneEndpoint(input *url.URL, domainSuffix *string) (*ManagedHSMDataPlaneEndpoint, error) {
if input.Scheme != "https" {
return nil, fmt.Errorf("expected the scheme to be `https` but got %q", input.Scheme)
}

hostname := strings.ToLower(input.Host)
if input.Port() != "" {
if port := input.Port(); port != "" {
if port != "443" {
return nil, fmt.Errorf("expected port to be '443' but got %q", port)
}
hostname = strings.TrimSuffix(hostname, fmt.Sprintf(":%s", input.Port()))
}
hostnameComponents := strings.Split(hostname, ".")
@@ -41,9 +58,9 @@ func parseDataPlaneEndpoint(input *url.URL, domainSuffix *string) (*dataPlaneEnd
return nil, fmt.Errorf("expected the hostname to end be in the format `{name}.%s` but got %q", *domainSuffix, hostname)
}

return &dataPlaneEndpoint{
managedHsmName: managedHSMName,
domainSuffix: parsedDomainSuffix,
return &ManagedHSMDataPlaneEndpoint{
ManagedHSMName: managedHSMName,
DomainSuffix: parsedDomainSuffix,
}, nil
}

Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ func ManagedHSMDataPlaneVersionedKeyID(input string, domainSuffix *string) (*Man
}

return &ManagedHSMDataPlaneVersionedKeyId{
ManagedHSMName: endpoint.managedHsmName,
DomainSuffix: endpoint.domainSuffix,
ManagedHSMName: endpoint.ManagedHSMName,
DomainSuffix: endpoint.DomainSuffix,
KeyName: resource.itemName,
KeyVersion: *resource.itemVersion,
}, nil
Original file line number Diff line number Diff line change
@@ -113,10 +113,9 @@ func TestParseManagedHSMDataPlaneVersionedKeyID_WithDomainSuffix_InvalidValuesFa
for _, input := range values {
t.Logf("Validating %q", input)
actual, err := ManagedHSMDataPlaneVersionedKeyID(input, pointer.To("managedhsm.azure.net"))
if err != nil {
continue
if err == nil {
t.Fatalf("unexpected value for %q: %q", input, actual.ID())
}
t.Fatalf("unexpected value for %q: %q", input, actual.ID())
}
}

Original file line number Diff line number Diff line change
@@ -65,8 +65,8 @@ func ManagedHSMDataPlaneVersionlessKeyID(input string, domainSuffix *string) (*M
}

return &ManagedHSMDataPlaneVersionlessKeyId{
ManagedHSMName: endpoint.managedHsmName,
DomainSuffix: endpoint.domainSuffix,
ManagedHSMName: endpoint.ManagedHSMName,
DomainSuffix: endpoint.DomainSuffix,
KeyName: resource.itemName,
}, nil
}
Original file line number Diff line number Diff line change
@@ -101,10 +101,9 @@ func TestParseManagedHSMDataPlaneVersionlessKeyID_WithDomainSuffix_InvalidValues
for _, input := range values {
t.Logf("Validating %q", input)
actual, err := ManagedHSMDataPlaneVersionlessKeyID(input, pointer.To("managedhsm.azure.net"))
if err != nil {
continue
if err == nil {
t.Fatalf("unexpected value for %q: %q", input, actual.ID())
}
t.Fatalf("unexpected value for %q: %q", input, actual.ID())
}
}

You are viewing a condensed version of this merge commit. You can view the full changes here.