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_dev_test_global_shutdown_schedule #5536

Merged
25 changes: 15 additions & 10 deletions azurerm/internal/services/devtestlabs/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
)

type Client struct {
LabsClient *dtl.LabsClient
LabSchedulesClient *dtl.SchedulesClient
PoliciesClient *dtl.PoliciesClient
VirtualMachinesClient *dtl.VirtualMachinesClient
VirtualNetworksClient *dtl.VirtualNetworksClient
GlobalLabSchedulesClient *dtl.GlobalSchedulesClient
LabsClient *dtl.LabsClient
LabSchedulesClient *dtl.SchedulesClient
PoliciesClient *dtl.PoliciesClient
VirtualMachinesClient *dtl.VirtualMachinesClient
VirtualNetworksClient *dtl.VirtualNetworksClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -29,11 +30,15 @@ func NewClient(o *common.ClientOptions) *Client {
LabSchedulesClient := dtl.NewSchedulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&LabSchedulesClient.Client, o.ResourceManagerAuthorizer)

GlobalLabSchedulesClient := dtl.NewGlobalSchedulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&GlobalLabSchedulesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
LabsClient: &LabsClient,
LabSchedulesClient: &LabSchedulesClient,
PoliciesClient: &PoliciesClient,
VirtualMachinesClient: &VirtualMachinesClient,
VirtualNetworksClient: &VirtualNetworksClient,
GlobalLabSchedulesClient: &GlobalLabSchedulesClient,
LabsClient: &LabsClient,
LabSchedulesClient: &LabSchedulesClient,
PoliciesClient: &PoliciesClient,
VirtualMachinesClient: &VirtualMachinesClient,
VirtualNetworksClient: &VirtualNetworksClient,
}
}
33 changes: 33 additions & 0 deletions azurerm/internal/services/devtestlabs/parse/global_schedule.go
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 GlobalScheduleId struct {
ResourceGroup string
Name string
}

func GlobalScheduleID(input string) (*GlobalScheduleId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse Global Schedule ID %q: %+v", input, err)
}

service := GlobalScheduleId{
ResourceGroup: id.ResourceGroup,
}

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

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

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

import "testing"

func TestGlobalSchedule(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *GlobalScheduleId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No DevTest Lab segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/",
Expected: nil,
},
{
Name: "No schedule name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/Microsoft.DevTestLab/schedules/",
Expected: nil,
},
{
Name: "Case incorrect in path element",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/Microsoft.DevTestLab/Schedules/schedule1",
Expected: nil,
},
{
Name: "Valid",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/Microsoft.DevTestLab/schedules/schedule1",
Expected: &GlobalScheduleId{
ResourceGroup: "myGroup1",
Name: "schedule1",
},
},
}

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

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

t.Fatalf("Expected a value but got an error: %s", err)
}

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

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
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 GlobalScheduleVirtualMachineId struct {
ResourceGroup string
Name string
}

func GlobalScheduleVirtualMachineID(input string) (*GlobalScheduleVirtualMachineId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse Virtual Machine ID %q: %+v", input, err)
}

service := GlobalScheduleVirtualMachineId{
ResourceGroup: id.ResourceGroup,
}

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

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

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

import "testing"

func TestGlobalScheduleVirtualMachine(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *GlobalScheduleVirtualMachineId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No virtual machine segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/",
Expected: nil,
},
{
Name: "No virtual machine name",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/microsoft.compute/virtualMachines/",
Expected: nil,
},
{
Name: "Case incorrect in path element",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/microsoft.compute/VirtualMachines/machine1",
Expected: nil,
},
{
Name: "Valid",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/microsoft.compute/virtualMachines/machine1",
Expected: &GlobalScheduleVirtualMachineId{
ResourceGroup: "myGroup1",
Name: "machine1",
},
},
}

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

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

t.Fatalf("Expected a value but got an error: %s", err)
}

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

if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
13 changes: 7 additions & 6 deletions azurerm/internal/services/devtestlabs/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func (r Registration) SupportedDataSources() 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_dev_test_lab": resourceArmDevTestLab(),
"azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(),
"azurerm_dev_test_linux_virtual_machine": resourceArmDevTestLinuxVirtualMachine(),
"azurerm_dev_test_policy": resourceArmDevTestPolicy(),
"azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(),
"azurerm_dev_test_windows_virtual_machine": resourceArmDevTestWindowsVirtualMachine()}
"azurerm_dev_test_global_shutdown_schedule": resourceArmDevTestLabGlobalShutdownSchedule(),
"azurerm_dev_test_lab": resourceArmDevTestLab(),
"azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(),
"azurerm_dev_test_linux_virtual_machine": resourceArmDevTestLinuxVirtualMachine(),
"azurerm_dev_test_policy": resourceArmDevTestPolicy(),
"azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(),
"azurerm_dev_test_windows_virtual_machine": resourceArmDevTestWindowsVirtualMachine()}
}
Loading