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 resource: azurerm_dedicated_hardware_security_module #7727

Merged
merged 5 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var services = mapOf(
"eventgrid" to "EventGrid",
"eventhub" to "EventHub",
"frontdoor" to "FrontDoor",
"hsm" to "Hardware Security Module",
"hdinsight" to "HDInsight",
"healthcare" to "Health Care",
"iothub" to "IoT Hub",
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 @@ -37,6 +37,7 @@ import (
frontdoor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor/client"
hdinsight "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight/client"
healthcare "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare/client"
hsm "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hsm/client"
iotcentral "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral/client"
iothub "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub/client"
timeseriesinsights "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iottimeseriesinsights/client"
Expand Down Expand Up @@ -118,6 +119,7 @@ type Client struct {
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Frontdoor *frontdoor.Client
HSM *hsm.Client
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTCentral *iotcentral.Client
Expand Down Expand Up @@ -202,6 +204,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.EventGrid = eventgrid.NewClient(o)
client.Eventhub = eventhub.NewClient(o)
client.Frontdoor = frontdoor.NewClient(o)
client.HSM = hsm.NewClient(o)
client.HDInsight = hdinsight.NewClient(o)
client.HealthCare = healthcare.NewClient(o)
client.IoTCentral = iotcentral.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 @@ -33,6 +33,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hsm"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iottimeseriesinsights"
Expand Down Expand Up @@ -111,6 +112,7 @@ func SupportedServices() []common.ServiceRegistration {
eventgrid.Registration{},
eventhub.Registration{},
frontdoor.Registration{},
hsm.Registration{},
hdinsight.Registration{},
healthcare.Registration{},
iothub.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/hsm/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/hardwaresecuritymodules/mgmt/2018-10-31-preview/hardwaresecuritymodules"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
DedicatedHsmClient *hardwaresecuritymodules.DedicatedHsmClient
}

func NewClient(o *common.ClientOptions) *Client {
dedicatedHsmClient := hardwaresecuritymodules.NewDedicatedHsmClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&dedicatedHsmClient.Client, o.ResourceManagerAuthorizer)

return &Client{
DedicatedHsmClient: &dedicatedHsmClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type DedicatedHardwareSecurityModuleId struct {
ResourceGroup string
Name string
}

func DedicatedHardwareSecurityModuleID(input string) (*DedicatedHardwareSecurityModuleId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("parsing DedicatedHardwareSecurityModule ID %q: %+v", input, err)
}

dedicatedHardwareSecurityModule := DedicatedHardwareSecurityModuleId{
ResourceGroup: id.ResourceGroup,
}

if dedicatedHardwareSecurityModule.Name, err = id.PopSegment("dedicatedHSMs"); err != nil {
return nil, err
}

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

return &dedicatedHardwareSecurityModule, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package parse

import (
"testing"
)

func TestDedicatedHardwareSecurityModuleID(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *DedicatedHardwareSecurityModuleId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing DedicatedHardwareSecurityModule Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.HardwareSecurityModules/dedicatedHSMs",
Expected: nil,
},
{
Name: "DedicatedHardwareSecurityModule ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.HardwareSecurityModules/dedicatedHSMs/hsm1",
Expected: &DedicatedHardwareSecurityModuleId{
ResourceGroup: "group1",
Name: "hsm1",
},
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.HardwareSecurityModules/DedicatedHSMs/hsm1",
Expected: nil,
},
}

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

actual, err := DedicatedHardwareSecurityModuleID(v.Input)
if err != nil {
if v.Expected == nil {
continue
}
t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}

if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
29 changes: 29 additions & 0 deletions azurerm/internal/services/hsm/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hsm

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 "Hardware Security Module"
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
func (r Registration) WebsiteCategories() []string {
return []string{
"Hardware Security Module",
}
}

// 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_dedicated_hardware_security_module": resourceArmDedicatedHardwareSecurityModule(),
}
}
Loading