From a216b584bfc5befe8342544976deae1bcd10e916 Mon Sep 17 00:00:00 2001 From: Sean Nixon Date: Mon, 27 Jan 2020 11:16:07 -0600 Subject: [PATCH 01/12] New resource: azurerm_dev_test_global_shutdown_schedule --- .../services/devtestlabs/client/client.go | 25 +- .../services/devtestlabs/registration.go | 13 +- ...e_arm_dev_test_global_shutdown_schedule.go | 324 ++++++++++++++++++ ..._dev_test_global_shutdown_schedule_test.go | 242 +++++++++++++ website/azurerm.erb | 4 + ...est_global_shutdown_schedule.html.markdown | 141 ++++++++ 6 files changed, 733 insertions(+), 16 deletions(-) create mode 100644 azurerm/internal/services/devtestlabs/resource_arm_dev_test_global_shutdown_schedule.go create mode 100644 azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_global_shutdown_schedule_test.go create mode 100644 website/docs/r/dev_test_global_shutdown_schedule.html.markdown diff --git a/azurerm/internal/services/devtestlabs/client/client.go b/azurerm/internal/services/devtestlabs/client/client.go index 869818017b94..bcf61e99d341 100644 --- a/azurerm/internal/services/devtestlabs/client/client.go +++ b/azurerm/internal/services/devtestlabs/client/client.go @@ -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 { @@ -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, } } diff --git a/azurerm/internal/services/devtestlabs/registration.go b/azurerm/internal/services/devtestlabs/registration.go index 607fa7bc4d9f..59aa87d5f7e1 100644 --- a/azurerm/internal/services/devtestlabs/registration.go +++ b/azurerm/internal/services/devtestlabs/registration.go @@ -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()} } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_global_shutdown_schedule.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_global_shutdown_schedule.go new file mode 100644 index 000000000000..aca289c77cbf --- /dev/null +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_global_shutdown_schedule.go @@ -0,0 +1,324 @@ +package devtestlabs + +import ( + "fmt" + "regexp" + "time" + + "github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDevTestLabGlobalShutdownSchedule() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDevTestLabGlobalShutdownScheduleCreateUpdate, + Read: resourceArmDevTestLabGlobalShutdownScheduleRead, + Update: resourceArmDevTestLabGlobalShutdownScheduleCreateUpdate, + Delete: resourceArmDevTestLabGlobalShutdownScheduleDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "location": azure.SchemaLocation(), + + "target_resource_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "status": { + Type: schema.TypeString, + Optional: true, + Default: dtl.EnableStatusEnabled, + ValidateFunc: validation.StringInSlice([]string{ + string(dtl.EnableStatusEnabled), + string(dtl.EnableStatusDisabled), + }, false), + }, + + "daily_recurrence": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "time": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile("^(0[0-9]|1[0-9]|2[0-3]|[0-9])[0-5][0-9]$"), + "Time of day must match the format HHmm where HH is 00-23 and mm is 00-59", + ), + }, + }, + }, + }, + + "time_zone_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.VirtualMachineTimeZoneCaseInsensitive(), + }, + + "notification_settings": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Optional: true, + Default: dtl.NotificationStatusDisabled, + ValidateFunc: validation.StringInSlice([]string{ + string(dtl.NotificationStatusEnabled), + string(dtl.NotificationStatusDisabled), + }, false), + }, + "time_in_minutes": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(15, 120), + }, + "webhook_url": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmDevTestLabGlobalShutdownScheduleCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DevTestLabs.GlobalLabSchedulesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + targetResourceID := d.Get("target_resource_id").(string) + rid, err := azure.ParseAzureResourceID(targetResourceID) + if err != nil { + return err + } + + vmName := rid.Path["virtualMachines"] + resGroup := rid.ResourceGroup + + // Can't find any official documentation on this, but the API returns a 400 for any other name. + // The best example I could find is here: https://social.msdn.microsoft.com/Forums/en-US/25a02403-dba9-4bcb-bdcc-1f4afcba5b65/powershell-script-to-autoshutdown-azure-virtual-machine?forum=WAVirtualMachinesforWindows + name := "shutdown-computevm-" + vmName + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resGroup, name, "") + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Schedule %q (Resource Group %q): %s", name, resGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_dev_test_global_shutdown_schedule", *existing.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + taskType := "ComputeVmShutdownTask" + t := d.Get("tags").(map[string]interface{}) + + schedule := dtl.Schedule{ + Location: &location, + ScheduleProperties: &dtl.ScheduleProperties{ + TargetResourceID: &targetResourceID, + TaskType: &taskType, + }, + Tags: tags.Expand(t), + } + + switch status := d.Get("status"); status { + case string(dtl.EnableStatusEnabled): + schedule.ScheduleProperties.Status = dtl.EnableStatusEnabled + case string(dtl.EnableStatusDisabled): + schedule.ScheduleProperties.Status = dtl.EnableStatusDisabled + default: + } + + if timeZoneId := d.Get("time_zone_id").(string); timeZoneId != "" { + schedule.ScheduleProperties.TimeZoneID = &timeZoneId + } + + if v, ok := d.GetOk("daily_recurrence"); ok { + dailyRecurrence := expandArmDevTestLabGlobalShutdownScheduleRecurrenceDaily(v) + schedule.DailyRecurrence = dailyRecurrence + } + + if _, ok := d.GetOk("notification_settings"); ok { + notificationSettings := expandArmDevTestLabGlobalShutdownScheduleNotificationSettings(d) + schedule.NotificationSettings = notificationSettings + } + + if _, err := client.CreateOrUpdate(ctx, resGroup, name, schedule); err != nil { + return err + } + + read, err := client.Get(ctx, resGroup, name, "") + if err != nil { + return err + } + + if read.ID == nil { + return fmt.Errorf("Cannot read Dev Test Global Schedule %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmDevTestLabGlobalShutdownScheduleRead(d, meta) +} + +func resourceArmDevTestLabGlobalShutdownScheduleRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DevTestLabs.GlobalLabSchedulesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["schedules"] + + resp, err := client.Get(ctx, resGroup, name, "") + + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on Dev Test Global Schedule %s: %s", name, err) + } + + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if props := resp.ScheduleProperties; props != nil { + d.Set("target_resource_id", props.TargetResourceID) + d.Set("time_zone_id", props.TimeZoneID) + + d.Set("status", string(props.Status)) + + if err := d.Set("daily_recurrence", flattenArmDevTestLabGlobalShutdownScheduleRecurrenceDaily(props.DailyRecurrence)); err != nil { + return fmt.Errorf("Error setting `dailyRecurrence`: %#v", err) + } + + if err := d.Set("notification_settings", flattenArmDevTestLabGlobalShutdownScheduleNotificationSettings(props.NotificationSettings)); err != nil { + return fmt.Errorf("Error setting `notificationSettings`: %#v", err) + } + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmDevTestLabGlobalShutdownScheduleDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DevTestLabs.GlobalLabSchedulesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["schedules"] + + if _, err := client.Delete(ctx, resGroup, name); err != nil { + return err + } + + return nil +} + +func expandArmDevTestLabGlobalShutdownScheduleRecurrenceDaily(recurrence interface{}) *dtl.DayDetails { + dailyRecurrenceConfigs := recurrence.([]interface{}) + dailyRecurrenceConfig := dailyRecurrenceConfigs[0].(map[string]interface{}) + dailyTime := dailyRecurrenceConfig["time"].(string) + + return &dtl.DayDetails{ + Time: &dailyTime, + } +} + +func flattenArmDevTestLabGlobalShutdownScheduleRecurrenceDaily(dailyRecurrence *dtl.DayDetails) []interface{} { + if dailyRecurrence == nil { + return []interface{}{} + } + + result := make(map[string]interface{}) + + if dailyRecurrence.Time != nil { + result["time"] = *dailyRecurrence.Time + } + + return []interface{}{result} +} + +func expandArmDevTestLabGlobalShutdownScheduleNotificationSettings(d *schema.ResourceData) *dtl.NotificationSettings { + notificationSettingsConfigs := d.Get("notification_settings").([]interface{}) + notificationSettingsConfig := notificationSettingsConfigs[0].(map[string]interface{}) + webhookUrl := notificationSettingsConfig["webhook_url"].(string) + timeInMinutes := int32(notificationSettingsConfig["time_in_minutes"].(int)) + + notificationStatus := dtl.NotificationStatus(notificationSettingsConfig["status"].(string)) + + return &dtl.NotificationSettings{ + WebhookURL: &webhookUrl, + TimeInMinutes: &timeInMinutes, + Status: notificationStatus, + } +} + +func flattenArmDevTestLabGlobalShutdownScheduleNotificationSettings(notificationSettings *dtl.NotificationSettings) []interface{} { + if notificationSettings == nil { + return []interface{}{} + } + + result := make(map[string]interface{}) + + if notificationSettings.WebhookURL != nil { + result["webhook_url"] = *notificationSettings.WebhookURL + } + + if notificationSettings.TimeInMinutes != nil { + result["time_in_minutes"] = *notificationSettings.TimeInMinutes + } + + if string(notificationSettings.Status) != "" { + result["status"] = string(notificationSettings.Status) + } + + return []interface{}{result} +} diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_global_shutdown_schedule_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_global_shutdown_schedule_test.go new file mode 100644 index 000000000000..1f2c49e466b5 --- /dev/null +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_global_shutdown_schedule_test.go @@ -0,0 +1,242 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" +) + +func TestAccAzureRMDevTestLabGlobalShutdownSchedule_autoShutdownBasic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dev_test_global_shutdown_schedule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDevTestLabGlobalShutdownScheduleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDevTestLabGlobalShutdownSchedule_autoShutdownBasic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDevTestLabGlobalShutdownScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "time_zone_id", "Pacific Standard Time"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.status", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.0.time", "0100"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDevTestLabGlobalShutdownSchedule_autoShutdownBasicUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDevTestLabGlobalShutdownScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "time_zone_id", "Central Standard Time"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.time_in_minutes", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.webhook_url", "https://www.bing.com/2/4"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.0.time", "1100"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + ), + }, + }, + }) +} + +func testCheckAzureRMDevTestLabGlobalShutdownScheduleExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + targetResourceID := rs.Primary.Attributes["target_resource_id"] + exists, err := testCheckAzureRMDevTestLabGlobalShutdownScheduleExistsInternal(targetResourceID) + + if err != nil { + return fmt.Errorf("Error checking if item has been created: %s", err) + } + if !exists { + return fmt.Errorf("Bad: Dev Test Lab Global Schedule %q does not exist", targetResourceID) + } + + return nil + } +} + +func testCheckAzureRMDevTestLabGlobalShutdownScheduleDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_dev_test_global_shutdown_schedule" { + continue + } + + targetResourceID := rs.Primary.Attributes["target_resource_id"] + exists, err := testCheckAzureRMDevTestLabGlobalShutdownScheduleExistsInternal(targetResourceID) + + if err != nil { + return fmt.Errorf("Error checking if item has been destroyed: %s", err) + } + if exists { + return fmt.Errorf("Bad: Dev Test Lab Global Schedule %q still exists", targetResourceID) + } + } + + return nil +} + +func testCheckAzureRMDevTestLabGlobalShutdownScheduleExistsInternal(vmID string) (bool, error) { + client := acceptance.AzureProvider.Meta().(*clients.Client).DevTestLabs.GlobalLabSchedulesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + rid, err := azure.ParseAzureResourceID(vmID) + if err != nil { + return false, fmt.Errorf("Bad: Failed to parse ID (id: %s): %+v", vmID, err) + } + + vmName := rid.Path["virtualMachines"] + name := "shutdown-computevm-" + vmName // Auto-shutdown schedule must use this naming format for Compute VMs + resourceGroup := rid.ResourceGroup + + resp, err := client.Get(ctx, resourceGroup, name, "") + if err != nil { + if resp.Response.IsHTTPStatus(404) { + return false, nil + } + return false, fmt.Errorf("Bad: Get on devTestLabsGlobalSchedules client (id: %s): %+v", vmID, err) + } + + return true, nil +} + +func testAccAzureRMDevTestLabGlobalShutdownSchedule_template(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctnic-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_B2s" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } + storage_os_disk { + name = "myosdisk-%d" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hostname" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMDevTestLabGlobalShutdownSchedule_autoShutdownBasic(data acceptance.TestData) string { + template := testAccAzureRMDevTestLabGlobalShutdownSchedule_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_dev_test_global_shutdown_schedule" "test" { + location = "${azurerm_resource_group.test.location}" + target_resource_id = "${azurerm_virtual_machine.test.id}" + + daily_recurrence { + time = "0100" + } + + time_zone_id = "Pacific Standard Time" + + notification_settings { + status = "Disabled" + } + + tags = { + environment = "Production" + } +} +`, template) +} + +func testAccAzureRMDevTestLabGlobalShutdownSchedule_autoShutdownBasicUpdate(data acceptance.TestData) string { + template := testAccAzureRMDevTestLabGlobalShutdownSchedule_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_dev_test_global_shutdown_schedule" "test" { + location = "${azurerm_resource_group.test.location}" + target_resource_id = "${azurerm_virtual_machine.test.id}" + status = "Disabled" + + daily_recurrence { + time = "1100" + } + + time_zone_id = "Central Standard Time" + + notification_settings { + time_in_minutes = 30 + webhook_url = "https://www.bing.com/2/4" + status = "Enabled" + } + + tags = { + environment = "Production" + } +} + +`, template) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 0721f294857b..38cb32cdd15f 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -1337,6 +1337,10 @@
  • Dev Test Resources