From 63f2150a7d59a16bb4b18b5bc0105bb413dd46f3 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Mon, 18 Feb 2019 16:44:21 +0800 Subject: [PATCH 01/29] Register automation variable client. --- azurerm/config.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azurerm/config.go b/azurerm/config.go index 0664504fad9b..fa9b808d48b4 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -102,6 +102,7 @@ type ArmClient struct { automationRunbookClient automation.RunbookClient automationRunbookDraftClient automation.RunbookDraftClient automationScheduleClient automation.ScheduleClient + automationVariableClient automation.VariableClient dnsClient dns.RecordSetsClient zonesClient dns.ZonesClient @@ -531,6 +532,10 @@ func (c *ArmClient) registerAutomationClients(endpoint, subscriptionId string, a runbookDraftClient := automation.NewRunbookDraftClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&runbookDraftClient.Client, auth) c.automationRunbookDraftClient = runbookDraftClient + + variableClient := automation.NewVariableClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&variableClient.Client, auth) + c.automationVariableClient = variableClient } func (c *ArmClient) registerAuthentication(endpoint, graphEndpoint, subscriptionId, tenantId string, auth, graphAuth autorest.Authorizer) { From bab63c4ed0648785e35eb99c06f6d6c017c30675 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Wed, 24 Apr 2019 18:45:11 -0700 Subject: [PATCH 02/29] Implement common parse value function for AutoVar --- ...resource_arm_automation_variable_common.go | 41 +++++++++ ...rce_arm_automation_variable_common_test.go | 83 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 azurerm/resource_arm_automation_variable_common.go create mode 100644 azurerm/resource_arm_automation_variable_common_test.go diff --git a/azurerm/resource_arm_automation_variable_common.go b/azurerm/resource_arm_automation_variable_common.go new file mode 100644 index 000000000000..2d80dd67bde3 --- /dev/null +++ b/azurerm/resource_arm_automation_variable_common.go @@ -0,0 +1,41 @@ +package azurerm + +import ( + "fmt" + "regexp" + "strconv" + "time" +) + +func parseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { + if input == nil { + if resource != "azurerm_automation_null_variable" { + return nil, fmt.Errorf("Expect resource to be %q, but actual value is %v", resource, input) + } + return nil, nil + } + + var value interface{} + var err error + actualResource := "Unknown" + datePattern := regexp.MustCompile(`"\\/Date\((-?[0-9]+)\)\\/"`) + matches := datePattern.FindStringSubmatch(*input) + if len(matches) == 2 && matches[0] == *input { + if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { + value = time.Unix(ticks/1000, ticks%1000*1000000) + actualResource = "azurerm_automation_datetime_variable" + } + } else if value, err = strconv.Unquote(*input); err == nil { + actualResource = "azurerm_automation_string_variable" + } else if value, err = strconv.ParseBool(*input); err == nil { + actualResource = "azurerm_automation_boolean_variable" + } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { + value = int32(value.(int64)) + actualResource = "azurerm_automation_integer_variable" + } + + if actualResource != resource { + return nil, fmt.Errorf("Expect value %q to be %q, but actually it is %q", *input, resource, actualResource) + } + return value, nil +} diff --git a/azurerm/resource_arm_automation_variable_common_test.go b/azurerm/resource_arm_automation_variable_common_test.go new file mode 100644 index 000000000000..1073f7dfdbd0 --- /dev/null +++ b/azurerm/resource_arm_automation_variable_common_test.go @@ -0,0 +1,83 @@ +package azurerm + +import ( + "testing" + "time" +) + +func TestParseAzureRmAutomationVariableValue(t *testing.T) { + type ExpectFunc func(interface{}) bool + cases := []struct { + Name string + Resource string + IsNil bool + Value string + HasError bool + ExpectValue interface{} + Expect ExpectFunc + }{ + { + Name: "null variable", + Resource: "azurerm_automation_null_variable", + IsNil: true, + Value: "", + HasError: false, + ExpectValue: nil, + Expect: func(v interface{}) bool { return v == nil }, + }, + { + Name: "string variable", + Resource: "azurerm_automation_string_variable", + Value: "\"Test String\"", + HasError: false, + ExpectValue: "Test String", + Expect: func(v interface{}) bool { return v.(string) == "Test String" }, + }, + { + Name: "integer variable", + Resource: "azurerm_automation_integer_variable", + Value: "135", + HasError: false, + ExpectValue: 135, + Expect: func(v interface{}) bool { return v.(int32) == 135 }, + }, + { + Name: "boolean variable", + Resource: "azurerm_automation_boolean_variable", + Value: "true", + HasError: false, + ExpectValue: true, + Expect: func(v interface{}) bool { return v.(bool) == true }, + }, + { + Name: "datetime variable", + Resource: "azurerm_automation_datetime_variable", + Value: "\"\\/Date(1556142054074)\\/\"", + HasError: false, + ExpectValue: time.Date(2019, time.April, 24, 14, 40, 54, 74000000, time.Local), + Expect: func(v interface{}) bool { + return v.(time.Time) == time.Date(2019, time.April, 24, 14, 40, 54, 74000000, time.Local) + }, + }, + } + + for _, tc := range cases { + t.Run(tc.Name, func(t *testing.T) { + value := &tc.Value + if tc.IsNil { + value = nil + } + actual, err := parseAzureRmAutomationVariableValue(tc.Resource, value) + if tc.HasError && err == nil { + t.Fatalf("Expect parseAzureRmAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) + } + if !tc.HasError { + if err != nil { + t.Fatalf("Expect parseAzureRmAutomationVariableValue to return no error for resource %q and value %s, err: %+v", tc.Resource, tc.Value, err) + } else if !tc.Expect(actual) { + t.Fatalf("Expect parseAzureRmAutomationVariableValue to return %v instead of %v for resource %q and value %s", tc.ExpectValue, actual, tc.Resource, tc.Value) + } + } + }) + } +} From 84067743fca5ec9281c95a2fac7b472edd75bac8 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 24 Apr 2019 19:14:42 -0700 Subject: [PATCH 03/29] Updates to string variable --- .../azure/automation_variable.go} | 4 +- .../azure/automation_variable_test.go} | 4 +- azurerm/provider.go | 1 + ...resource_arm_automation_string_variable.go | 167 ++++++++++++++ ...rce_arm_automation_string_variable_test.go | 203 ++++++++++++++++++ .../automation_string_variable.html.markdown | 69 ++++++ 6 files changed, 444 insertions(+), 4 deletions(-) rename azurerm/{resource_arm_automation_variable_common.go => helpers/azure/automation_variable.go} (94%) rename azurerm/{resource_arm_automation_variable_common_test.go => helpers/azure/automation_variable_test.go} (96%) create mode 100644 azurerm/resource_arm_automation_string_variable.go create mode 100644 azurerm/resource_arm_automation_string_variable_test.go create mode 100644 website/docs/r/automation_string_variable.html.markdown diff --git a/azurerm/resource_arm_automation_variable_common.go b/azurerm/helpers/azure/automation_variable.go similarity index 94% rename from azurerm/resource_arm_automation_variable_common.go rename to azurerm/helpers/azure/automation_variable.go index 2d80dd67bde3..63eb7f08ac33 100644 --- a/azurerm/resource_arm_automation_variable_common.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -1,4 +1,4 @@ -package azurerm +package azure import ( "fmt" @@ -7,7 +7,7 @@ import ( "time" ) -func parseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { +func ParseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { return nil, fmt.Errorf("Expect resource to be %q, but actual value is %v", resource, input) diff --git a/azurerm/resource_arm_automation_variable_common_test.go b/azurerm/helpers/azure/automation_variable_test.go similarity index 96% rename from azurerm/resource_arm_automation_variable_common_test.go rename to azurerm/helpers/azure/automation_variable_test.go index 1073f7dfdbd0..08ddfc998f81 100644 --- a/azurerm/resource_arm_automation_variable_common_test.go +++ b/azurerm/helpers/azure/automation_variable_test.go @@ -1,4 +1,4 @@ -package azurerm +package azure import ( "testing" @@ -67,7 +67,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { if tc.IsNil { value = nil } - actual, err := parseAzureRmAutomationVariableValue(tc.Resource, value) + actual, err := ParseAzureRmAutomationVariableValue(tc.Resource, value) if tc.HasError && err == nil { t.Fatalf("Expect parseAzureRmAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) } diff --git a/azurerm/provider.go b/azurerm/provider.go index d7fe04774a1a..8ee36c8664f6 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -179,6 +179,7 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_module": resourceArmAutomationModule(), "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go new file mode 100644 index 000000000000..1c010cbfbbc1 --- /dev/null +++ b/azurerm/resource_arm_automation_string_variable.go @@ -0,0 +1,167 @@ +package azurerm + +import ( + "fmt" + "log" + "strconv" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func resourceArmAutomationStringVariable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAutomationStringVariableCreateUpdate, + Read: resourceArmAutomationStringVariableRead, + Update: resourceArmAutomationStringVariableCreateUpdate, + Delete: resourceArmAutomationStringVariableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "value": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceArmAutomationStringVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_automation_string_variable", *resp.ID) + } + } + + description := d.Get("description").(string) + encrypted := d.Get("encrypted").(bool) + value := strconv.Quote(d.Get("value").(string)) + + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + Value: utils.String(value), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation String Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmAutomationStringVariableRead(d, meta) +} + +func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation String Variable %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_string_variable", properties.Value) + if err != nil { + return err + } + d.Set("value", value) + } + } + + return nil +} + +func resourceArmAutomationStringVariableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/resource_arm_automation_string_variable_test.go b/azurerm/resource_arm_automation_string_variable_test.go new file mode 100644 index 000000000000..9e96fb13cbff --- /dev/null +++ b/azurerm/resource_arm_automation_string_variable_test.go @@ -0,0 +1,203 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { + resourceName := "azurerm_automation_string_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationStringVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { + resourceName := "azurerm_automation_string_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationStringVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationStringVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_automation_string_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationStringVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + ), + }, + { + Config: testAccAzureRMAutomationStringVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationStringVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), + ), + }, + { + Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationStringVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + ), + }, + }, + }) +} + +func testCheckAzureRMAutomationStringVariableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation String Variable not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation String Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationStringVariableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_automation_string_variable" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMAutomationStringVariable_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_string_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + value = "Hello, Terraform Basic Test." +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAutomationStringVariable_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_string_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + description = "This variable is created by Terraform acceptance test." + value = "Hello, Terraform Complete Test." +} +`, rInt, location, rInt, rInt) +} diff --git a/website/docs/r/automation_string_variable.html.markdown b/website/docs/r/automation_string_variable.html.markdown new file mode 100644 index 000000000000..f61e6f3cd55e --- /dev/null +++ b/website/docs/r/automation_string_variable.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_string_variable" +sidebar_current: "docs-azurerm-resource-automation-string-variable" +description: |- + Manages an automation variable on Azure. +--- + +# azurerm_automation_string_variable + +Manages an automation variable on Azure. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "tfex-example-rg" + location = "West US" +} + +resource "azurerm_automation_account" "example" { + name = "tfex-example-account" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_string_variable" "example" { + name = "tfex-example-var" + resource_group_name = "${azurerm_resource_group.example.name}" + automation_account_name = "${azurerm_automation_account.example.name}" + value = "Hello, Terraform Basic Test." +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. + +* `description` - (Optional) The description of the Automation Variable. + +* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. + +* `value` - (Optional) The value of the Automation Variable. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + + +## Import + +Automation String Variable can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_automation_string_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +``` From 43514760e69b6a9d310fad3c2e642f960883e0f5 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 13:21:22 -0700 Subject: [PATCH 04/29] Updated error msgs --- azurerm/helpers/azure/automation_variable.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 63eb7f08ac33..aefcf7397a97 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -10,7 +10,7 @@ import ( func ParseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { - return nil, fmt.Errorf("Expect resource to be %q, but actual value is %v", resource, input) + return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource, actualResource) } return nil, nil } @@ -35,7 +35,7 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf } if actualResource != resource { - return nil, fmt.Errorf("Expect value %q to be %q, but actually it is %q", *input, resource, actualResource) + return nil, fmt.Errorf("Expected value %q to be %q, actual type is %q", *input, resource, actualResource) } return value, nil } From 7438635ffe511eb1dcc833f86b007fb7fe271376 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 13:27:00 -0700 Subject: [PATCH 05/29] Fix build break --- azurerm/helpers/azure/automation_variable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index aefcf7397a97..500999d218bb 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -10,7 +10,7 @@ import ( func ParseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { - return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource, actualResource) + return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource) } return nil, nil } From 5524afced0fc47b02ba27a23a4bcb959771839ea Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 14:21:41 -0700 Subject: [PATCH 06/29] Persist RG name and AA name to state file --- azurerm/resource_arm_automation_string_variable.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index 1c010cbfbbc1..404e727f1509 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -132,6 +132,8 @@ func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interf } d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) if properties := resp.VariableProperties; properties != nil { d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) From 0c7c1ed631aaa77e988df37b749d2aa06a74e0b7 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 15:13:01 -0700 Subject: [PATCH 07/29] Fix time skew issue --- azurerm/helpers/azure/automation_variable.go | 2 +- azurerm/helpers/azure/automation_variable_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 500999d218bb..a64a6a53764c 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -22,7 +22,7 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf matches := datePattern.FindStringSubmatch(*input) if len(matches) == 2 && matches[0] == *input { if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { - value = time.Unix(ticks/1000, ticks%1000*1000000) + value = time.Unix(ticks/1000, ticks%1000*1000000).In(time.UTC) actualResource = "azurerm_automation_datetime_variable" } } else if value, err = strconv.Unquote(*input); err == nil { diff --git a/azurerm/helpers/azure/automation_variable_test.go b/azurerm/helpers/azure/automation_variable_test.go index 08ddfc998f81..3e6ed49ee369 100644 --- a/azurerm/helpers/azure/automation_variable_test.go +++ b/azurerm/helpers/azure/automation_variable_test.go @@ -54,9 +54,9 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { Resource: "azurerm_automation_datetime_variable", Value: "\"\\/Date(1556142054074)\\/\"", HasError: false, - ExpectValue: time.Date(2019, time.April, 24, 14, 40, 54, 74000000, time.Local), + ExpectValue: time.Date(2019, time.April, 24, 21, 40, 54, 74000000, time.UTC), Expect: func(v interface{}) bool { - return v.(time.Time) == time.Date(2019, time.April, 24, 14, 40, 54, 74000000, time.Local) + return v.(time.Time) == time.Date(2019, time.April, 24, 21, 40, 54, 74000000, time.UTC) }, }, } From 3758c93d0ad0e499c783ba8f717a4bbb99855fe0 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 16:28:45 -0700 Subject: [PATCH 08/29] Add null variable resource --- azurerm/provider.go | 1 + .../resource_arm_automation_null_variable.go | 144 +++++++++++++ ...ource_arm_automation_null_variable_test.go | 196 ++++++++++++++++++ website/azurerm.erb | 8 + .../r/automation_null_variable.html.markdown | 64 ++++++ 5 files changed, 413 insertions(+) create mode 100644 azurerm/resource_arm_automation_null_variable.go create mode 100644 azurerm/resource_arm_automation_null_variable_test.go create mode 100644 website/docs/r/automation_null_variable.html.markdown diff --git a/azurerm/provider.go b/azurerm/provider.go index 8ee36c8664f6..513e4185fe41 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -179,6 +179,7 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_module": resourceArmAutomationModule(), "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_automation_null_variable": resourceArmAutomationNullVariable(), "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_availability_set": resourceArmAvailabilitySet(), diff --git a/azurerm/resource_arm_automation_null_variable.go b/azurerm/resource_arm_automation_null_variable.go new file mode 100644 index 000000000000..fb20aabdaf52 --- /dev/null +++ b/azurerm/resource_arm_automation_null_variable.go @@ -0,0 +1,144 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func resourceArmAutomationNullVariable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAutomationNullVariableCreateUpdate, + Read: resourceArmAutomationNullVariableRead, + Update: resourceArmAutomationNullVariableCreateUpdate, + Delete: resourceArmAutomationNullVariableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceArmAutomationNullVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_automation_null_variable", *resp.ID) + } + } + + description := d.Get("description").(string) + + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation Null Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmAutomationNullVariableRead(d, meta) +} + +func resourceArmAutomationNullVariableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation Null Variable %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + } + + return nil +} + +func resourceArmAutomationNullVariableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/resource_arm_automation_null_variable_test.go b/azurerm/resource_arm_automation_null_variable_test.go new file mode 100644 index 000000000000..42d6df75027a --- /dev/null +++ b/azurerm/resource_arm_automation_null_variable_test.go @@ -0,0 +1,196 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMAutomationNullVariable_basic(t *testing.T) { + resourceName := "azurerm_automation_null_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationNullVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationNullVariableExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationNullVariable_complete(t *testing.T) { + resourceName := "azurerm_automation_null_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationNullVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationNullVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationNullVariable_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_automation_null_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationNullVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationNullVariableExists(resourceName), + ), + }, + { + Config: testAccAzureRMAutomationNullVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationNullVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + ), + }, + { + Config: testAccAzureRMAutomationNullVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationNullVariableExists(resourceName), + ), + }, + }, + }) +} + +func testCheckAzureRMAutomationNullVariableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation Null Variable not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation Null Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationNullVariableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_automation_null_variable" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMAutomationNullVariable_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_null_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAutomationNullVariable_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_null_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + description = "This variable is created by Terraform acceptance test." +} +`, rInt, location, rInt, rInt) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 7db9c3e5b3c9..6cad3aa0ab39 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -409,6 +409,14 @@ > azurerm_automation_schedule + + > + azurerm_automation_null_variable + + + > + azurerm_automation_string_variable + diff --git a/website/docs/r/automation_null_variable.html.markdown b/website/docs/r/automation_null_variable.html.markdown new file mode 100644 index 000000000000..776c396644bc --- /dev/null +++ b/website/docs/r/automation_null_variable.html.markdown @@ -0,0 +1,64 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_null_variable" +sidebar_current: "docs-azurerm-resource-automation-null-variable" +description: |- + Manages an automation variable on Azure. +--- + +# azurerm_automation_null_variable + +Manages an automation variable on Azure. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "tfex-example-rg" + location = "West US" +} + +resource "azurerm_automation_account" "example" { + name = "tfex-example-account" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_null_variable" "example" { + name = "tfex-example-var" + resource_group_name = "${azurerm_resource_group.example.name}" + automation_account_name = "${azurerm_automation_account.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. + +* `description` - (Optional) The description of the Automation Variable. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + + +## Import + +Automation Null Variable can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_automation_null_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +``` From 8305a48cc9621c4bc4fbbcfe401e3309f5d92f95 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 25 Apr 2019 18:55:05 -0700 Subject: [PATCH 09/29] Added bool variable --- azurerm/helpers/azure/automation_variable.go | 2 +- .../helpers/azure/automation_variable_test.go | 2 +- azurerm/provider.go | 1 + .../resource_arm_automation_bool_variable.go | 169 +++++++++++++++ ...ource_arm_automation_bool_variable_test.go | 203 ++++++++++++++++++ website/azurerm.erb | 4 + .../r/automation_bool_variable.html.markdown | 69 ++++++ 7 files changed, 448 insertions(+), 2 deletions(-) create mode 100644 azurerm/resource_arm_automation_bool_variable.go create mode 100644 azurerm/resource_arm_automation_bool_variable_test.go create mode 100644 website/docs/r/automation_bool_variable.html.markdown diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index a64a6a53764c..a977a050556a 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -28,7 +28,7 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf } else if value, err = strconv.Unquote(*input); err == nil { actualResource = "azurerm_automation_string_variable" } else if value, err = strconv.ParseBool(*input); err == nil { - actualResource = "azurerm_automation_boolean_variable" + actualResource = "azurerm_automation_bool_variable" } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { value = int32(value.(int64)) actualResource = "azurerm_automation_integer_variable" diff --git a/azurerm/helpers/azure/automation_variable_test.go b/azurerm/helpers/azure/automation_variable_test.go index 3e6ed49ee369..fc7604b03390 100644 --- a/azurerm/helpers/azure/automation_variable_test.go +++ b/azurerm/helpers/azure/automation_variable_test.go @@ -43,7 +43,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }, { Name: "boolean variable", - Resource: "azurerm_automation_boolean_variable", + Resource: "azurerm_automation_bool_variable", Value: "true", HasError: false, ExpectValue: true, diff --git a/azurerm/provider.go b/azurerm/provider.go index 513e4185fe41..34ae4f02c4d0 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -179,6 +179,7 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_module": resourceArmAutomationModule(), "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_automation_bool_variable": resourceArmAutomationBoolVariable(), "azurerm_automation_null_variable": resourceArmAutomationNullVariable(), "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go new file mode 100644 index 000000000000..acd6a778a462 --- /dev/null +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -0,0 +1,169 @@ +package azurerm + +import ( + "fmt" + "log" + "strconv" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func resourceArmAutomationBoolVariable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAutomationBoolVariableCreateUpdate, + Read: resourceArmAutomationBoolVariableRead, + Update: resourceArmAutomationBoolVariableCreateUpdate, + Delete: resourceArmAutomationBoolVariableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "value": { + Type: schema.TypeBool, + Optional: true, + }, + }, + } +} + +func resourceArmAutomationBoolVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_automation_bool_variable", *resp.ID) + } + } + + description := d.Get("description").(string) + encrypted := d.Get("encrypted").(bool) + value := strconv.FormatBool(d.Get("value").(bool)) + + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + Value: utils.String(value), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation Bool Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmAutomationBoolVariableRead(d, meta) +} + +func resourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation Bool Variable %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_bool_variable", properties.Value) + if err != nil { + return err + } + d.Set("value", value) + } + } + + return nil +} + +func resourceArmAutomationBoolVariableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/resource_arm_automation_bool_variable_test.go b/azurerm/resource_arm_automation_bool_variable_test.go new file mode 100644 index 000000000000..ac4449a0741c --- /dev/null +++ b/azurerm/resource_arm_automation_bool_variable_test.go @@ -0,0 +1,203 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { + resourceName := "azurerm_automation_bool_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationBoolVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "false"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { + resourceName := "azurerm_automation_bool_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationBoolVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationBoolVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_automation_bool_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationBoolVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "false"), + ), + }, + { + Config: testAccAzureRMAutomationBoolVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationBoolVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "true"), + ), + }, + { + Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationBoolVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "false"), + ), + }, + }, + }) +} + +func testCheckAzureRMAutomationBoolVariableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation Bool Variable not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation Bool Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationBoolVariableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_automation_bool_variable" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMAutomationBoolVariable_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_bool_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + value = false +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAutomationBoolVariable_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_bool_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + description = "This variable is created by Terraform acceptance test." + value = true +} +`, rInt, location, rInt, rInt) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 6cad3aa0ab39..4c7781a82f79 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -410,6 +410,10 @@ azurerm_automation_schedule + > + azurerm_automation_bool_variable + + > azurerm_automation_null_variable diff --git a/website/docs/r/automation_bool_variable.html.markdown b/website/docs/r/automation_bool_variable.html.markdown new file mode 100644 index 000000000000..445e68440c32 --- /dev/null +++ b/website/docs/r/automation_bool_variable.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_bool_variable" +sidebar_current: "docs-azurerm-resource-automation-bool-variable" +description: |- + Manages an automation variable on Azure. +--- + +# azurerm_automation_bool_variable + +Manages an automation variable on Azure. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "tfex-example-rg" + location = "West US" +} + +resource "azurerm_automation_account" "example" { + name = "tfex-example-account" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_bool_variable" "example" { + name = "tfex-example-var" + resource_group_name = "${azurerm_resource_group.example.name}" + automation_account_name = "${azurerm_automation_account.example.name}" + value = false +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. + +* `description` - (Optional) The description of the Automation Variable. + +* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. + +* `value` - (Optional) The value of the Automation Variable. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + + +## Import + +Automation Bool Variable can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_automation_bool_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +``` From 4468f3624960b42626cb7a8b80ce52ec5c6c446b Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 26 Apr 2019 13:58:21 -0700 Subject: [PATCH 10/29] Added azurerm_automation_int_variable --- azurerm/helpers/azure/automation_variable.go | 2 +- .../helpers/azure/automation_variable_test.go | 2 +- azurerm/provider.go | 1 + .../resource_arm_automation_int_variable.go | 169 +++++++++++++++ ...source_arm_automation_int_variable_test.go | 203 ++++++++++++++++++ website/azurerm.erb | 4 + .../r/automation_int_variable.html.markdown | 69 ++++++ 7 files changed, 448 insertions(+), 2 deletions(-) create mode 100644 azurerm/resource_arm_automation_int_variable.go create mode 100644 azurerm/resource_arm_automation_int_variable_test.go create mode 100644 website/docs/r/automation_int_variable.html.markdown diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index a977a050556a..42e9aeda431b 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -31,7 +31,7 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf actualResource = "azurerm_automation_bool_variable" } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { value = int32(value.(int64)) - actualResource = "azurerm_automation_integer_variable" + actualResource = "azurerm_automation_int_variable" } if actualResource != resource { diff --git a/azurerm/helpers/azure/automation_variable_test.go b/azurerm/helpers/azure/automation_variable_test.go index fc7604b03390..f3a6b41a782f 100644 --- a/azurerm/helpers/azure/automation_variable_test.go +++ b/azurerm/helpers/azure/automation_variable_test.go @@ -35,7 +35,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }, { Name: "integer variable", - Resource: "azurerm_automation_integer_variable", + Resource: "azurerm_automation_int_variable", Value: "135", HasError: false, ExpectValue: 135, diff --git a/azurerm/provider.go b/azurerm/provider.go index 34ae4f02c4d0..a0972d118941 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -180,6 +180,7 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), "azurerm_automation_bool_variable": resourceArmAutomationBoolVariable(), + "azurerm_automation_int_variable": resourceArmAutomationIntVariable(), "azurerm_automation_null_variable": resourceArmAutomationNullVariable(), "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go new file mode 100644 index 000000000000..596c75cf9439 --- /dev/null +++ b/azurerm/resource_arm_automation_int_variable.go @@ -0,0 +1,169 @@ +package azurerm + +import ( + "fmt" + "log" + "strconv" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func resourceArmAutomationIntVariable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAutomationIntVariableCreateUpdate, + Read: resourceArmAutomationIntVariableRead, + Update: resourceArmAutomationIntVariableCreateUpdate, + Delete: resourceArmAutomationIntVariableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "value": { + Type: schema.TypeInt, + Optional: true, + }, + }, + } +} + +func resourceArmAutomationIntVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_automation_int_variable", *resp.ID) + } + } + + description := d.Get("description").(string) + encrypted := d.Get("encrypted").(bool) + value := strconv.Itoa(d.Get("value").(int)) + + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + Value: utils.String(value), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation Int Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmAutomationIntVariableRead(d, meta) +} + +func resourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation Int Variable %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_int_variable", properties.Value) + if err != nil { + return err + } + d.Set("value", value) + } + } + + return nil +} + +func resourceArmAutomationIntVariableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/resource_arm_automation_int_variable_test.go b/azurerm/resource_arm_automation_int_variable_test.go new file mode 100644 index 000000000000..35467dbf85f8 --- /dev/null +++ b/azurerm/resource_arm_automation_int_variable_test.go @@ -0,0 +1,203 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { + resourceName := "azurerm_automation_int_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationIntVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "1234"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { + resourceName := "azurerm_automation_int_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationIntVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationIntVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "12345"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_automation_int_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationIntVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "1234"), + ), + }, + { + Config: testAccAzureRMAutomationIntVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationIntVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "12345"), + ), + }, + { + Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationIntVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "1234"), + ), + }, + }, + }) +} + +func testCheckAzureRMAutomationIntVariableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation Int Variable not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation Int Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationIntVariableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_automation_int_variable" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMAutomationIntVariable_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_int_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + value = 1234 +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAutomationIntVariable_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_int_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + description = "This variable is created by Terraform acceptance test." + value = 12345 +} +`, rInt, location, rInt, rInt) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 4c7781a82f79..0db58299beb5 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -414,6 +414,10 @@ azurerm_automation_bool_variable + > + azurerm_automation_bool_variable + + > azurerm_automation_null_variable diff --git a/website/docs/r/automation_int_variable.html.markdown b/website/docs/r/automation_int_variable.html.markdown new file mode 100644 index 000000000000..2a659b2df43d --- /dev/null +++ b/website/docs/r/automation_int_variable.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_int_variable" +sidebar_current: "docs-azurerm-resource-automation-int-variable" +description: |- + Manages an automation variable on Azure. +--- + +# azurerm_automation_int_variable + +Manages an automation variable on Azure. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "tfex-example-rg" + location = "West US" +} + +resource "azurerm_automation_account" "example" { + name = "tfex-example-account" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_int_variable" "example" { + name = "tfex-example-var" + resource_group_name = "${azurerm_resource_group.example.name}" + automation_account_name = "${azurerm_automation_account.example.name}" + value = 1234 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. + +* `description` - (Optional) The description of the Automation Variable. + +* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. + +* `value` - (Optional) The value of the Automation Variable. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + + +## Import + +Automation Int Variable can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_automation_int_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +``` From 9823ecbb947f4e6d318c9e52539637d5b62707ec Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 26 Apr 2019 18:39:39 -0700 Subject: [PATCH 11/29] Added datetime variable --- azurerm/provider.go | 1 + ...source_arm_automation_datetime_variable.go | 173 +++++++++++++++ ...e_arm_automation_datetime_variable_test.go | 203 ++++++++++++++++++ website/azurerm.erb | 4 + ...automation_datetime_variable.html.markdown | 69 ++++++ 5 files changed, 450 insertions(+) create mode 100644 azurerm/resource_arm_automation_datetime_variable.go create mode 100644 azurerm/resource_arm_automation_datetime_variable_test.go create mode 100644 website/docs/r/automation_datetime_variable.html.markdown diff --git a/azurerm/provider.go b/azurerm/provider.go index a0972d118941..9b84a153e3e8 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -180,6 +180,7 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), "azurerm_automation_bool_variable": resourceArmAutomationBoolVariable(), + "azurerm_automation_datetime_variable": resourceArmAutomationDatetimeVariable(), "azurerm_automation_int_variable": resourceArmAutomationIntVariable(), "azurerm_automation_null_variable": resourceArmAutomationNullVariable(), "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go new file mode 100644 index 000000000000..76c01b049d5c --- /dev/null +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -0,0 +1,173 @@ +package azurerm + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func resourceArmAutomationDatetimeVariable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAutomationDatetimeVariableCreateUpdate, + Read: resourceArmAutomationDatetimeVariableRead, + Update: resourceArmAutomationDatetimeVariableCreateUpdate, + Delete: resourceArmAutomationDatetimeVariableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "value": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceArmAutomationDatetimeVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_automation_datetime_variable", *resp.ID) + } + } + + description := d.Get("description").(string) + encrypted := d.Get("encrypted").(bool) + vTime, parseErr := time.Parse(time.RFC3339, d.Get("value").(string)) + if parseErr != nil { + return fmt.Errorf("Error invalid time format: %+v", parseErr) + } + value := fmt.Sprintf("\"\\/Date(%d)\\/\"", vTime.UnixNano()/1000000) + + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + Value: utils.String(value), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmAutomationDatetimeVariableRead(d, meta) +} + +func resourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation Datetime Variable %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_datetime_variable", properties.Value) + if err != nil { + return err + } + d.Set("value", value.(time.Time).Format("2006-01-02T15:04:05.999Z")) + } + } + + return nil +} + +func resourceArmAutomationDatetimeVariableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/resource_arm_automation_datetime_variable_test.go b/azurerm/resource_arm_automation_datetime_variable_test.go new file mode 100644 index 000000000000..db3c68f733cd --- /dev/null +++ b/azurerm/resource_arm_automation_datetime_variable_test.go @@ -0,0 +1,203 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { + resourceName := "azurerm_automation_datetime_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { + resourceName := "azurerm_automation_datetime_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationDatetimeVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_automation_datetime_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + ), + }, + { + Config: testAccAzureRMAutomationDatetimeVariable_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), + ), + }, + { + Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + ), + }, + }, + }) +} + +func testCheckAzureRMAutomationDatetimeVariableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation Datetime Variable not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationDatetimeVariableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_automation_datetime_variable" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMAutomationDatetimeVariable_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_datetime_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + value = "2019-04-24T21:40:54.074Z" +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAutomationDatetimeVariable_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctestAutoAcct-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_datetime_variable" "test" { + name = "acctestAutoVar-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + automation_account_name = "${azurerm_automation_account.test.name}" + description = "This variable is created by Terraform acceptance test." + value = "2019-04-20T08:40:04.02Z" +} +`, rInt, location, rInt, rInt) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 0db58299beb5..6db9dfe3d710 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -414,6 +414,10 @@ azurerm_automation_bool_variable + > + azurerm_automation_datetime_variable + + > azurerm_automation_bool_variable diff --git a/website/docs/r/automation_datetime_variable.html.markdown b/website/docs/r/automation_datetime_variable.html.markdown new file mode 100644 index 000000000000..5c20d63cc6fc --- /dev/null +++ b/website/docs/r/automation_datetime_variable.html.markdown @@ -0,0 +1,69 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_datetime_variable" +sidebar_current: "docs-azurerm-resource-automation-datetime-variable" +description: |- + Manages an automation variable on Azure. +--- + +# azurerm_automation_datetime_variable + +Manages an automation variable on Azure. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "tfex-example-rg" + location = "West US" +} + +resource "azurerm_automation_account" "example" { + name = "tfex-example-account" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = { + name = "Basic" + } +} + +resource "azurerm_automation_datetime_variable" "example" { + name = "tfex-example-var" + resource_group_name = "${azurerm_resource_group.example.name}" + automation_account_name = "${azurerm_automation_account.example.name}" + value = "2019-04-24T21:40:54.074Z" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. + +* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. + +* `description` - (Optional) The description of the Automation Variable. + +* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. + +* `value` - (Optional) The value of the Automation Variable. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + + +## Import + +Automation Datetime Variable can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_automation_datetime_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +``` From 49ef0b089efd3fe171e444652f764e1096411dac Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 29 Apr 2019 12:25:59 -0700 Subject: [PATCH 12/29] Update azurerm/helpers/azure/automation_variable.go Co-Authored-By: jeffreyCline --- azurerm/helpers/azure/automation_variable.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 42e9aeda431b..6fad91a447d6 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -20,6 +20,7 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf actualResource := "Unknown" datePattern := regexp.MustCompile(`"\\/Date\((-?[0-9]+)\)\\/"`) matches := datePattern.FindStringSubmatch(*input) + if len(matches) == 2 && matches[0] == *input { if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { value = time.Unix(ticks/1000, ticks%1000*1000000).In(time.UTC) From 3b6bfe879d31732986c2f3dc924529dec5b93952 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 29 Apr 2019 12:26:25 -0700 Subject: [PATCH 13/29] Update website/docs/r/automation_bool_variable.html.markdown Co-Authored-By: jeffreyCline --- website/docs/r/automation_bool_variable.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/automation_bool_variable.html.markdown b/website/docs/r/automation_bool_variable.html.markdown index 445e68440c32..41db4cdb9099 100644 --- a/website/docs/r/automation_bool_variable.html.markdown +++ b/website/docs/r/automation_bool_variable.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `description` - (Optional) The description of the Automation Variable. -* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. +* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. * `value` - (Optional) The value of the Automation Variable. From 972720bf2ce22baa1f861a30d25e820e6dfb3da5 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 1 May 2019 15:53:47 -0700 Subject: [PATCH 14/29] Changes per PR comments --- azurerm/automation_variable.go | 225 ++++++++++++++++++ .../azure => }/automation_variable_test.go | 4 +- .../resource_arm_automation_bool_variable.go | 139 +---------- ...source_arm_automation_datetime_variable.go | 143 +---------- .../resource_arm_automation_int_variable.go | 139 +---------- .../resource_arm_automation_null_variable.go | 119 +-------- ...resource_arm_automation_string_variable.go | 139 +---------- .../r/automation_bool_variable.html.markdown | 10 +- ...automation_datetime_variable.html.markdown | 12 +- .../r/automation_int_variable.html.markdown | 12 +- .../r/automation_null_variable.html.markdown | 10 +- .../automation_string_variable.html.markdown | 12 +- 12 files changed, 281 insertions(+), 683 deletions(-) create mode 100644 azurerm/automation_variable.go rename azurerm/{helpers/azure => }/automation_variable_test.go (96%) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go new file mode 100644 index 000000000000..7ec0fcba9ee9 --- /dev/null +++ b/azurerm/automation_variable.go @@ -0,0 +1,225 @@ +package azurerm + +import ( + "fmt" + "log" + "regexp" + "strconv" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" + "github.com/hashicorp/terraform/helper/schema" + "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/utils" +) + +func parseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { + if input == nil { + if resource != "azurerm_automation_null_variable" { + return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource) + } + return nil, nil + } + + var value interface{} + var err error + actualResource := "Unknown" + datePattern := regexp.MustCompile(`"\\/Date\((-?[0-9]+)\)\\/"`) + matches := datePattern.FindStringSubmatch(*input) + + if len(matches) == 2 && matches[0] == *input { + if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { + value = time.Unix(ticks/1000, ticks%1000*1000000).In(time.UTC) + actualResource = "azurerm_automation_datetime_variable" + } + } else if value, err = strconv.Unquote(*input); err == nil { + actualResource = "azurerm_automation_string_variable" + } else if value, err = strconv.ParseBool(*input); err == nil { + actualResource = "azurerm_automation_bool_variable" + } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { + value = int32(value.(int64)) + actualResource = "azurerm_automation_int_variable" + } + + if actualResource != resource { + return nil, fmt.Errorf("Expected value %q to be %q, actual type is %q", *input, resource, actualResource) + } + return value, nil +} + +func AutomationVariableCommonSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema { + + varSchema := map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + } + return azure.MergeSchema(s, varSchema) +} + +func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + varTypeLower := strings.ToLower(varType) + + if requireResourcesToBeImported { + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), *resp.ID) + } + } + + description := d.Get("description").(string) + encrypted := d.Get("encrypted").(bool) + value := "" + + if varTypeLower == "datetime" { + vTime, parseErr := time.Parse(time.RFC3339, d.Get("value").(string)) + if parseErr != nil { + return fmt.Errorf("Error invalid time format: %+v", parseErr) + } + value = fmt.Sprintf("\"\\/Date(%d)\\/\"", vTime.UnixNano()/1000000) + } else if varTypeLower == "bool" { + value = strconv.FormatBool(d.Get("value").(bool)) + } else if varTypeLower == "int" { + value = strconv.Itoa(d.Get("value").(int)) + } else if varTypeLower == "string" { + value = strconv.Quote(d.Get("value").(string)) + } + + parameters := automation.VariableCreateOrUpdateParameters{} + + if varTypeLower == "null" { + parameters = automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + }, + } + } else { + parameters = automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + Value: utils.String(value), + }, + } + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { + return fmt.Errorf("Error creating Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + return fmt.Errorf("Error retrieving Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Automation %s Variable %q (Automation Account Name %q / Resource Group %q) ID", varType, name, accountName, resourceGroup) + } + d.SetId(*resp.ID) + + return nil +} + +func resourceArmAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + varTypeLower := strings.ToLower(varType) + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation %s Variable %q does not exist - removing from state", varType, d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := parseAzureRmAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) + if err != nil { + return err + } + + if varTypeLower == "datetime" { + d.Set("value", value.(time.Time).Format("2006-01-02T15:04:05.999Z")) + } else if varTypeLower != "null" { + d.Set("value", value) + } + } + } + + return nil +} + +func resourceArmAutomationVariableDelete(d *schema.ResourceData, meta interface{}, varType string) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + accountName := id.Path["automationAccounts"] + name := id.Path["variables"] + + if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { + return fmt.Errorf("Error deleting Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/helpers/azure/automation_variable_test.go b/azurerm/automation_variable_test.go similarity index 96% rename from azurerm/helpers/azure/automation_variable_test.go rename to azurerm/automation_variable_test.go index f3a6b41a782f..2ad332039b23 100644 --- a/azurerm/helpers/azure/automation_variable_test.go +++ b/azurerm/automation_variable_test.go @@ -1,4 +1,4 @@ -package azure +package azurerm import ( "testing" @@ -67,7 +67,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { if tc.IsNil { value = nil } - actual, err := ParseAzureRmAutomationVariableValue(tc.Resource, value) + actual, err := parseAzureRmAutomationVariableValue(tc.Resource, value) if tc.HasError && err == nil { t.Fatalf("Expect parseAzureRmAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) } diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go index acd6a778a462..32f91d9b0260 100644 --- a/azurerm/resource_arm_automation_bool_variable.go +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -1,16 +1,7 @@ package azurerm import ( - "fmt" - "log" - "strconv" - - "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" ) func resourceArmAutomationBoolVariable() *schema.Resource { @@ -24,146 +15,28 @@ func resourceArmAutomationBoolVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), - "automation_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - - "encrypted": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "value": { Type: schema.TypeBool, Optional: true, }, - }, + }), } } func resourceArmAutomationBoolVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("automation_account_name").(string) - - if requireResourcesToBeImported { - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error checking for present of existing Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - } - if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError("azurerm_automation_bool_variable", *resp.ID) - } - } - - description := d.Get("description").(string) - encrypted := d.Get("encrypted").(bool) - value := strconv.FormatBool(d.Get("value").(bool)) - - parameters := automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - Value: utils.String(value), - }, - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { - return fmt.Errorf("Error creating Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - return fmt.Errorf("Error retrieving Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Automation Bool Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Bool"); err != nil { + return err } - d.SetId(*resp.ID) - return resourceArmAutomationBoolVariableRead(d, meta) } func resourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Automation Bool Variable %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("automation_account_name", accountName) - if properties := resp.VariableProperties; properties != nil { - d.Set("description", properties.Description) - d.Set("encrypted", properties.IsEncrypted) - if !d.Get("encrypted").(bool) { - value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_bool_variable", properties.Value) - if err != nil { - return err - } - d.Set("value", value) - } - } - - return nil + return resourceArmAutomationVariableRead(d, meta, "Bool") } func resourceArmAutomationBoolVariableDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { - return fmt.Errorf("Error deleting Automation Bool Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - return nil + return resourceArmAutomationVariableDelete(d, meta, "Bool") } diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go index 76c01b049d5c..146e5e28ac6f 100644 --- a/azurerm/resource_arm_automation_datetime_variable.go +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -1,16 +1,7 @@ package azurerm import ( - "fmt" - "log" - "time" - - "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" ) func resourceArmAutomationDatetimeVariable() *schema.Resource { @@ -24,150 +15,28 @@ func resourceArmAutomationDatetimeVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), - "automation_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - - "encrypted": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "value": { Type: schema.TypeString, Optional: true, }, - }, + }), } } func resourceArmAutomationDatetimeVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("automation_account_name").(string) - - if requireResourcesToBeImported { - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error checking for present of existing Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - } - if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError("azurerm_automation_datetime_variable", *resp.ID) - } - } - - description := d.Get("description").(string) - encrypted := d.Get("encrypted").(bool) - vTime, parseErr := time.Parse(time.RFC3339, d.Get("value").(string)) - if parseErr != nil { - return fmt.Errorf("Error invalid time format: %+v", parseErr) - } - value := fmt.Sprintf("\"\\/Date(%d)\\/\"", vTime.UnixNano()/1000000) - - parameters := automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - Value: utils.String(value), - }, - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { - return fmt.Errorf("Error creating Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - return fmt.Errorf("Error retrieving Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Datetime"); err != nil { + return err } - d.SetId(*resp.ID) - return resourceArmAutomationDatetimeVariableRead(d, meta) } func resourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Automation Datetime Variable %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("automation_account_name", accountName) - if properties := resp.VariableProperties; properties != nil { - d.Set("description", properties.Description) - d.Set("encrypted", properties.IsEncrypted) - if !d.Get("encrypted").(bool) { - value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_datetime_variable", properties.Value) - if err != nil { - return err - } - d.Set("value", value.(time.Time).Format("2006-01-02T15:04:05.999Z")) - } - } - - return nil + return resourceArmAutomationVariableRead(d, meta, "Datetime") } func resourceArmAutomationDatetimeVariableDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { - return fmt.Errorf("Error deleting Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - return nil + return resourceArmAutomationVariableDelete(d, meta, "Datetime") } diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go index 596c75cf9439..e328ab4878bc 100644 --- a/azurerm/resource_arm_automation_int_variable.go +++ b/azurerm/resource_arm_automation_int_variable.go @@ -1,16 +1,7 @@ package azurerm import ( - "fmt" - "log" - "strconv" - - "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" ) func resourceArmAutomationIntVariable() *schema.Resource { @@ -24,146 +15,28 @@ func resourceArmAutomationIntVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), - "automation_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - - "encrypted": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "value": { Type: schema.TypeInt, Optional: true, }, - }, + }), } } func resourceArmAutomationIntVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("automation_account_name").(string) - - if requireResourcesToBeImported { - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error checking for present of existing Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - } - if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError("azurerm_automation_int_variable", *resp.ID) - } - } - - description := d.Get("description").(string) - encrypted := d.Get("encrypted").(bool) - value := strconv.Itoa(d.Get("value").(int)) - - parameters := automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - Value: utils.String(value), - }, - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { - return fmt.Errorf("Error creating Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - return fmt.Errorf("Error retrieving Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Automation Int Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Int"); err != nil { + return err } - d.SetId(*resp.ID) - return resourceArmAutomationIntVariableRead(d, meta) } func resourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Automation Int Variable %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("automation_account_name", accountName) - if properties := resp.VariableProperties; properties != nil { - d.Set("description", properties.Description) - d.Set("encrypted", properties.IsEncrypted) - if !d.Get("encrypted").(bool) { - value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_int_variable", properties.Value) - if err != nil { - return err - } - d.Set("value", value) - } - } - - return nil + return resourceArmAutomationVariableRead(d, meta, "Int") } func resourceArmAutomationIntVariableDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { - return fmt.Errorf("Error deleting Automation Int Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - return nil + return resourceArmAutomationVariableDelete(d, meta, "Int") } diff --git a/azurerm/resource_arm_automation_null_variable.go b/azurerm/resource_arm_automation_null_variable.go index fb20aabdaf52..50cfc366dce9 100644 --- a/azurerm/resource_arm_automation_null_variable.go +++ b/azurerm/resource_arm_automation_null_variable.go @@ -1,14 +1,7 @@ package azurerm import ( - "fmt" - "log" - - "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" ) func resourceArmAutomationNullVariable() *schema.Resource { @@ -22,123 +15,23 @@ func resourceArmAutomationNullVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), - - "automation_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - }, + }), } } func resourceArmAutomationNullVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("automation_account_name").(string) - - if requireResourcesToBeImported { - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error checking for present of existing Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - } - if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError("azurerm_automation_null_variable", *resp.ID) - } - } - - description := d.Get("description").(string) - - parameters := automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - }, - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { - return fmt.Errorf("Error creating Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - return fmt.Errorf("Error retrieving Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Automation Null Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Null"); err != nil { + return err } - d.SetId(*resp.ID) - return resourceArmAutomationNullVariableRead(d, meta) } func resourceArmAutomationNullVariableRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Automation Null Variable %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("automation_account_name", accountName) - if properties := resp.VariableProperties; properties != nil { - d.Set("description", properties.Description) - } - - return nil + return resourceArmAutomationVariableRead(d, meta, "Null") } func resourceArmAutomationNullVariableDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { - return fmt.Errorf("Error deleting Automation Null Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - return nil + return resourceArmAutomationVariableDelete(d, meta, "Null") } diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index 404e727f1509..c5db9bc97a10 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -1,16 +1,7 @@ package azurerm import ( - "fmt" - "log" - "strconv" - - "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" ) func resourceArmAutomationStringVariable() *schema.Resource { @@ -24,146 +15,28 @@ func resourceArmAutomationStringVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), - "automation_account_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - - "encrypted": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "value": { Type: schema.TypeString, Optional: true, }, - }, + }), } } func resourceArmAutomationStringVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("automation_account_name").(string) - - if requireResourcesToBeImported { - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error checking for present of existing Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - } - if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError("azurerm_automation_string_variable", *resp.ID) - } - } - - description := d.Get("description").(string) - encrypted := d.Get("encrypted").(bool) - value := strconv.Quote(d.Get("value").(string)) - - parameters := automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - Value: utils.String(value), - }, - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { - return fmt.Errorf("Error creating Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - return fmt.Errorf("Error retrieving Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Automation String Variable %q (Automation Account Name %q / Resource Group %q) ID", name, accountName, resourceGroup) + if err := resourceArmAutomationVariableCreateUpdate(d, meta, "String"); err != nil { + return err } - d.SetId(*resp.ID) - return resourceArmAutomationStringVariableRead(d, meta) } func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - resp, err := client.Get(ctx, resourceGroup, accountName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Automation String Variable %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("automation_account_name", accountName) - if properties := resp.VariableProperties; properties != nil { - d.Set("description", properties.Description) - d.Set("encrypted", properties.IsEncrypted) - if !d.Get("encrypted").(bool) { - value, err := azure.ParseAzureRmAutomationVariableValue("azurerm_automation_string_variable", properties.Value) - if err != nil { - return err - } - d.Set("value", value) - } - } - - return nil + return resourceArmAutomationVariableRead(d, meta, "String") } func resourceArmAutomationStringVariableDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).automationVariableClient - ctx := meta.(*ArmClient).StopContext - - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - accountName := id.Path["automationAccounts"] - name := id.Path["variables"] - - if _, err := client.Delete(ctx, resourceGroup, accountName, name); err != nil { - return fmt.Errorf("Error deleting Automation String Variable %q (Automation Account Name %q / Resource Group %q): %+v", name, accountName, resourceGroup, err) - } - - return nil + return resourceArmAutomationVariableDelete(d, meta, "String") } diff --git a/website/docs/r/automation_bool_variable.html.markdown b/website/docs/r/automation_bool_variable.html.markdown index 41db4cdb9099..7c8c78131885 100644 --- a/website/docs/r/automation_bool_variable.html.markdown +++ b/website/docs/r/automation_bool_variable.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_bool_variable" sidebar_current: "docs-azurerm-resource-automation-bool-variable" description: |- - Manages an automation variable on Azure. + Manages a boolean variable in Azure Automation. --- # azurerm_automation_bool_variable -Manages an automation variable on Azure. +Manages a boolean variable in Azure Automation ## Example Usage @@ -24,9 +24,7 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku = { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_bool_variable" "example" { @@ -51,7 +49,7 @@ The following arguments are supported: * `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. -* `value` - (Optional) The value of the Automation Variable. +* `value` - (Optional) The value of the Automation Variable as a `boolean`. ## Attributes Reference diff --git a/website/docs/r/automation_datetime_variable.html.markdown b/website/docs/r/automation_datetime_variable.html.markdown index 5c20d63cc6fc..4ace656a44bf 100644 --- a/website/docs/r/automation_datetime_variable.html.markdown +++ b/website/docs/r/automation_datetime_variable.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_datetime_variable" sidebar_current: "docs-azurerm-resource-automation-datetime-variable" description: |- - Manages an automation variable on Azure. + Manages a date/time variable in Azure Automation. --- # azurerm_automation_datetime_variable -Manages an automation variable on Azure. +Manages a date/time variable in Azure Automation ## Example Usage @@ -24,9 +24,7 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku = { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_datetime_variable" "example" { @@ -49,9 +47,9 @@ The following arguments are supported: * `description` - (Optional) The description of the Automation Variable. -* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. +* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. -* `value` - (Optional) The value of the Automation Variable. +* `value` - (Optional) The value of the Automation Variable in the [RFC3339 Section 5.6 Internet Date/Time Format](https://tools.ietf.org/html/rfc3339#section-5.6). ## Attributes Reference diff --git a/website/docs/r/automation_int_variable.html.markdown b/website/docs/r/automation_int_variable.html.markdown index 2a659b2df43d..6f2a505ac00c 100644 --- a/website/docs/r/automation_int_variable.html.markdown +++ b/website/docs/r/automation_int_variable.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_int_variable" sidebar_current: "docs-azurerm-resource-automation-int-variable" description: |- - Manages an automation variable on Azure. + Manages a integer variable in Azure Automation. --- # azurerm_automation_int_variable -Manages an automation variable on Azure. +Manages a integer variable in Azure Automation ## Example Usage @@ -24,9 +24,7 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku = { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_int_variable" "example" { @@ -49,9 +47,9 @@ The following arguments are supported: * `description` - (Optional) The description of the Automation Variable. -* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. +* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. -* `value` - (Optional) The value of the Automation Variable. +* `value` - (Optional) The value of the Automation Variable as a `integer`. ## Attributes Reference diff --git a/website/docs/r/automation_null_variable.html.markdown b/website/docs/r/automation_null_variable.html.markdown index 776c396644bc..f1aff89cf3b1 100644 --- a/website/docs/r/automation_null_variable.html.markdown +++ b/website/docs/r/automation_null_variable.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_null_variable" sidebar_current: "docs-azurerm-resource-automation-null-variable" description: |- - Manages an automation variable on Azure. + Manages a null variable in Azure Automation --- # azurerm_automation_null_variable -Manages an automation variable on Azure. +Manages a null variable in Azure Automation ## Example Usage @@ -24,9 +24,7 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku = { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_null_variable" "example" { @@ -48,6 +46,8 @@ The following arguments are supported: * `description` - (Optional) The description of the Automation Variable. +* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. + ## Attributes Reference The following attributes are exported: diff --git a/website/docs/r/automation_string_variable.html.markdown b/website/docs/r/automation_string_variable.html.markdown index f61e6f3cd55e..9a114d0642d3 100644 --- a/website/docs/r/automation_string_variable.html.markdown +++ b/website/docs/r/automation_string_variable.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_string_variable" sidebar_current: "docs-azurerm-resource-automation-string-variable" description: |- - Manages an automation variable on Azure. + Manages a string variable in Azure Automation. --- # azurerm_automation_string_variable -Manages an automation variable on Azure. +Manages a string variable in Azure Automation ## Example Usage @@ -24,9 +24,7 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku = { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_string_variable" "example" { @@ -49,9 +47,9 @@ The following arguments are supported: * `description` - (Optional) The description of the Automation Variable. -* `encrypted` - (Optional) The encrypted flag of the Automation Variable. Defaults to `false`. +* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. -* `value` - (Optional) The value of the Automation Variable. +* `value` - (Optional) The value of the Automation Variable as a `string`. ## Attributes Reference From e256005692c0fc8fb525457511f167d36f63872e Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 2 May 2019 16:49:31 -0700 Subject: [PATCH 15/29] Changes requested per PR comments --- azurerm/automation_variable.go | 31 ++++------ azurerm/automation_variable_test.go | 58 +++++++++++++++++++ .../resource_arm_automation_bool_variable.go | 7 +-- ...ource_arm_automation_bool_variable_test.go | 47 +-------------- ...source_arm_automation_datetime_variable.go | 13 ++--- ...e_arm_automation_datetime_variable_test.go | 47 +-------------- .../resource_arm_automation_int_variable.go | 7 +-- ...source_arm_automation_int_variable_test.go | 47 +-------------- .../resource_arm_automation_null_variable.go | 9 +-- ...ource_arm_automation_null_variable_test.go | 47 +-------------- ...resource_arm_automation_string_variable.go | 13 ++--- ...rce_arm_automation_string_variable_test.go | 47 +-------------- 12 files changed, 94 insertions(+), 279 deletions(-) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index 7ec0fcba9ee9..b04cce193135 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -53,6 +53,8 @@ func parseAzureRmAutomationVariableValue(resource string, input *string) (interf func AutomationVariableCommonSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema { varSchema := map[string]*schema.Schema{ + "resource_group_name": resourceGroupNameSchema(), + "name": { Type: schema.TypeString, Required: true, @@ -120,25 +122,16 @@ func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta inte value = strconv.Quote(d.Get("value").(string)) } - parameters := automation.VariableCreateOrUpdateParameters{} + parameters := automation.VariableCreateOrUpdateParameters{ + Name: utils.String(name), + VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ + Description: utils.String(description), + IsEncrypted: utils.Bool(encrypted), + }, + } - if varTypeLower == "null" { - parameters = automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - }, - } - } else { - parameters = automation.VariableCreateOrUpdateParameters{ - Name: utils.String(name), - VariableCreateOrUpdateProperties: &automation.VariableCreateOrUpdateProperties{ - Description: utils.String(description), - IsEncrypted: utils.Bool(encrypted), - Value: utils.String(value), - }, - } + if varTypeLower != "null" { + parameters.VariableCreateOrUpdateProperties.Value = utils.String(value) } if _, err := client.CreateOrUpdate(ctx, resourceGroup, accountName, name, parameters); err != nil { @@ -154,7 +147,7 @@ func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta inte } d.SetId(*resp.ID) - return nil + return resourceArmAutomationVariableRead(d, meta, varType) } func resourceArmAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error { diff --git a/azurerm/automation_variable_test.go b/azurerm/automation_variable_test.go index 2ad332039b23..ebf4618a213d 100644 --- a/azurerm/automation_variable_test.go +++ b/azurerm/automation_variable_test.go @@ -1,8 +1,14 @@ package azurerm import ( + "fmt" + "strings" "testing" "time" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestParseAzureRmAutomationVariableValue(t *testing.T) { @@ -81,3 +87,55 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }) } } + +func testCheckAzureRMAutomationVariableExists(resourceName string, varType string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Automation %s Variable not found: %s", varType, resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Automation %s Variable %q (Automation Account Name %q / Resource Group %q) does not exist", varType, name, accountName, resourceGroup) + } + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMAutomationVariableDestroy(s *terraform.State, varType string) error { + client := testAccProvider.Meta().(*ArmClient).automationVariableClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resourceName := fmt.Sprintf("azurerm_automation_%s_variable", strings.ToLower(varType)) + + for _, rs := range s.RootModule().Resources { + if rs.Type != resourceName { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + accountName := rs.Primary.Attributes["automation_account_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) + } + } + + return nil + } + + return nil +} diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go index 32f91d9b0260..7480ab944921 100644 --- a/azurerm/resource_arm_automation_bool_variable.go +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -16,8 +16,6 @@ func resourceArmAutomationBoolVariable() *schema.Resource { }, Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "resource_group_name": resourceGroupNameSchema(), - "value": { Type: schema.TypeBool, Optional: true, @@ -27,10 +25,7 @@ func resourceArmAutomationBoolVariable() *schema.Resource { } func resourceArmAutomationBoolVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Bool"); err != nil { - return err - } - return resourceArmAutomationBoolVariableRead(d, meta) + return resourceArmAutomationVariableCreateUpdate(d, meta, "Bool") } func resourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_automation_bool_variable_test.go b/azurerm/resource_arm_automation_bool_variable_test.go index ac4449a0741c..8eafd6b27bfd 100644 --- a/azurerm/resource_arm_automation_bool_variable_test.go +++ b/azurerm/resource_arm_automation_bool_variable_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { @@ -100,53 +99,11 @@ func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { } func testCheckAzureRMAutomationBoolVariableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Automation Bool Variable not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Automation Bool Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) - } - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - - return nil - } + return testCheckAzureRMAutomationVariableExists(resourceName, "Bool") } func testCheckAzureRMAutomationBoolVariableDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_automation_bool_variable" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - } - - return nil - } - - return nil + return testCheckAzureRMAutomationVariableDestroy(s, "Bool") } func testAccAzureRMAutomationBoolVariable_basic(rInt int, location string) string { diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go index 146e5e28ac6f..f967e5bfd7b9 100644 --- a/azurerm/resource_arm_automation_datetime_variable.go +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -2,6 +2,7 @@ package azurerm import ( "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func resourceArmAutomationDatetimeVariable() *schema.Resource { @@ -16,21 +17,17 @@ func resourceArmAutomationDatetimeVariable() *schema.Resource { }, Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "resource_group_name": resourceGroupNameSchema(), - "value": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.RFC3339Time, }, }), } } func resourceArmAutomationDatetimeVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Datetime"); err != nil { - return err - } - return resourceArmAutomationDatetimeVariableRead(d, meta) + return resourceArmAutomationVariableCreateUpdate(d, meta, "Datetime") } func resourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_automation_datetime_variable_test.go b/azurerm/resource_arm_automation_datetime_variable_test.go index db3c68f733cd..446012d56545 100644 --- a/azurerm/resource_arm_automation_datetime_variable_test.go +++ b/azurerm/resource_arm_automation_datetime_variable_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { @@ -100,53 +99,11 @@ func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) } func testCheckAzureRMAutomationDatetimeVariableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Automation Datetime Variable not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Automation Datetime Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) - } - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - - return nil - } + return testCheckAzureRMAutomationVariableExists(resourceName, "Datetime") } func testCheckAzureRMAutomationDatetimeVariableDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_automation_datetime_variable" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - } - - return nil - } - - return nil + return testCheckAzureRMAutomationVariableDestroy(s, "Datetime") } func testAccAzureRMAutomationDatetimeVariable_basic(rInt int, location string) string { diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go index e328ab4878bc..7ab70f551d31 100644 --- a/azurerm/resource_arm_automation_int_variable.go +++ b/azurerm/resource_arm_automation_int_variable.go @@ -16,8 +16,6 @@ func resourceArmAutomationIntVariable() *schema.Resource { }, Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "resource_group_name": resourceGroupNameSchema(), - "value": { Type: schema.TypeInt, Optional: true, @@ -27,10 +25,7 @@ func resourceArmAutomationIntVariable() *schema.Resource { } func resourceArmAutomationIntVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Int"); err != nil { - return err - } - return resourceArmAutomationIntVariableRead(d, meta) + return resourceArmAutomationVariableCreateUpdate(d, meta, "Int") } func resourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_automation_int_variable_test.go b/azurerm/resource_arm_automation_int_variable_test.go index 35467dbf85f8..41e9687d871e 100644 --- a/azurerm/resource_arm_automation_int_variable_test.go +++ b/azurerm/resource_arm_automation_int_variable_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { @@ -100,53 +99,11 @@ func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { } func testCheckAzureRMAutomationIntVariableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Automation Int Variable not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Automation Int Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) - } - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - - return nil - } + return testCheckAzureRMAutomationVariableExists(resourceName, "Int") } func testCheckAzureRMAutomationIntVariableDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_automation_int_variable" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - } - - return nil - } - - return nil + return testCheckAzureRMAutomationVariableDestroy(s, "Int") } func testAccAzureRMAutomationIntVariable_basic(rInt int, location string) string { diff --git a/azurerm/resource_arm_automation_null_variable.go b/azurerm/resource_arm_automation_null_variable.go index 50cfc366dce9..fc48f3a66d4e 100644 --- a/azurerm/resource_arm_automation_null_variable.go +++ b/azurerm/resource_arm_automation_null_variable.go @@ -15,17 +15,12 @@ func resourceArmAutomationNullVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "resource_group_name": resourceGroupNameSchema(), - }), + Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{}), } } func resourceArmAutomationNullVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := resourceArmAutomationVariableCreateUpdate(d, meta, "Null"); err != nil { - return err - } - return resourceArmAutomationNullVariableRead(d, meta) + return resourceArmAutomationVariableCreateUpdate(d, meta, "Null") } func resourceArmAutomationNullVariableRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_automation_null_variable_test.go b/azurerm/resource_arm_automation_null_variable_test.go index 42d6df75027a..30a5be241da7 100644 --- a/azurerm/resource_arm_automation_null_variable_test.go +++ b/azurerm/resource_arm_automation_null_variable_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAutomationNullVariable_basic(t *testing.T) { @@ -95,53 +94,11 @@ func TestAccAzureRMAutomationNullVariable_basicCompleteUpdate(t *testing.T) { } func testCheckAzureRMAutomationNullVariableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Automation Null Variable not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Automation Null Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) - } - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - - return nil - } + return testCheckAzureRMAutomationVariableExists(resourceName, "Null") } func testCheckAzureRMAutomationNullVariableDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_automation_null_variable" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - } - - return nil - } - - return nil + return testCheckAzureRMAutomationVariableDestroy(s, "Null") } func testAccAzureRMAutomationNullVariable_basic(rInt int, location string) string { diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index c5db9bc97a10..ca40453416e2 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -2,6 +2,7 @@ package azurerm import ( "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func resourceArmAutomationStringVariable() *schema.Resource { @@ -16,21 +17,17 @@ func resourceArmAutomationStringVariable() *schema.Resource { }, Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "resource_group_name": resourceGroupNameSchema(), - "value": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, }, }), } } func resourceArmAutomationStringVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - if err := resourceArmAutomationVariableCreateUpdate(d, meta, "String"); err != nil { - return err - } - return resourceArmAutomationStringVariableRead(d, meta) + return resourceArmAutomationVariableCreateUpdate(d, meta, "String") } func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_automation_string_variable_test.go b/azurerm/resource_arm_automation_string_variable_test.go index 9e96fb13cbff..72057cea2e2a 100644 --- a/azurerm/resource_arm_automation_string_variable_test.go +++ b/azurerm/resource_arm_automation_string_variable_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { @@ -100,53 +99,11 @@ func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { } func testCheckAzureRMAutomationStringVariableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Automation String Variable not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Automation String Variable %q (Automation Account Name %q / Resource Group %q) does not exist", name, accountName, resourceGroup) - } - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - - return nil - } + return testCheckAzureRMAutomationVariableExists(resourceName, "String") } func testCheckAzureRMAutomationStringVariableDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*ArmClient).automationVariableClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_automation_string_variable" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - accountName := rs.Primary.Attributes["automation_account_name"] - - if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on automationVariableClient: %+v", err) - } - } - - return nil - } - - return nil + return testCheckAzureRMAutomationVariableDestroy(s, "String") } func testAccAzureRMAutomationStringVariable_basic(rInt int, location string) string { From 223ef2a59f4d574fee199beb37b424e820e44042 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Tue, 7 May 2019 12:56:56 -0700 Subject: [PATCH 16/29] Changes requested in PR --- azurerm/automation_variable.go | 11 +- azurerm/provider.go | 1 - .../resource_arm_automation_bool_variable.go | 7 +- ...source_arm_automation_datetime_variable.go | 8 +- .../resource_arm_automation_int_variable.go | 7 +- .../resource_arm_automation_null_variable.go | 32 ---- ...ource_arm_automation_null_variable_test.go | 153 ------------------ ...resource_arm_automation_string_variable.go | 8 +- website/azurerm.erb | 4 - .../r/automation_null_variable.html.markdown | 64 -------- 10 files changed, 12 insertions(+), 283 deletions(-) delete mode 100644 azurerm/resource_arm_automation_null_variable.go delete mode 100644 azurerm/resource_arm_automation_null_variable_test.go delete mode 100644 website/docs/r/automation_null_variable.html.markdown diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index b04cce193135..9e8670cd69bc 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -10,7 +10,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform/helper/schema" - "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/utils" @@ -50,7 +49,7 @@ func parseAzureRmAutomationVariableValue(resource string, input *string) (interf return value, nil } -func AutomationVariableCommonSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema { +func AutomationVariableCommonSchemaFrom(attType schema.ValueType, validateFunc schema.SchemaValidateFunc) map[string]*schema.Schema { varSchema := map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), @@ -79,8 +78,14 @@ func AutomationVariableCommonSchemaFrom(s map[string]*schema.Schema) map[string] Optional: true, Default: false, }, + + "value": { + Type: attType, + Optional: true, + ValidateFunc: validateFunc, + }, } - return azure.MergeSchema(s, varSchema) + return varSchema } func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error { diff --git a/azurerm/provider.go b/azurerm/provider.go index 9b84a153e3e8..fea5e72bc77b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -182,7 +182,6 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_bool_variable": resourceArmAutomationBoolVariable(), "azurerm_automation_datetime_variable": resourceArmAutomationDatetimeVariable(), "azurerm_automation_int_variable": resourceArmAutomationIntVariable(), - "azurerm_automation_null_variable": resourceArmAutomationNullVariable(), "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_availability_set": resourceArmAvailabilitySet(), diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go index 7480ab944921..490ca608b421 100644 --- a/azurerm/resource_arm_automation_bool_variable.go +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -15,12 +15,7 @@ func resourceArmAutomationBoolVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "value": { - Type: schema.TypeBool, - Optional: true, - }, - }), + Schema: AutomationVariableCommonSchemaFrom(schema.TypeBool, nil), } } diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go index f967e5bfd7b9..79fe98c60d19 100644 --- a/azurerm/resource_arm_automation_datetime_variable.go +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -16,13 +16,7 @@ func resourceArmAutomationDatetimeVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.RFC3339Time, - }, - }), + Schema: AutomationVariableCommonSchemaFrom(schema.TypeString, validate.RFC3339Time), } } diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go index 7ab70f551d31..b67fceb5556b 100644 --- a/azurerm/resource_arm_automation_int_variable.go +++ b/azurerm/resource_arm_automation_int_variable.go @@ -15,12 +15,7 @@ func resourceArmAutomationIntVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "value": { - Type: schema.TypeInt, - Optional: true, - }, - }), + Schema: AutomationVariableCommonSchemaFrom(schema.TypeInt, nil), } } diff --git a/azurerm/resource_arm_automation_null_variable.go b/azurerm/resource_arm_automation_null_variable.go deleted file mode 100644 index fc48f3a66d4e..000000000000 --- a/azurerm/resource_arm_automation_null_variable.go +++ /dev/null @@ -1,32 +0,0 @@ -package azurerm - -import ( - "github.com/hashicorp/terraform/helper/schema" -) - -func resourceArmAutomationNullVariable() *schema.Resource { - return &schema.Resource{ - Create: resourceArmAutomationNullVariableCreateUpdate, - Read: resourceArmAutomationNullVariableRead, - Update: resourceArmAutomationNullVariableCreateUpdate, - Delete: resourceArmAutomationNullVariableDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{}), - } -} - -func resourceArmAutomationNullVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableCreateUpdate(d, meta, "Null") -} - -func resourceArmAutomationNullVariableRead(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableRead(d, meta, "Null") -} - -func resourceArmAutomationNullVariableDelete(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableDelete(d, meta, "Null") -} diff --git a/azurerm/resource_arm_automation_null_variable_test.go b/azurerm/resource_arm_automation_null_variable_test.go deleted file mode 100644 index 30a5be241da7..000000000000 --- a/azurerm/resource_arm_automation_null_variable_test.go +++ /dev/null @@ -1,153 +0,0 @@ -package azurerm - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" -) - -func TestAccAzureRMAutomationNullVariable_basic(t *testing.T) { - resourceName := "azurerm_automation_null_variable.test" - ri := tf.AccRandTimeInt() - location := testLocation() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutomationNullVariable_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationNullVariableExists(resourceName), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMAutomationNullVariable_complete(t *testing.T) { - resourceName := "azurerm_automation_null_variable.test" - ri := tf.AccRandTimeInt() - location := testLocation() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutomationNullVariable_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationNullVariableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMAutomationNullVariable_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_null_variable.test" - ri := tf.AccRandTimeInt() - location := testLocation() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationNullVariableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutomationNullVariable_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationNullVariableExists(resourceName), - ), - }, - { - Config: testAccAzureRMAutomationNullVariable_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationNullVariableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - ), - }, - { - Config: testAccAzureRMAutomationNullVariable_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationNullVariableExists(resourceName), - ), - }, - }, - }) -} - -func testCheckAzureRMAutomationNullVariableExists(resourceName string) resource.TestCheckFunc { - return testCheckAzureRMAutomationVariableExists(resourceName, "Null") -} - -func testCheckAzureRMAutomationNullVariableDestroy(s *terraform.State) error { - return testCheckAzureRMAutomationVariableDestroy(s, "Null") -} - -func testAccAzureRMAutomationNullVariable_basic(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_automation_account" "test" { - name = "acctestAutoAcct-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku = { - name = "Basic" - } -} - -resource "azurerm_automation_null_variable" "test" { - name = "acctestAutoVar-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" -} -`, rInt, location, rInt, rInt) -} - -func testAccAzureRMAutomationNullVariable_complete(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_automation_account" "test" { - name = "acctestAutoAcct-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku = { - name = "Basic" - } -} - -resource "azurerm_automation_null_variable" "test" { - name = "acctestAutoVar-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" - description = "This variable is created by Terraform acceptance test." -} -`, rInt, location, rInt, rInt) -} diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index ca40453416e2..1f508736b467 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -16,13 +16,7 @@ func resourceArmAutomationStringVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.NoEmptyStrings, - }, - }), + Schema: AutomationVariableCommonSchemaFrom(schema.TypeString, validate.NoEmptyStrings), } } diff --git a/website/azurerm.erb b/website/azurerm.erb index 6db9dfe3d710..91a2c9437dab 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -422,10 +422,6 @@ azurerm_automation_bool_variable - > - azurerm_automation_null_variable - - > azurerm_automation_string_variable diff --git a/website/docs/r/automation_null_variable.html.markdown b/website/docs/r/automation_null_variable.html.markdown deleted file mode 100644 index f1aff89cf3b1..000000000000 --- a/website/docs/r/automation_null_variable.html.markdown +++ /dev/null @@ -1,64 +0,0 @@ ---- -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_null_variable" -sidebar_current: "docs-azurerm-resource-automation-null-variable" -description: |- - Manages a null variable in Azure Automation ---- - -# azurerm_automation_null_variable - -Manages a null variable in Azure Automation - - -## Example Usage - -```hcl -resource "azurerm_resource_group" "example" { - name = "tfex-example-rg" - location = "West US" -} - -resource "azurerm_automation_account" "example" { - name = "tfex-example-account" - location = "${azurerm_resource_group.example.location}" - resource_group_name = "${azurerm_resource_group.example.name}" - - sku_name = "Basic" -} - -resource "azurerm_automation_null_variable" "example" { - name = "tfex-example-var" - resource_group_name = "${azurerm_resource_group.example.name}" - automation_account_name = "${azurerm_automation_account.example.name}" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) The name of the Automation Variable. Changing this forces a new resource to be created. - -* `resource_group_name` - (Required) The name of the resource group in which to create the Automation Variable. Changing this forces a new resource to be created. - -* `automation_account_name` - (Required) The name of the automation account in which the Variable is created. Changing this forces a new resource to be created. - -* `description` - (Optional) The description of the Automation Variable. - -* `encrypted` - (Optional) Specifies if the Automation Variable is encrypted. Defaults to `false`. - -## Attributes Reference - -The following attributes are exported: - -* `id` - The ID of the Automation Variable. - - -## Import - -Automation Null Variable can be imported using the `resource id`, e.g. - -```shell -$ terraform import azurerm_automation_null_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var -``` From f8fd819f46b63d71c8cb84ffa8b800be20bc6994 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 8 May 2019 12:44:07 -0700 Subject: [PATCH 17/29] Fix test cases --- azurerm/resource_arm_automation_bool_variable_test.go | 4 ++-- azurerm/resource_arm_automation_datetime_variable_test.go | 4 ++-- azurerm/resource_arm_automation_int_variable_test.go | 4 ++-- azurerm/resource_arm_automation_string_variable_test.go | 4 ++-- website/docs/r/automation_bool_variable.html.markdown | 4 +++- website/docs/r/automation_datetime_variable.html.markdown | 4 +++- website/docs/r/automation_int_variable.html.markdown | 4 +++- website/docs/r/automation_string_variable.html.markdown | 4 +++- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/azurerm/resource_arm_automation_bool_variable_test.go b/azurerm/resource_arm_automation_bool_variable_test.go index 8eafd6b27bfd..25e9f80cad0b 100644 --- a/azurerm/resource_arm_automation_bool_variable_test.go +++ b/azurerm/resource_arm_automation_bool_variable_test.go @@ -118,7 +118,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } @@ -144,7 +144,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } diff --git a/azurerm/resource_arm_automation_datetime_variable_test.go b/azurerm/resource_arm_automation_datetime_variable_test.go index 446012d56545..46c5ca0b3cc0 100644 --- a/azurerm/resource_arm_automation_datetime_variable_test.go +++ b/azurerm/resource_arm_automation_datetime_variable_test.go @@ -118,7 +118,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } @@ -144,7 +144,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } diff --git a/azurerm/resource_arm_automation_int_variable_test.go b/azurerm/resource_arm_automation_int_variable_test.go index 41e9687d871e..f55c37457136 100644 --- a/azurerm/resource_arm_automation_int_variable_test.go +++ b/azurerm/resource_arm_automation_int_variable_test.go @@ -118,7 +118,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } @@ -144,7 +144,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } diff --git a/azurerm/resource_arm_automation_string_variable_test.go b/azurerm/resource_arm_automation_string_variable_test.go index 72057cea2e2a..3416612e88ef 100644 --- a/azurerm/resource_arm_automation_string_variable_test.go +++ b/azurerm/resource_arm_automation_string_variable_test.go @@ -118,7 +118,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } @@ -144,7 +144,7 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = { + sku { name = "Basic" } } diff --git a/website/docs/r/automation_bool_variable.html.markdown b/website/docs/r/automation_bool_variable.html.markdown index 7c8c78131885..9314fba0b158 100644 --- a/website/docs/r/automation_bool_variable.html.markdown +++ b/website/docs/r/automation_bool_variable.html.markdown @@ -24,7 +24,9 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku_name = "Basic" + sku { + name = "Basic" + } } resource "azurerm_automation_bool_variable" "example" { diff --git a/website/docs/r/automation_datetime_variable.html.markdown b/website/docs/r/automation_datetime_variable.html.markdown index 4ace656a44bf..d106aad8e735 100644 --- a/website/docs/r/automation_datetime_variable.html.markdown +++ b/website/docs/r/automation_datetime_variable.html.markdown @@ -24,7 +24,9 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku_name = "Basic" + sku { + name = "Basic" + } } resource "azurerm_automation_datetime_variable" "example" { diff --git a/website/docs/r/automation_int_variable.html.markdown b/website/docs/r/automation_int_variable.html.markdown index 6f2a505ac00c..8f4bfd0c4fe9 100644 --- a/website/docs/r/automation_int_variable.html.markdown +++ b/website/docs/r/automation_int_variable.html.markdown @@ -24,7 +24,9 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku_name = "Basic" + sku { + name = "Basic" + } } resource "azurerm_automation_int_variable" "example" { diff --git a/website/docs/r/automation_string_variable.html.markdown b/website/docs/r/automation_string_variable.html.markdown index 9a114d0642d3..a59908171147 100644 --- a/website/docs/r/automation_string_variable.html.markdown +++ b/website/docs/r/automation_string_variable.html.markdown @@ -24,7 +24,9 @@ resource "azurerm_automation_account" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku_name = "Basic" + sku { + name = "Basic" + } } resource "azurerm_automation_string_variable" "example" { From 4a61e045f4c86366a2b822b499670c053a1143c2 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 8 May 2019 18:36:10 -0700 Subject: [PATCH 18/29] Add support for data sources --- azurerm/automation_variable.go | 94 +++++++++++++++++-- azurerm/automation_variable_test.go | 17 +--- .../data_source_automation_bool_variable.go | 17 ++++ ...ta_source_automation_bool_variable_test.go | 41 ++++++++ ...ata_source_automation_datetime_variable.go | 17 ++++ ...ource_automation_datetime_variable_test.go | 41 ++++++++ .../data_source_automation_int_variable.go | 17 ++++ ...ata_source_automation_int_variable_test.go | 41 ++++++++ .../data_source_automation_string_variable.go | 17 ++++ ..._source_automation_string_variable_test.go | 41 ++++++++ azurerm/provider.go | 4 + .../resource_arm_automation_bool_variable.go | 8 +- ...source_arm_automation_datetime_variable.go | 8 +- .../resource_arm_automation_int_variable.go | 8 +- ...resource_arm_automation_string_variable.go | 8 +- website/azurerm.erb | 16 ++++ .../d/automation_bool_variable.html.markdown | 50 ++++++++++ ...automation_datetime_variable.html.markdown | 50 ++++++++++ .../d/automation_int_variable.html.markdown | 50 ++++++++++ .../automation_string_variable.html.markdown | 50 ++++++++++ 20 files changed, 559 insertions(+), 36 deletions(-) create mode 100644 azurerm/data_source_automation_bool_variable.go create mode 100644 azurerm/data_source_automation_bool_variable_test.go create mode 100644 azurerm/data_source_automation_datetime_variable.go create mode 100644 azurerm/data_source_automation_datetime_variable_test.go create mode 100644 azurerm/data_source_automation_int_variable.go create mode 100644 azurerm/data_source_automation_int_variable_test.go create mode 100644 azurerm/data_source_automation_string_variable.go create mode 100644 azurerm/data_source_automation_string_variable_test.go create mode 100644 website/docs/d/automation_bool_variable.html.markdown create mode 100644 website/docs/d/automation_datetime_variable.html.markdown create mode 100644 website/docs/d/automation_int_variable.html.markdown create mode 100644 website/docs/d/automation_string_variable.html.markdown diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index 9e8670cd69bc..b64852d4d425 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -15,7 +15,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func parseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { +func parseAzureAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource) @@ -49,7 +49,7 @@ func parseAzureRmAutomationVariableValue(resource string, input *string) (interf return value, nil } -func AutomationVariableCommonSchemaFrom(attType schema.ValueType, validateFunc schema.SchemaValidateFunc) map[string]*schema.Schema { +func resourceAutomationVariableCommonSchema(attType schema.ValueType, validateFunc schema.SchemaValidateFunc) map[string]*schema.Schema { varSchema := map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), @@ -88,7 +88,42 @@ func AutomationVariableCommonSchemaFrom(attType schema.ValueType, validateFunc s return varSchema } -func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error { +func datasourceAutomationVariableCommonSchema(attType schema.ValueType) map[string]*schema.Schema { + + varSchema := map[string]*schema.Schema{ + "resource_group_name": resourceGroupNameSchema(), + + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "automation_account_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + + "encrypted": { + Type: schema.TypeBool, + Computed: true, + }, + + "value": { + Type: attType, + Computed: true, + }, + } + return varSchema +} + +func resourceAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error { client := meta.(*ArmClient).automationVariableClient ctx := meta.(*ArmClient).StopContext @@ -104,6 +139,7 @@ func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta inte return fmt.Errorf("Error checking for present of existing Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) } } + if !utils.ResponseWasNotFound(resp.Response) { return tf.ImportAsExistsError(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), *resp.ID) } @@ -152,10 +188,10 @@ func resourceArmAutomationVariableCreateUpdate(d *schema.ResourceData, meta inte } d.SetId(*resp.ID) - return resourceArmAutomationVariableRead(d, meta, varType) + return resourceAutomationVariableRead(d, meta, varType) } -func resourceArmAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error { +func resourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error { client := meta.(*ArmClient).automationVariableClient ctx := meta.(*ArmClient).StopContext @@ -186,7 +222,51 @@ func resourceArmAutomationVariableRead(d *schema.ResourceData, meta interface{}, d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) if !d.Get("encrypted").(bool) { - value, err := parseAzureRmAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) + value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) + if err != nil { + return err + } + + if varTypeLower == "datetime" { + d.Set("value", value.(time.Time).Format("2006-01-02T15:04:05.999Z")) + } else if varTypeLower != "null" { + d.Set("value", value) + } + } + } + + return nil +} + +func datasourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error { + client := meta.(*ArmClient).automationVariableClient + ctx := meta.(*ArmClient).StopContext + + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("automation_account_name").(string) + name := d.Get("name").(string) + varTypeLower := strings.ToLower(varType) + + resp, err := client.Get(ctx, resourceGroup, accountName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Automation %s Variable %q does not exist - removing from state", varType, d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Automation %s Variable %q (Automation Account Name %q / Resource Group %q): %+v", varType, name, accountName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("automation_account_name", accountName) + if properties := resp.VariableProperties; properties != nil { + d.Set("description", properties.Description) + d.Set("encrypted", properties.IsEncrypted) + if !d.Get("encrypted").(bool) { + value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) if err != nil { return err } @@ -202,7 +282,7 @@ func resourceArmAutomationVariableRead(d *schema.ResourceData, meta interface{}, return nil } -func resourceArmAutomationVariableDelete(d *schema.ResourceData, meta interface{}, varType string) error { +func resourceAutomationVariableDelete(d *schema.ResourceData, meta interface{}, varType string) error { client := meta.(*ArmClient).automationVariableClient ctx := meta.(*ArmClient).StopContext diff --git a/azurerm/automation_variable_test.go b/azurerm/automation_variable_test.go index ebf4618a213d..1ef8541a9679 100644 --- a/azurerm/automation_variable_test.go +++ b/azurerm/automation_variable_test.go @@ -22,15 +22,6 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { ExpectValue interface{} Expect ExpectFunc }{ - { - Name: "null variable", - Resource: "azurerm_automation_null_variable", - IsNil: true, - Value: "", - HasError: false, - ExpectValue: nil, - Expect: func(v interface{}) bool { return v == nil }, - }, { Name: "string variable", Resource: "azurerm_automation_string_variable", @@ -73,15 +64,15 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { if tc.IsNil { value = nil } - actual, err := parseAzureRmAutomationVariableValue(tc.Resource, value) + actual, err := parseAzureAutomationVariableValue(tc.Resource, value) if tc.HasError && err == nil { - t.Fatalf("Expect parseAzureRmAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) + t.Fatalf("Expect parseAzureAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) } if !tc.HasError { if err != nil { - t.Fatalf("Expect parseAzureRmAutomationVariableValue to return no error for resource %q and value %s, err: %+v", tc.Resource, tc.Value, err) + t.Fatalf("Expect parseAzureAutomationVariableValue to return no error for resource %q and value %s, err: %+v", tc.Resource, tc.Value, err) } else if !tc.Expect(actual) { - t.Fatalf("Expect parseAzureRmAutomationVariableValue to return %v instead of %v for resource %q and value %s", tc.ExpectValue, actual, tc.Resource, tc.Value) + t.Fatalf("Expect parseAzureAutomationVariableValue to return %v instead of %v for resource %q and value %s", tc.ExpectValue, actual, tc.Resource, tc.Value) } } }) diff --git a/azurerm/data_source_automation_bool_variable.go b/azurerm/data_source_automation_bool_variable.go new file mode 100644 index 000000000000..fb3c6a977dc4 --- /dev/null +++ b/azurerm/data_source_automation_bool_variable.go @@ -0,0 +1,17 @@ +package azurerm + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +func dataSourceArmAutomationBoolVariable() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmAutomationBoolVariableRead, + + Schema: datasourceAutomationVariableCommonSchema(schema.TypeBool), + } +} + +func dataSourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { + return datasourceAutomationVariableRead(d, meta, "Bool") +} diff --git a/azurerm/data_source_automation_bool_variable_test.go b/azurerm/data_source_automation_bool_variable_test.go new file mode 100644 index 000000000000..39c0eb1a4030 --- /dev/null +++ b/azurerm/data_source_automation_bool_variable_test.go @@ -0,0 +1,41 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAzureRMAutomationBoolVariable_basic(t *testing.T) { + dataSourceName := "data.azurerm_automation_bool_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAutomationBoolVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "value", "false"), + ), + }, + }, + }) +} + +func testAccDataSourceAutomationBoolVariable_basic(rInt int, location string) string { + config := testAccAzureRMAutomationBoolVariable_basic(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_automation_bool_variable" "test" { + name = "${azurerm_automation_bool_variable.test.name}" + resource_group_name = "${azurerm_automation_bool_variable.test.resource_group_name}" + automation_account_name = "${azurerm_automation_bool_variable.test.automation_account_name}" +} +`, config) +} diff --git a/azurerm/data_source_automation_datetime_variable.go b/azurerm/data_source_automation_datetime_variable.go new file mode 100644 index 000000000000..8c0a4b5d06c9 --- /dev/null +++ b/azurerm/data_source_automation_datetime_variable.go @@ -0,0 +1,17 @@ +package azurerm + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +func dataSourceArmAutomationDatetimeVariable() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmAutomationDatetimeVariableRead, + + Schema: datasourceAutomationVariableCommonSchema(schema.TypeString), + } +} + +func dataSourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { + return datasourceAutomationVariableRead(d, meta, "Datetime") +} diff --git a/azurerm/data_source_automation_datetime_variable_test.go b/azurerm/data_source_automation_datetime_variable_test.go new file mode 100644 index 000000000000..61ab82bb84a5 --- /dev/null +++ b/azurerm/data_source_automation_datetime_variable_test.go @@ -0,0 +1,41 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAzureRMAutomationDatetimeVariable_basic(t *testing.T) { + dataSourceName := "data.azurerm_automation_datetime_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAutomationDatetimeVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "value", "2019-04-24T21:40:54.074Z"), + ), + }, + }, + }) +} + +func testAccDataSourceAutomationDatetimeVariable_basic(rInt int, location string) string { + config := testAccAzureRMAutomationDatetimeVariable_basic(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_automation_datetime_variable" "test" { + name = "${azurerm_automation_datetime_variable.test.name}" + resource_group_name = "${azurerm_automation_datetime_variable.test.resource_group_name}" + automation_account_name = "${azurerm_automation_datetime_variable.test.automation_account_name}" +} +`, config) +} diff --git a/azurerm/data_source_automation_int_variable.go b/azurerm/data_source_automation_int_variable.go new file mode 100644 index 000000000000..d546b4f4734d --- /dev/null +++ b/azurerm/data_source_automation_int_variable.go @@ -0,0 +1,17 @@ +package azurerm + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +func dataSourceArmAutomationIntVariable() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmAutomationIntVariableRead, + + Schema: datasourceAutomationVariableCommonSchema(schema.TypeInt), + } +} + +func dataSourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { + return datasourceAutomationVariableRead(d, meta, "Int") +} diff --git a/azurerm/data_source_automation_int_variable_test.go b/azurerm/data_source_automation_int_variable_test.go new file mode 100644 index 000000000000..396c184583a2 --- /dev/null +++ b/azurerm/data_source_automation_int_variable_test.go @@ -0,0 +1,41 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAzureRMAutomationIntVariable_basic(t *testing.T) { + dataSourceName := "data.azurerm_automation_int_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAutomationIntVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "value", "1234"), + ), + }, + }, + }) +} + +func testAccDataSourceAutomationIntVariable_basic(rInt int, location string) string { + config := testAccAzureRMAutomationIntVariable_basic(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_automation_int_variable" "test" { + name = "${azurerm_automation_int_variable.test.name}" + resource_group_name = "${azurerm_automation_int_variable.test.resource_group_name}" + automation_account_name = "${azurerm_automation_int_variable.test.automation_account_name}" +} +`, config) +} diff --git a/azurerm/data_source_automation_string_variable.go b/azurerm/data_source_automation_string_variable.go new file mode 100644 index 000000000000..8b83b3dc3262 --- /dev/null +++ b/azurerm/data_source_automation_string_variable.go @@ -0,0 +1,17 @@ +package azurerm + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +func dataSourceArmAutomationStringVariable() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmAutomationStringVariableRead, + + Schema: datasourceAutomationVariableCommonSchema(schema.TypeString), + } +} + +func dataSourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { + return datasourceAutomationVariableRead(d, meta, "String") +} diff --git a/azurerm/data_source_automation_string_variable_test.go b/azurerm/data_source_automation_string_variable_test.go new file mode 100644 index 000000000000..73db1db0077f --- /dev/null +++ b/azurerm/data_source_automation_string_variable_test.go @@ -0,0 +1,41 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAzureRMAutomationStringVariable_basic(t *testing.T) { + dataSourceName := "data.azurerm_automation_string_variable.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAutomationStringVariable_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "value", "Hello, Terraform Basic Test."), + ), + }, + }, + }) +} + +func testAccDataSourceAutomationStringVariable_basic(rInt int, location string) string { + config := testAccAzureRMAutomationStringVariable_basic(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_automation_string_variable" "test" { + name = "${azurerm_automation_string_variable.test.name}" + resource_group_name = "${azurerm_automation_string_variable.test.resource_group_name}" + automation_account_name = "${azurerm_automation_string_variable.test.automation_account_name}" +} +`, config) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index fea5e72bc77b..c45bdd2265e2 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -103,6 +103,10 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_application_insights": dataSourceArmApplicationInsights(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_automation_bool_variable": dataSourceArmAutomationBoolVariable(), + "azurerm_automation_datetime_variable": dataSourceArmAutomationDatetimeVariable(), + "azurerm_automation_int_variable": dataSourceArmAutomationIntVariable(), + "azurerm_automation_string_variable": dataSourceArmAutomationStringVariable(), "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go index 490ca608b421..ba4c37b4747b 100644 --- a/azurerm/resource_arm_automation_bool_variable.go +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -15,18 +15,18 @@ func resourceArmAutomationBoolVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(schema.TypeBool, nil), + Schema: resourceAutomationVariableCommonSchema(schema.TypeBool, nil), } } func resourceArmAutomationBoolVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableCreateUpdate(d, meta, "Bool") + return resourceAutomationVariableCreateUpdate(d, meta, "Bool") } func resourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableRead(d, meta, "Bool") + return resourceAutomationVariableRead(d, meta, "Bool") } func resourceArmAutomationBoolVariableDelete(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableDelete(d, meta, "Bool") + return resourceAutomationVariableDelete(d, meta, "Bool") } diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go index 79fe98c60d19..7645a5e90a68 100644 --- a/azurerm/resource_arm_automation_datetime_variable.go +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -16,18 +16,18 @@ func resourceArmAutomationDatetimeVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(schema.TypeString, validate.RFC3339Time), + Schema: resourceAutomationVariableCommonSchema(schema.TypeString, validate.RFC3339Time), } } func resourceArmAutomationDatetimeVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableCreateUpdate(d, meta, "Datetime") + return resourceAutomationVariableCreateUpdate(d, meta, "Datetime") } func resourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableRead(d, meta, "Datetime") + return resourceAutomationVariableRead(d, meta, "Datetime") } func resourceArmAutomationDatetimeVariableDelete(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableDelete(d, meta, "Datetime") + return resourceAutomationVariableDelete(d, meta, "Datetime") } diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go index b67fceb5556b..6842c447a586 100644 --- a/azurerm/resource_arm_automation_int_variable.go +++ b/azurerm/resource_arm_automation_int_variable.go @@ -15,18 +15,18 @@ func resourceArmAutomationIntVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(schema.TypeInt, nil), + Schema: resourceAutomationVariableCommonSchema(schema.TypeInt, nil), } } func resourceArmAutomationIntVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableCreateUpdate(d, meta, "Int") + return resourceAutomationVariableCreateUpdate(d, meta, "Int") } func resourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableRead(d, meta, "Int") + return resourceAutomationVariableRead(d, meta, "Int") } func resourceArmAutomationIntVariableDelete(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableDelete(d, meta, "Int") + return resourceAutomationVariableDelete(d, meta, "Int") } diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index 1f508736b467..486d827a62a0 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -16,18 +16,18 @@ func resourceArmAutomationStringVariable() *schema.Resource { State: schema.ImportStatePassthrough, }, - Schema: AutomationVariableCommonSchemaFrom(schema.TypeString, validate.NoEmptyStrings), + Schema: resourceAutomationVariableCommonSchema(schema.TypeString, validate.NoEmptyStrings), } } func resourceArmAutomationStringVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableCreateUpdate(d, meta, "String") + return resourceAutomationVariableCreateUpdate(d, meta, "String") } func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableRead(d, meta, "String") + return resourceAutomationVariableRead(d, meta, "String") } func resourceArmAutomationStringVariableDelete(d *schema.ResourceData, meta interface{}) error { - return resourceArmAutomationVariableDelete(d, meta, "String") + return resourceAutomationVariableDelete(d, meta, "String") } diff --git a/website/azurerm.erb b/website/azurerm.erb index 91a2c9437dab..5eec45ac86c4 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -79,6 +79,22 @@ azurerm_application_insights + > + azurerm_automation_bool_variable + + + > + azurerm_automation_datetime_variable + + + > + azurerm_automation_int_variable + + + > + azurerm_automation_string_variable + + > azurerm_availability_set diff --git a/website/docs/d/automation_bool_variable.html.markdown b/website/docs/d/automation_bool_variable.html.markdown new file mode 100644 index 000000000000..e35065d32364 --- /dev/null +++ b/website/docs/d/automation_bool_variable.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_bool_variable" +sidebar_current: "docs-azurerm-datasource-automation-bool-variable" +description: |- + Gets information about an existing Automation Bool Variable +--- + +# Data Source: azurerm_automation_bool_variable + +Use this data source to access information about an existing Automation Bool Variable. + + +## Example Usage + +```hcl +data "azurerm_automation_bool_variable" "example" { + name = "tfex-example-var" + resource_group_name = "tfex-example-rg" + automation_account_name = "tfex-example-account" +} + +output "variable_id" { + value = "${data.azurerm_automation_bool_variable.example.id}" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. + +* `resource_group_name` - (Required) The Name of the Resource Group where the automation account exists. + +* `automation_account_name` - (Required) The name of the automation account in which the Automation Variable exists. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + +* `description` - The description of the Automation Variable. + +* `encrypted` - Specifies if the Automation Variable is encrypted. Defaults to `false`. + +* `value` - The value of the Automation Variable as a `boolean`. diff --git a/website/docs/d/automation_datetime_variable.html.markdown b/website/docs/d/automation_datetime_variable.html.markdown new file mode 100644 index 000000000000..136d64e3c428 --- /dev/null +++ b/website/docs/d/automation_datetime_variable.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_datetime_variable" +sidebar_current: "docs-azurerm-datasource-automation-datetime-variable" +description: |- + Gets information about an existing Automation Datetime Variable +--- + +# Data Source: azurerm_automation_datetime_variable + +Use this data source to access information about an existing Automation Datetime Variable. + + +## Example Usage + +```hcl +data "azurerm_automation_datetime_variable" "example" { + name = "tfex-example-var" + resource_group_name = "tfex-example-rg" + automation_account_name = "tfex-example-account" +} + +output "variable_id" { + value = "${data.azurerm_automation_datetime_variable.example.id}" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. + +* `resource_group_name` - (Required) The Name of the Resource Group where the automation account exists. + +* `automation_account_name` - (Required) The name of the automation account in which the Automation Variable exists. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + +* `description` - The description of the Automation Variable. + +* `encrypted` - Specifies if the Automation Variable is encrypted. Defaults to `false`. + +* `value` - The value of the Automation Variable in the [RFC3339 Section 5.6 Internet Date/Time Format](https://tools.ietf.org/html/rfc3339#section-5.6). diff --git a/website/docs/d/automation_int_variable.html.markdown b/website/docs/d/automation_int_variable.html.markdown new file mode 100644 index 000000000000..f9bb70d10b96 --- /dev/null +++ b/website/docs/d/automation_int_variable.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_int_variable" +sidebar_current: "docs-azurerm-datasource-automation-int-variable" +description: |- + Gets information about an existing Automation Int Variable +--- + +# Data Source: azurerm_automation_int_variable + +Use this data source to access information about an existing Automation Int Variable. + + +## Example Usage + +```hcl +data "azurerm_automation_int_variable" "example" { + name = "tfex-example-var" + resource_group_name = "tfex-example-rg" + automation_account_name = "tfex-example-account" +} + +output "variable_id" { + value = "${data.azurerm_automation_int_variable.example.id}" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. + +* `resource_group_name` - (Required) The Name of the Resource Group where the automation account exists. + +* `automation_account_name` - (Required) The name of the automation account in which the Automation Variable exists. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + +* `description` - The description of the Automation Variable. + +* `encrypted` - Specifies if the Automation Variable is encrypted. Defaults to `false`. + +* `value` - The value of the Automation Variable as a `integer`. diff --git a/website/docs/d/automation_string_variable.html.markdown b/website/docs/d/automation_string_variable.html.markdown new file mode 100644 index 000000000000..d83ee63e71f1 --- /dev/null +++ b/website/docs/d/automation_string_variable.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automation_string_variable" +sidebar_current: "docs-azurerm-datasource-automation-string-variable" +description: |- + Gets information about an existing Automation String Variable +--- + +# Data Source: azurerm_automation_string_variable + +Use this data source to access information about an existing Automation String Variable. + + +## Example Usage + +```hcl +data "azurerm_automation_string_variable" "example" { + name = "tfex-example-var" + resource_group_name = "tfex-example-rg" + automation_account_name = "tfex-example-account" +} + +output "variable_id" { + value = "${data.azurerm_automation_string_variable.example.id}" +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Automation Variable. + +* `resource_group_name` - (Required) The Name of the Resource Group where the automation account exists. + +* `automation_account_name` - (Required) The name of the automation account in which the Automation Variable exists. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Automation Variable. + +* `description` - The description of the Automation Variable. + +* `encrypted` - Specifies if the Automation Variable is encrypted. Defaults to `false`. + +* `value` - The value of the Automation Variable as a `string`. From 8980a5ca7b33df90c7eb0952c5f0740fa854f8d9 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 8 May 2019 18:42:00 -0700 Subject: [PATCH 19/29] Resolve conficts --- azurerm/provider.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azurerm/provider.go b/azurerm/provider.go index bd8502e06007..daee989a7eb4 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -107,6 +107,10 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_application_insights": dataSourceArmApplicationInsights(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_automation_bool_variable": dataSourceArmAutomationBoolVariable(), + "azurerm_automation_datetime_variable": dataSourceArmAutomationDatetimeVariable(), + "azurerm_automation_int_variable": dataSourceArmAutomationIntVariable(), + "azurerm_automation_string_variable": dataSourceArmAutomationStringVariable(), "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), From aac306e359673bd7206752c2db63df221eaf11f8 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 14:09:11 -0700 Subject: [PATCH 20/29] addressed minor PR comment --- azurerm/automation_variable.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index b64852d4d425..3b518783c30a 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -50,8 +50,7 @@ func parseAzureAutomationVariableValue(resource string, input *string) (interfac } func resourceAutomationVariableCommonSchema(attType schema.ValueType, validateFunc schema.SchemaValidateFunc) map[string]*schema.Schema { - - varSchema := map[string]*schema.Schema{ + return map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), "name": { @@ -85,12 +84,10 @@ func resourceAutomationVariableCommonSchema(attType schema.ValueType, validateFu ValidateFunc: validateFunc, }, } - return varSchema } func datasourceAutomationVariableCommonSchema(attType schema.ValueType) map[string]*schema.Schema { - - varSchema := map[string]*schema.Schema{ + return map[string]*schema.Schema{ "resource_group_name": resourceGroupNameSchema(), "name": { @@ -120,7 +117,6 @@ func datasourceAutomationVariableCommonSchema(attType schema.ValueType) map[stri Computed: true, }, } - return varSchema } func resourceAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error { From e39b34c7d806eb967d0f5bb885b74c08b12a4436 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 14:23:57 -0700 Subject: [PATCH 21/29] put var type at the end of all names --- azurerm/automation_variable.go | 8 +++---- azurerm/automation_variable_test.go | 8 +++---- ...> data_source_automation_variable_bool.go} | 6 ++--- ...a_source_automation_variable_bool_test.go} | 10 ++++---- ...ta_source_automation_variable_datetime.go} | 6 ++--- ...urce_automation_variable_datetime_test.go} | 10 ++++---- ...=> data_source_automation_variable_int.go} | 6 ++--- ...ta_source_automation_variable_int_test.go} | 10 ++++---- ...data_source_automation_variable_string.go} | 6 ++--- ...source_automation_variable_string_test.go} | 10 ++++---- azurerm/helpers/azure/automation_variable.go | 8 +++---- azurerm/provider.go | 16 ++++++------- .../resource_arm_automation_bool_variable.go | 16 ++++++------- ...ource_arm_automation_bool_variable_test.go | 10 ++++---- ...source_arm_automation_datetime_variable.go | 16 ++++++------- ...e_arm_automation_datetime_variable_test.go | 10 ++++---- .../resource_arm_automation_int_variable.go | 16 ++++++------- ...source_arm_automation_int_variable_test.go | 10 ++++---- ...resource_arm_automation_string_variable.go | 16 ++++++------- ...rce_arm_automation_string_variable_test.go | 10 ++++---- website/azurerm.erb | 24 +++++++++---------- .../d/automation_bool_variable.html.markdown | 8 +++---- ...automation_datetime_variable.html.markdown | 8 +++---- .../d/automation_int_variable.html.markdown | 8 +++---- .../automation_string_variable.html.markdown | 8 +++---- ...=> automation_variable_bool.html.markdown} | 10 ++++---- ...utomation_variable_datetime.html.markdown} | 10 ++++---- ... => automation_variable_int.html.markdown} | 10 ++++---- ... automation_variable_string.html.markdown} | 10 ++++---- 29 files changed, 152 insertions(+), 152 deletions(-) rename azurerm/{data_source_automation_bool_variable.go => data_source_automation_variable_bool.go} (60%) rename azurerm/{data_source_automation_bool_variable_test.go => data_source_automation_variable_bool_test.go} (75%) rename azurerm/{data_source_automation_datetime_variable.go => data_source_automation_variable_datetime.go} (60%) rename azurerm/{data_source_automation_datetime_variable_test.go => data_source_automation_variable_datetime_test.go} (69%) rename azurerm/{data_source_automation_int_variable.go => data_source_automation_variable_int.go} (60%) rename azurerm/{data_source_automation_int_variable_test.go => data_source_automation_variable_int_test.go} (75%) rename azurerm/{data_source_automation_string_variable.go => data_source_automation_variable_string.go} (60%) rename azurerm/{data_source_automation_string_variable_test.go => data_source_automation_variable_string_test.go} (70%) rename website/docs/r/{automation_bool_variable.html.markdown => automation_variable_bool.html.markdown} (86%) rename website/docs/r/{automation_datetime_variable.html.markdown => automation_variable_datetime.html.markdown} (86%) rename website/docs/r/{automation_int_variable.html.markdown => automation_variable_int.html.markdown} (86%) rename website/docs/r/{automation_string_variable.html.markdown => automation_variable_string.html.markdown} (86%) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index 3b518783c30a..fab45c4512b6 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -32,15 +32,15 @@ func parseAzureAutomationVariableValue(resource string, input *string) (interfac if len(matches) == 2 && matches[0] == *input { if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { value = time.Unix(ticks/1000, ticks%1000*1000000).In(time.UTC) - actualResource = "azurerm_automation_datetime_variable" + actualResource = "azurerm_automation_variable_datetime" } } else if value, err = strconv.Unquote(*input); err == nil { - actualResource = "azurerm_automation_string_variable" + actualResource = "azurerm_automation_variable_string" } else if value, err = strconv.ParseBool(*input); err == nil { - actualResource = "azurerm_automation_bool_variable" + actualResource = "azurerm_automation_variable_bool" } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { value = int32(value.(int64)) - actualResource = "azurerm_automation_int_variable" + actualResource = "azurerm_automation_variable_int" } if actualResource != resource { diff --git a/azurerm/automation_variable_test.go b/azurerm/automation_variable_test.go index 1ef8541a9679..dbc51642a85a 100644 --- a/azurerm/automation_variable_test.go +++ b/azurerm/automation_variable_test.go @@ -24,7 +24,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }{ { Name: "string variable", - Resource: "azurerm_automation_string_variable", + Resource: "azurerm_automation_variable_string", Value: "\"Test String\"", HasError: false, ExpectValue: "Test String", @@ -32,7 +32,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }, { Name: "integer variable", - Resource: "azurerm_automation_int_variable", + Resource: "azurerm_automation_variable_int", Value: "135", HasError: false, ExpectValue: 135, @@ -40,7 +40,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }, { Name: "boolean variable", - Resource: "azurerm_automation_bool_variable", + Resource: "azurerm_automation_variable_bool", Value: "true", HasError: false, ExpectValue: true, @@ -48,7 +48,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { }, { Name: "datetime variable", - Resource: "azurerm_automation_datetime_variable", + Resource: "azurerm_automation_variable_datetime", Value: "\"\\/Date(1556142054074)\\/\"", HasError: false, ExpectValue: time.Date(2019, time.April, 24, 21, 40, 54, 74000000, time.UTC), diff --git a/azurerm/data_source_automation_bool_variable.go b/azurerm/data_source_automation_variable_bool.go similarity index 60% rename from azurerm/data_source_automation_bool_variable.go rename to azurerm/data_source_automation_variable_bool.go index fb3c6a977dc4..f133a8315369 100644 --- a/azurerm/data_source_automation_bool_variable.go +++ b/azurerm/data_source_automation_variable_bool.go @@ -4,14 +4,14 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func dataSourceArmAutomationBoolVariable() *schema.Resource { +func dataSourceArmAutomationVariableBool() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmAutomationBoolVariableRead, + Read: dataSourceArmAutomationVariableBoolRead, Schema: datasourceAutomationVariableCommonSchema(schema.TypeBool), } } -func dataSourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceArmAutomationVariableBoolRead(d *schema.ResourceData, meta interface{}) error { return datasourceAutomationVariableRead(d, meta, "Bool") } diff --git a/azurerm/data_source_automation_bool_variable_test.go b/azurerm/data_source_automation_variable_bool_test.go similarity index 75% rename from azurerm/data_source_automation_bool_variable_test.go rename to azurerm/data_source_automation_variable_bool_test.go index 39c0eb1a4030..5519d1e10d76 100644 --- a/azurerm/data_source_automation_bool_variable_test.go +++ b/azurerm/data_source_automation_variable_bool_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMAutomationBoolVariable_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_bool_variable.test" + dataSourceName := "data.azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -32,10 +32,10 @@ func testAccDataSourceAutomationBoolVariable_basic(rInt int, location string) st return fmt.Sprintf(` %s -data "azurerm_automation_bool_variable" "test" { - name = "${azurerm_automation_bool_variable.test.name}" - resource_group_name = "${azurerm_automation_bool_variable.test.resource_group_name}" - automation_account_name = "${azurerm_automation_bool_variable.test.automation_account_name}" +data "azurerm_automation_variable_bool" "test" { + name = "${azurerm_automation_variable_bool.test.name}" + resource_group_name = "${azurerm_automation_variable_bool.test.resource_group_name}" + automation_account_name = "${azurerm_automation_variable_bool.test.automation_account_name}" } `, config) } diff --git a/azurerm/data_source_automation_datetime_variable.go b/azurerm/data_source_automation_variable_datetime.go similarity index 60% rename from azurerm/data_source_automation_datetime_variable.go rename to azurerm/data_source_automation_variable_datetime.go index 8c0a4b5d06c9..575413adb7dc 100644 --- a/azurerm/data_source_automation_datetime_variable.go +++ b/azurerm/data_source_automation_variable_datetime.go @@ -4,14 +4,14 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func dataSourceArmAutomationDatetimeVariable() *schema.Resource { +func dataSourceArmAutomationVariableDateTime() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmAutomationDatetimeVariableRead, + Read: dataSourceArmAutomationVariableDateTimeRead, Schema: datasourceAutomationVariableCommonSchema(schema.TypeString), } } -func dataSourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceArmAutomationVariableDateTimeRead(d *schema.ResourceData, meta interface{}) error { return datasourceAutomationVariableRead(d, meta, "Datetime") } diff --git a/azurerm/data_source_automation_datetime_variable_test.go b/azurerm/data_source_automation_variable_datetime_test.go similarity index 69% rename from azurerm/data_source_automation_datetime_variable_test.go rename to azurerm/data_source_automation_variable_datetime_test.go index 61ab82bb84a5..79cd8eb9288c 100644 --- a/azurerm/data_source_automation_datetime_variable_test.go +++ b/azurerm/data_source_automation_variable_datetime_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMAutomationDatetimeVariable_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_datetime_variable.test" + dataSourceName := "data.azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -32,10 +32,10 @@ func testAccDataSourceAutomationDatetimeVariable_basic(rInt int, location string return fmt.Sprintf(` %s -data "azurerm_automation_datetime_variable" "test" { - name = "${azurerm_automation_datetime_variable.test.name}" - resource_group_name = "${azurerm_automation_datetime_variable.test.resource_group_name}" - automation_account_name = "${azurerm_automation_datetime_variable.test.automation_account_name}" +data "azurerm_automation_variable_datetime" "test" { + name = "${azurerm_automation_variable_datetime.test.name}" + resource_group_name = "${azurerm_automation_variable_datetime.test.resource_group_name}" + automation_account_name = "${azurerm_automation_variable_datetime.test.automation_account_name}" } `, config) } diff --git a/azurerm/data_source_automation_int_variable.go b/azurerm/data_source_automation_variable_int.go similarity index 60% rename from azurerm/data_source_automation_int_variable.go rename to azurerm/data_source_automation_variable_int.go index d546b4f4734d..84cb82667dde 100644 --- a/azurerm/data_source_automation_int_variable.go +++ b/azurerm/data_source_automation_variable_int.go @@ -4,14 +4,14 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func dataSourceArmAutomationIntVariable() *schema.Resource { +func dataSourceArmAutomationVariableInt() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmAutomationIntVariableRead, + Read: dataSourceArmAutomationVariableIntRead, Schema: datasourceAutomationVariableCommonSchema(schema.TypeInt), } } -func dataSourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceArmAutomationVariableIntRead(d *schema.ResourceData, meta interface{}) error { return datasourceAutomationVariableRead(d, meta, "Int") } diff --git a/azurerm/data_source_automation_int_variable_test.go b/azurerm/data_source_automation_variable_int_test.go similarity index 75% rename from azurerm/data_source_automation_int_variable_test.go rename to azurerm/data_source_automation_variable_int_test.go index 396c184583a2..f0a23089c28f 100644 --- a/azurerm/data_source_automation_int_variable_test.go +++ b/azurerm/data_source_automation_variable_int_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMAutomationIntVariable_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_int_variable.test" + dataSourceName := "data.azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -32,10 +32,10 @@ func testAccDataSourceAutomationIntVariable_basic(rInt int, location string) str return fmt.Sprintf(` %s -data "azurerm_automation_int_variable" "test" { - name = "${azurerm_automation_int_variable.test.name}" - resource_group_name = "${azurerm_automation_int_variable.test.resource_group_name}" - automation_account_name = "${azurerm_automation_int_variable.test.automation_account_name}" +data "azurerm_automation_variable_int" "test" { + name = "${azurerm_automation_variable_int.test.name}" + resource_group_name = "${azurerm_automation_variable_int.test.resource_group_name}" + automation_account_name = "${azurerm_automation_variable_int.test.automation_account_name}" } `, config) } diff --git a/azurerm/data_source_automation_string_variable.go b/azurerm/data_source_automation_variable_string.go similarity index 60% rename from azurerm/data_source_automation_string_variable.go rename to azurerm/data_source_automation_variable_string.go index 8b83b3dc3262..6fb94381c592 100644 --- a/azurerm/data_source_automation_string_variable.go +++ b/azurerm/data_source_automation_variable_string.go @@ -4,14 +4,14 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func dataSourceArmAutomationStringVariable() *schema.Resource { +func dataSourceArmAutomationVariableString() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmAutomationStringVariableRead, + Read: dataSourceArmAutomationVariableStringRead, Schema: datasourceAutomationVariableCommonSchema(schema.TypeString), } } -func dataSourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceArmAutomationVariableStringRead(d *schema.ResourceData, meta interface{}) error { return datasourceAutomationVariableRead(d, meta, "String") } diff --git a/azurerm/data_source_automation_string_variable_test.go b/azurerm/data_source_automation_variable_string_test.go similarity index 70% rename from azurerm/data_source_automation_string_variable_test.go rename to azurerm/data_source_automation_variable_string_test.go index 73db1db0077f..7cca1a6ca50e 100644 --- a/azurerm/data_source_automation_string_variable_test.go +++ b/azurerm/data_source_automation_variable_string_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMAutomationStringVariable_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_string_variable.test" + dataSourceName := "data.azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -32,10 +32,10 @@ func testAccDataSourceAutomationStringVariable_basic(rInt int, location string) return fmt.Sprintf(` %s -data "azurerm_automation_string_variable" "test" { - name = "${azurerm_automation_string_variable.test.name}" - resource_group_name = "${azurerm_automation_string_variable.test.resource_group_name}" - automation_account_name = "${azurerm_automation_string_variable.test.automation_account_name}" +data "azurerm_automation_variable_string" "test" { + name = "${azurerm_automation_variable_string.test.name}" + resource_group_name = "${azurerm_automation_variable_string.test.resource_group_name}" + automation_account_name = "${azurerm_automation_variable_string.test.automation_account_name}" } `, config) } diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 6fad91a447d6..042206256230 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -24,15 +24,15 @@ func ParseAzureRmAutomationVariableValue(resource string, input *string) (interf if len(matches) == 2 && matches[0] == *input { if ticks, err := strconv.ParseInt(matches[1], 10, 64); err == nil { value = time.Unix(ticks/1000, ticks%1000*1000000).In(time.UTC) - actualResource = "azurerm_automation_datetime_variable" + actualResource = "azurerm_automation_variable_datetime" } } else if value, err = strconv.Unquote(*input); err == nil { - actualResource = "azurerm_automation_string_variable" + actualResource = "azurerm_automation_variable_string" } else if value, err = strconv.ParseBool(*input); err == nil { - actualResource = "azurerm_automation_bool_variable" + actualResource = "azurerm_automation_variable_bool" } else if value, err = strconv.ParseInt(*input, 10, 32); err == nil { value = int32(value.(int64)) - actualResource = "azurerm_automation_int_variable" + actualResource = "azurerm_automation_variable_int" } if actualResource != resource { diff --git a/azurerm/provider.go b/azurerm/provider.go index daee989a7eb4..8c839777bd8b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -107,10 +107,10 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_application_insights": dataSourceArmApplicationInsights(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_automation_bool_variable": dataSourceArmAutomationBoolVariable(), - "azurerm_automation_datetime_variable": dataSourceArmAutomationDatetimeVariable(), - "azurerm_automation_int_variable": dataSourceArmAutomationIntVariable(), - "azurerm_automation_string_variable": dataSourceArmAutomationStringVariable(), + "azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(), + "azurerm_automation_variable_datetime": dataSourceArmAutomationVariableDateTime(), + "azurerm_automation_variable_int": dataSourceArmAutomationVariableInt(), + "azurerm_automation_variable_string": dataSourceArmAutomationVariableString(), "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), @@ -214,10 +214,10 @@ func Provider() terraform.ResourceProvider { "azurerm_automation_module": resourceArmAutomationModule(), "azurerm_automation_runbook": resourceArmAutomationRunbook(), "azurerm_automation_schedule": resourceArmAutomationSchedule(), - "azurerm_automation_bool_variable": resourceArmAutomationBoolVariable(), - "azurerm_automation_datetime_variable": resourceArmAutomationDatetimeVariable(), - "azurerm_automation_int_variable": resourceArmAutomationIntVariable(), - "azurerm_automation_string_variable": resourceArmAutomationStringVariable(), + "azurerm_automation_variable_bool": resourceArmAutomationVariableBool(), + "azurerm_automation_variable_datetime": resourceArmAutomationVariableDateTime(), + "azurerm_automation_variable_int": resourceArmAutomationVariableInt(), + "azurerm_automation_variable_string": resourceArmAutomationVariableString(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_bool_variable.go index ba4c37b4747b..6b1bc9c2770d 100644 --- a/azurerm/resource_arm_automation_bool_variable.go +++ b/azurerm/resource_arm_automation_bool_variable.go @@ -4,12 +4,12 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func resourceArmAutomationBoolVariable() *schema.Resource { +func resourceArmAutomationVariableBool() *schema.Resource { return &schema.Resource{ - Create: resourceArmAutomationBoolVariableCreateUpdate, - Read: resourceArmAutomationBoolVariableRead, - Update: resourceArmAutomationBoolVariableCreateUpdate, - Delete: resourceArmAutomationBoolVariableDelete, + Create: resourceArmAutomationVariableBoolCreateUpdate, + Read: resourceArmAutomationVariableBoolRead, + Update: resourceArmAutomationVariableBoolCreateUpdate, + Delete: resourceArmAutomationVariableBoolDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -19,14 +19,14 @@ func resourceArmAutomationBoolVariable() *schema.Resource { } } -func resourceArmAutomationBoolVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableBoolCreateUpdate(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableCreateUpdate(d, meta, "Bool") } -func resourceArmAutomationBoolVariableRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableBoolRead(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableRead(d, meta, "Bool") } -func resourceArmAutomationBoolVariableDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableBoolDelete(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableDelete(d, meta, "Bool") } diff --git a/azurerm/resource_arm_automation_bool_variable_test.go b/azurerm/resource_arm_automation_bool_variable_test.go index 25e9f80cad0b..770118b51dbe 100644 --- a/azurerm/resource_arm_automation_bool_variable_test.go +++ b/azurerm/resource_arm_automation_bool_variable_test.go @@ -10,7 +10,7 @@ import ( ) func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { - resourceName := "azurerm_automation_bool_variable.test" + resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -36,7 +36,7 @@ func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { } func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { - resourceName := "azurerm_automation_bool_variable.test" + resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -63,7 +63,7 @@ func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { } func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_bool_variable.test" + resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -123,7 +123,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_bool_variable" "test" { +resource "azurerm_automation_variable_bool" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" @@ -149,7 +149,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_bool_variable" "test" { +resource "azurerm_automation_variable_bool" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_datetime_variable.go index 7645a5e90a68..8343052c029d 100644 --- a/azurerm/resource_arm_automation_datetime_variable.go +++ b/azurerm/resource_arm_automation_datetime_variable.go @@ -5,12 +5,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) -func resourceArmAutomationDatetimeVariable() *schema.Resource { +func resourceArmAutomationVariableDateTime() *schema.Resource { return &schema.Resource{ - Create: resourceArmAutomationDatetimeVariableCreateUpdate, - Read: resourceArmAutomationDatetimeVariableRead, - Update: resourceArmAutomationDatetimeVariableCreateUpdate, - Delete: resourceArmAutomationDatetimeVariableDelete, + Create: resourceArmAutomationVariableDateTimeCreateUpdate, + Read: resourceArmAutomationVariableDateTimeRead, + Update: resourceArmAutomationVariableDateTimeCreateUpdate, + Delete: resourceArmAutomationVariableDateTimeDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -20,14 +20,14 @@ func resourceArmAutomationDatetimeVariable() *schema.Resource { } } -func resourceArmAutomationDatetimeVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableDateTimeCreateUpdate(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableCreateUpdate(d, meta, "Datetime") } -func resourceArmAutomationDatetimeVariableRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableDateTimeRead(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableRead(d, meta, "Datetime") } -func resourceArmAutomationDatetimeVariableDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableDateTimeDelete(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableDelete(d, meta, "Datetime") } diff --git a/azurerm/resource_arm_automation_datetime_variable_test.go b/azurerm/resource_arm_automation_datetime_variable_test.go index 46c5ca0b3cc0..32386b643197 100644 --- a/azurerm/resource_arm_automation_datetime_variable_test.go +++ b/azurerm/resource_arm_automation_datetime_variable_test.go @@ -10,7 +10,7 @@ import ( ) func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { - resourceName := "azurerm_automation_datetime_variable.test" + resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -36,7 +36,7 @@ func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { } func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { - resourceName := "azurerm_automation_datetime_variable.test" + resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -63,7 +63,7 @@ func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { } func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_datetime_variable.test" + resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -123,7 +123,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_datetime_variable" "test" { +resource "azurerm_automation_variable_datetime" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" @@ -149,7 +149,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_datetime_variable" "test" { +resource "azurerm_automation_variable_datetime" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_int_variable.go index 6842c447a586..ea2c5992f235 100644 --- a/azurerm/resource_arm_automation_int_variable.go +++ b/azurerm/resource_arm_automation_int_variable.go @@ -4,12 +4,12 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func resourceArmAutomationIntVariable() *schema.Resource { +func resourceArmAutomationVariableInt() *schema.Resource { return &schema.Resource{ - Create: resourceArmAutomationIntVariableCreateUpdate, - Read: resourceArmAutomationIntVariableRead, - Update: resourceArmAutomationIntVariableCreateUpdate, - Delete: resourceArmAutomationIntVariableDelete, + Create: resourceArmAutomationVariableIntCreateUpdate, + Read: resourceArmAutomationVariableIntRead, + Update: resourceArmAutomationVariableIntCreateUpdate, + Delete: resourceArmAutomationVariableIntDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -19,14 +19,14 @@ func resourceArmAutomationIntVariable() *schema.Resource { } } -func resourceArmAutomationIntVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableIntCreateUpdate(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableCreateUpdate(d, meta, "Int") } -func resourceArmAutomationIntVariableRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableIntRead(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableRead(d, meta, "Int") } -func resourceArmAutomationIntVariableDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableIntDelete(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableDelete(d, meta, "Int") } diff --git a/azurerm/resource_arm_automation_int_variable_test.go b/azurerm/resource_arm_automation_int_variable_test.go index f55c37457136..62efa24bbc2b 100644 --- a/azurerm/resource_arm_automation_int_variable_test.go +++ b/azurerm/resource_arm_automation_int_variable_test.go @@ -10,7 +10,7 @@ import ( ) func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { - resourceName := "azurerm_automation_int_variable.test" + resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -36,7 +36,7 @@ func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { } func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { - resourceName := "azurerm_automation_int_variable.test" + resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -63,7 +63,7 @@ func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { } func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_int_variable.test" + resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -123,7 +123,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_int_variable" "test" { +resource "azurerm_automation_variable_int" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" @@ -149,7 +149,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_int_variable" "test" { +resource "azurerm_automation_variable_int" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_string_variable.go index 486d827a62a0..b52b84e4eb26 100644 --- a/azurerm/resource_arm_automation_string_variable.go +++ b/azurerm/resource_arm_automation_string_variable.go @@ -5,12 +5,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) -func resourceArmAutomationStringVariable() *schema.Resource { +func resourceArmAutomationVariableString() *schema.Resource { return &schema.Resource{ - Create: resourceArmAutomationStringVariableCreateUpdate, - Read: resourceArmAutomationStringVariableRead, - Update: resourceArmAutomationStringVariableCreateUpdate, - Delete: resourceArmAutomationStringVariableDelete, + Create: resourceArmAutomationVariableStringCreateUpdate, + Read: resourceArmAutomationVariableStringRead, + Update: resourceArmAutomationVariableStringCreateUpdate, + Delete: resourceArmAutomationVariableStringDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -20,14 +20,14 @@ func resourceArmAutomationStringVariable() *schema.Resource { } } -func resourceArmAutomationStringVariableCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableStringCreateUpdate(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableCreateUpdate(d, meta, "String") } -func resourceArmAutomationStringVariableRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableStringRead(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableRead(d, meta, "String") } -func resourceArmAutomationStringVariableDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmAutomationVariableStringDelete(d *schema.ResourceData, meta interface{}) error { return resourceAutomationVariableDelete(d, meta, "String") } diff --git a/azurerm/resource_arm_automation_string_variable_test.go b/azurerm/resource_arm_automation_string_variable_test.go index 3416612e88ef..db5f9138b4c9 100644 --- a/azurerm/resource_arm_automation_string_variable_test.go +++ b/azurerm/resource_arm_automation_string_variable_test.go @@ -10,7 +10,7 @@ import ( ) func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { - resourceName := "azurerm_automation_string_variable.test" + resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -36,7 +36,7 @@ func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { } func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { - resourceName := "azurerm_automation_string_variable.test" + resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -63,7 +63,7 @@ func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { } func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_string_variable.test" + resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -123,7 +123,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_string_variable" "test" { +resource "azurerm_automation_variable_string" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" @@ -149,7 +149,7 @@ resource "azurerm_automation_account" "test" { } } -resource "azurerm_automation_string_variable" "test" { +resource "azurerm_automation_variable_string" "test" { name = "acctestAutoVar-%d" resource_group_name = "${azurerm_resource_group.test.name}" automation_account_name = "${azurerm_automation_account.test.name}" diff --git a/website/azurerm.erb b/website/azurerm.erb index 99585170fdc8..7cf2b853b750 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -96,19 +96,19 @@ > - azurerm_automation_bool_variable + azurerm_automation_variable_bool > - azurerm_automation_datetime_variable + azurerm_automation_variable_datetime > - azurerm_automation_int_variable + azurerm_automation_variable_int > - azurerm_automation_string_variable + azurerm_automation_variable_string > @@ -546,20 +546,20 @@ azurerm_automation_schedule - > - azurerm_automation_bool_variable + > + azurerm_automation_variable_bool - > - azurerm_automation_datetime_variable + > + azurerm_automation_variable_datetime - > - azurerm_automation_bool_variable + > + azurerm_automation_variable_bool - > - azurerm_automation_string_variable + > + azurerm_automation_variable_string diff --git a/website/docs/d/automation_bool_variable.html.markdown b/website/docs/d/automation_bool_variable.html.markdown index e35065d32364..238b4a1fd4e8 100644 --- a/website/docs/d/automation_bool_variable.html.markdown +++ b/website/docs/d/automation_bool_variable.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_bool_variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_bool" sidebar_current: "docs-azurerm-datasource-automation-bool-variable" description: |- Gets information about an existing Automation Bool Variable --- -# Data Source: azurerm_automation_bool_variable +# Data Source: azurerm_automation_variable_bool Use this data source to access information about an existing Automation Bool Variable. @@ -14,14 +14,14 @@ Use this data source to access information about an existing Automation Bool Var ## Example Usage ```hcl -data "azurerm_automation_bool_variable" "example" { +data "azurerm_automation_variable_bool" "example" { name = "tfex-example-var" resource_group_name = "tfex-example-rg" automation_account_name = "tfex-example-account" } output "variable_id" { - value = "${data.azurerm_automation_bool_variable.example.id}" + value = "${data.azurerm_automation_variable_bool.example.id}" } ``` diff --git a/website/docs/d/automation_datetime_variable.html.markdown b/website/docs/d/automation_datetime_variable.html.markdown index 136d64e3c428..4f83d8c98936 100644 --- a/website/docs/d/automation_datetime_variable.html.markdown +++ b/website/docs/d/automation_datetime_variable.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_datetime_variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_datetime" sidebar_current: "docs-azurerm-datasource-automation-datetime-variable" description: |- Gets information about an existing Automation Datetime Variable --- -# Data Source: azurerm_automation_datetime_variable +# Data Source: azurerm_automation_variable_datetime Use this data source to access information about an existing Automation Datetime Variable. @@ -14,14 +14,14 @@ Use this data source to access information about an existing Automation Datetime ## Example Usage ```hcl -data "azurerm_automation_datetime_variable" "example" { +data "azurerm_automation_variable_datetime" "example" { name = "tfex-example-var" resource_group_name = "tfex-example-rg" automation_account_name = "tfex-example-account" } output "variable_id" { - value = "${data.azurerm_automation_datetime_variable.example.id}" + value = "${data.azurerm_automation_variable_datetime.example.id}" } ``` diff --git a/website/docs/d/automation_int_variable.html.markdown b/website/docs/d/automation_int_variable.html.markdown index f9bb70d10b96..b293e861dbeb 100644 --- a/website/docs/d/automation_int_variable.html.markdown +++ b/website/docs/d/automation_int_variable.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_int_variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_int" sidebar_current: "docs-azurerm-datasource-automation-int-variable" description: |- Gets information about an existing Automation Int Variable --- -# Data Source: azurerm_automation_int_variable +# Data Source: azurerm_automation_variable_int Use this data source to access information about an existing Automation Int Variable. @@ -14,14 +14,14 @@ Use this data source to access information about an existing Automation Int Vari ## Example Usage ```hcl -data "azurerm_automation_int_variable" "example" { +data "azurerm_automation_variable_int" "example" { name = "tfex-example-var" resource_group_name = "tfex-example-rg" automation_account_name = "tfex-example-account" } output "variable_id" { - value = "${data.azurerm_automation_int_variable.example.id}" + value = "${data.azurerm_automation_variable_int.example.id}" } ``` diff --git a/website/docs/d/automation_string_variable.html.markdown b/website/docs/d/automation_string_variable.html.markdown index d83ee63e71f1..1702a355f597 100644 --- a/website/docs/d/automation_string_variable.html.markdown +++ b/website/docs/d/automation_string_variable.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_string_variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_string" sidebar_current: "docs-azurerm-datasource-automation-string-variable" description: |- Gets information about an existing Automation String Variable --- -# Data Source: azurerm_automation_string_variable +# Data Source: azurerm_automation_variable_string Use this data source to access information about an existing Automation String Variable. @@ -14,14 +14,14 @@ Use this data source to access information about an existing Automation String V ## Example Usage ```hcl -data "azurerm_automation_string_variable" "example" { +data "azurerm_automation_variable_string" "example" { name = "tfex-example-var" resource_group_name = "tfex-example-rg" automation_account_name = "tfex-example-account" } output "variable_id" { - value = "${data.azurerm_automation_string_variable.example.id}" + value = "${data.azurerm_automation_variable_string.example.id}" } ``` diff --git a/website/docs/r/automation_bool_variable.html.markdown b/website/docs/r/automation_variable_bool.html.markdown similarity index 86% rename from website/docs/r/automation_bool_variable.html.markdown rename to website/docs/r/automation_variable_bool.html.markdown index 9314fba0b158..f570eac73654 100644 --- a/website/docs/r/automation_bool_variable.html.markdown +++ b/website/docs/r/automation_variable_bool.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_bool_variable" -sidebar_current: "docs-azurerm-resource-automation-bool-variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_bool" +sidebar_current: "docs-azurerm-resource-automation-variable-bool" description: |- Manages a boolean variable in Azure Automation. --- -# azurerm_automation_bool_variable +# azurerm_automation_variable_bool Manages a boolean variable in Azure Automation @@ -29,7 +29,7 @@ resource "azurerm_automation_account" "example" { } } -resource "azurerm_automation_bool_variable" "example" { +resource "azurerm_automation_variable_bool" "example" { name = "tfex-example-var" resource_group_name = "${azurerm_resource_group.example.name}" automation_account_name = "${azurerm_automation_account.example.name}" @@ -65,5 +65,5 @@ The following attributes are exported: Automation Bool Variable can be imported using the `resource id`, e.g. ```shell -$ terraform import azurerm_automation_bool_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +$ terraform import azurerm_automation_variable_bool.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var ``` diff --git a/website/docs/r/automation_datetime_variable.html.markdown b/website/docs/r/automation_variable_datetime.html.markdown similarity index 86% rename from website/docs/r/automation_datetime_variable.html.markdown rename to website/docs/r/automation_variable_datetime.html.markdown index d106aad8e735..13d3ced0442d 100644 --- a/website/docs/r/automation_datetime_variable.html.markdown +++ b/website/docs/r/automation_variable_datetime.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_datetime_variable" -sidebar_current: "docs-azurerm-resource-automation-datetime-variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_datetime" +sidebar_current: "docs-azurerm-resource-automation-variable-datetime" description: |- Manages a date/time variable in Azure Automation. --- -# azurerm_automation_datetime_variable +# azurerm_automation_variable_datetime Manages a date/time variable in Azure Automation @@ -29,7 +29,7 @@ resource "azurerm_automation_account" "example" { } } -resource "azurerm_automation_datetime_variable" "example" { +resource "azurerm_automation_variable_datetime" "example" { name = "tfex-example-var" resource_group_name = "${azurerm_resource_group.example.name}" automation_account_name = "${azurerm_automation_account.example.name}" @@ -65,5 +65,5 @@ The following attributes are exported: Automation Datetime Variable can be imported using the `resource id`, e.g. ```shell -$ terraform import azurerm_automation_datetime_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +$ terraform import azurerm_automation_variable_datetime.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var ``` diff --git a/website/docs/r/automation_int_variable.html.markdown b/website/docs/r/automation_variable_int.html.markdown similarity index 86% rename from website/docs/r/automation_int_variable.html.markdown rename to website/docs/r/automation_variable_int.html.markdown index 8f4bfd0c4fe9..3b1a14bd974d 100644 --- a/website/docs/r/automation_int_variable.html.markdown +++ b/website/docs/r/automation_variable_int.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_int_variable" -sidebar_current: "docs-azurerm-resource-automation-int-variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_int" +sidebar_current: "docs-azurerm-resource-automation-variable-int" description: |- Manages a integer variable in Azure Automation. --- -# azurerm_automation_int_variable +# azurerm_automation_variable_int Manages a integer variable in Azure Automation @@ -29,7 +29,7 @@ resource "azurerm_automation_account" "example" { } } -resource "azurerm_automation_int_variable" "example" { +resource "azurerm_automation_variable_int" "example" { name = "tfex-example-var" resource_group_name = "${azurerm_resource_group.example.name}" automation_account_name = "${azurerm_automation_account.example.name}" @@ -65,5 +65,5 @@ The following attributes are exported: Automation Int Variable can be imported using the `resource id`, e.g. ```shell -$ terraform import azurerm_automation_int_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +$ terraform import azurerm_automation_variable_int.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var ``` diff --git a/website/docs/r/automation_string_variable.html.markdown b/website/docs/r/automation_variable_string.html.markdown similarity index 86% rename from website/docs/r/automation_string_variable.html.markdown rename to website/docs/r/automation_variable_string.html.markdown index a59908171147..f46d0dbc357d 100644 --- a/website/docs/r/automation_string_variable.html.markdown +++ b/website/docs/r/automation_variable_string.html.markdown @@ -1,12 +1,12 @@ --- layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automation_string_variable" -sidebar_current: "docs-azurerm-resource-automation-string-variable" +page_title: "Azure Resource Manager: azurerm_automation_variable_string" +sidebar_current: "docs-azurerm-resource-automation-variable-string" description: |- Manages a string variable in Azure Automation. --- -# azurerm_automation_string_variable +# azurerm_automation_variable_string Manages a string variable in Azure Automation @@ -29,7 +29,7 @@ resource "azurerm_automation_account" "example" { } } -resource "azurerm_automation_string_variable" "example" { +resource "azurerm_automation_variable_string" "example" { name = "tfex-example-var" resource_group_name = "${azurerm_resource_group.example.name}" automation_account_name = "${azurerm_automation_account.example.name}" @@ -65,5 +65,5 @@ The following attributes are exported: Automation String Variable can be imported using the `resource id`, e.g. ```shell -$ terraform import azurerm_automation_string_variable.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var +$ terraform import azurerm_automation_variable_string.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/tfex-example-rg/providers/Microsoft.Automation/automationAccounts/tfex-example-account/variables/tfex-example-var ``` From e15f577c5d2cafe1c69231e11c9dd51fcb5a34ff Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 14:31:01 -0700 Subject: [PATCH 22/29] missed some file renames --- ..._bool_variable.go => resource_arm_automation_variable_bool.go} | 0 ...able_test.go => resource_arm_automation_variable_bool_test.go} | 0 ...e_variable.go => resource_arm_automation_variable_datetime.go} | 0 ..._test.go => resource_arm_automation_variable_datetime_test.go} | 0 ...on_int_variable.go => resource_arm_automation_variable_int.go} | 0 ...iable_test.go => resource_arm_automation_variable_int_test.go} | 0 ...ing_variable.go => resource_arm_automation_variable_string.go} | 0 ...le_test.go => resource_arm_automation_variable_string_test.go} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename azurerm/{resource_arm_automation_bool_variable.go => resource_arm_automation_variable_bool.go} (100%) rename azurerm/{resource_arm_automation_bool_variable_test.go => resource_arm_automation_variable_bool_test.go} (100%) rename azurerm/{resource_arm_automation_datetime_variable.go => resource_arm_automation_variable_datetime.go} (100%) rename azurerm/{resource_arm_automation_datetime_variable_test.go => resource_arm_automation_variable_datetime_test.go} (100%) rename azurerm/{resource_arm_automation_int_variable.go => resource_arm_automation_variable_int.go} (100%) rename azurerm/{resource_arm_automation_int_variable_test.go => resource_arm_automation_variable_int_test.go} (100%) rename azurerm/{resource_arm_automation_string_variable.go => resource_arm_automation_variable_string.go} (100%) rename azurerm/{resource_arm_automation_string_variable_test.go => resource_arm_automation_variable_string_test.go} (100%) diff --git a/azurerm/resource_arm_automation_bool_variable.go b/azurerm/resource_arm_automation_variable_bool.go similarity index 100% rename from azurerm/resource_arm_automation_bool_variable.go rename to azurerm/resource_arm_automation_variable_bool.go diff --git a/azurerm/resource_arm_automation_bool_variable_test.go b/azurerm/resource_arm_automation_variable_bool_test.go similarity index 100% rename from azurerm/resource_arm_automation_bool_variable_test.go rename to azurerm/resource_arm_automation_variable_bool_test.go diff --git a/azurerm/resource_arm_automation_datetime_variable.go b/azurerm/resource_arm_automation_variable_datetime.go similarity index 100% rename from azurerm/resource_arm_automation_datetime_variable.go rename to azurerm/resource_arm_automation_variable_datetime.go diff --git a/azurerm/resource_arm_automation_datetime_variable_test.go b/azurerm/resource_arm_automation_variable_datetime_test.go similarity index 100% rename from azurerm/resource_arm_automation_datetime_variable_test.go rename to azurerm/resource_arm_automation_variable_datetime_test.go diff --git a/azurerm/resource_arm_automation_int_variable.go b/azurerm/resource_arm_automation_variable_int.go similarity index 100% rename from azurerm/resource_arm_automation_int_variable.go rename to azurerm/resource_arm_automation_variable_int.go diff --git a/azurerm/resource_arm_automation_int_variable_test.go b/azurerm/resource_arm_automation_variable_int_test.go similarity index 100% rename from azurerm/resource_arm_automation_int_variable_test.go rename to azurerm/resource_arm_automation_variable_int_test.go diff --git a/azurerm/resource_arm_automation_string_variable.go b/azurerm/resource_arm_automation_variable_string.go similarity index 100% rename from azurerm/resource_arm_automation_string_variable.go rename to azurerm/resource_arm_automation_variable_string.go diff --git a/azurerm/resource_arm_automation_string_variable_test.go b/azurerm/resource_arm_automation_variable_string_test.go similarity index 100% rename from azurerm/resource_arm_automation_string_variable_test.go rename to azurerm/resource_arm_automation_variable_string_test.go From 23c136408e5b3864a1e0196f840b1dc4a4fe193f Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 14:32:44 -0700 Subject: [PATCH 23/29] fixed tests --- azurerm/automation_variable.go | 6 +++--- azurerm/automation_variable_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index fab45c4512b6..8a871acb941e 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -137,7 +137,7 @@ func resourceAutomationVariableCreateUpdate(d *schema.ResourceData, meta interfa } if !utils.ResponseWasNotFound(resp.Response) { - return tf.ImportAsExistsError(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), *resp.ID) + return tf.ImportAsExistsError(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), *resp.ID) } } @@ -218,7 +218,7 @@ func resourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, va d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) if !d.Get("encrypted").(bool) { - value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) + value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) if err != nil { return err } @@ -262,7 +262,7 @@ func datasourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) if !d.Get("encrypted").(bool) { - value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_%s_variable", varTypeLower), properties.Value) + value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) if err != nil { return err } diff --git a/azurerm/automation_variable_test.go b/azurerm/automation_variable_test.go index dbc51642a85a..c3ca3a9b5cd6 100644 --- a/azurerm/automation_variable_test.go +++ b/azurerm/automation_variable_test.go @@ -108,7 +108,7 @@ func testCheckAzureRMAutomationVariableDestroy(s *terraform.State, varType strin client := testAccProvider.Meta().(*ArmClient).automationVariableClient ctx := testAccProvider.Meta().(*ArmClient).StopContext - resourceName := fmt.Sprintf("azurerm_automation_%s_variable", strings.ToLower(varType)) + resourceName := fmt.Sprintf("azurerm_automation_variable_%s", strings.ToLower(varType)) for _, rs := range s.RootModule().Resources { if rs.Type != resourceName { From 3bcc1307fd5496fb3fa93d3436daa1d1be771434 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 14:42:13 -0700 Subject: [PATCH 24/29] fixed test names to conform to new format --- ...ta_source_automation_variable_bool_test.go | 8 ++-- ...ource_automation_variable_datetime_test.go | 8 ++-- ...ata_source_automation_variable_int_test.go | 8 ++-- ..._source_automation_variable_string_test.go | 8 ++-- ...ource_arm_automation_variable_bool_test.go | 40 +++++++++---------- ...e_arm_automation_variable_datetime_test.go | 40 +++++++++---------- ...source_arm_automation_variable_int_test.go | 40 +++++++++---------- ...rce_arm_automation_variable_string_test.go | 40 +++++++++---------- 8 files changed, 96 insertions(+), 96 deletions(-) diff --git a/azurerm/data_source_automation_variable_bool_test.go b/azurerm/data_source_automation_variable_bool_test.go index 5519d1e10d76..ea3893f0b8bd 100644 --- a/azurerm/data_source_automation_variable_bool_test.go +++ b/azurerm/data_source_automation_variable_bool_test.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccDataSourceAzureRMAutomationBoolVariable_basic(t *testing.T) { +func TestAccDataSourceAzureRMAutomationVariableBool_basic(t *testing.T) { dataSourceName := "data.azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -18,7 +18,7 @@ func TestAccDataSourceAzureRMAutomationBoolVariable_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationBoolVariable_basic(ri, location), + Config: testAccDataSourceAutomationVariableBool_basic(ri, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "value", "false"), ), @@ -27,8 +27,8 @@ func TestAccDataSourceAzureRMAutomationBoolVariable_basic(t *testing.T) { }) } -func testAccDataSourceAutomationBoolVariable_basic(rInt int, location string) string { - config := testAccAzureRMAutomationBoolVariable_basic(rInt, location) +func testAccDataSourceAutomationVariableBool_basic(rInt int, location string) string { + config := testAccAzureRMAutomationVariableBool_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/data_source_automation_variable_datetime_test.go b/azurerm/data_source_automation_variable_datetime_test.go index 79cd8eb9288c..7f89e8c198fa 100644 --- a/azurerm/data_source_automation_variable_datetime_test.go +++ b/azurerm/data_source_automation_variable_datetime_test.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccDataSourceAzureRMAutomationDatetimeVariable_basic(t *testing.T) { +func TestAccDataSourceAzureRMAutomationVariableDateTime_basic(t *testing.T) { dataSourceName := "data.azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -18,7 +18,7 @@ func TestAccDataSourceAzureRMAutomationDatetimeVariable_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationDatetimeVariable_basic(ri, location), + Config: testAccDataSourceAutomationVariableDateTime_basic(ri, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "value", "2019-04-24T21:40:54.074Z"), ), @@ -27,8 +27,8 @@ func TestAccDataSourceAzureRMAutomationDatetimeVariable_basic(t *testing.T) { }) } -func testAccDataSourceAutomationDatetimeVariable_basic(rInt int, location string) string { - config := testAccAzureRMAutomationDatetimeVariable_basic(rInt, location) +func testAccDataSourceAutomationVariableDateTime_basic(rInt int, location string) string { + config := testAccAzureRMAutomationVariableDateTime_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/data_source_automation_variable_int_test.go b/azurerm/data_source_automation_variable_int_test.go index f0a23089c28f..4bf5b417f8b4 100644 --- a/azurerm/data_source_automation_variable_int_test.go +++ b/azurerm/data_source_automation_variable_int_test.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccDataSourceAzureRMAutomationIntVariable_basic(t *testing.T) { +func TestAccDataSourceAzureRMAutomationVariableInt_basic(t *testing.T) { dataSourceName := "data.azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -18,7 +18,7 @@ func TestAccDataSourceAzureRMAutomationIntVariable_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationIntVariable_basic(ri, location), + Config: testAccDataSourceAutomationVariableInt_basic(ri, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "value", "1234"), ), @@ -27,8 +27,8 @@ func TestAccDataSourceAzureRMAutomationIntVariable_basic(t *testing.T) { }) } -func testAccDataSourceAutomationIntVariable_basic(rInt int, location string) string { - config := testAccAzureRMAutomationIntVariable_basic(rInt, location) +func testAccDataSourceAutomationVariableInt_basic(rInt int, location string) string { + config := testAccAzureRMAutomationVariableInt_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/data_source_automation_variable_string_test.go b/azurerm/data_source_automation_variable_string_test.go index 7cca1a6ca50e..68a40d6513a5 100644 --- a/azurerm/data_source_automation_variable_string_test.go +++ b/azurerm/data_source_automation_variable_string_test.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccDataSourceAzureRMAutomationStringVariable_basic(t *testing.T) { +func TestAccDataSourceAzureRMAutomationVariableString_basic(t *testing.T) { dataSourceName := "data.azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -18,7 +18,7 @@ func TestAccDataSourceAzureRMAutomationStringVariable_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationStringVariable_basic(ri, location), + Config: testAccDataSourceAutomationVariableString_basic(ri, location), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "value", "Hello, Terraform Basic Test."), ), @@ -27,8 +27,8 @@ func TestAccDataSourceAzureRMAutomationStringVariable_basic(t *testing.T) { }) } -func testAccDataSourceAutomationStringVariable_basic(rInt int, location string) string { - config := testAccAzureRMAutomationStringVariable_basic(rInt, location) +func testAccDataSourceAutomationVariableString_basic(rInt int, location string) string { + config := testAccAzureRMAutomationVariableString_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/resource_arm_automation_variable_bool_test.go b/azurerm/resource_arm_automation_variable_bool_test.go index 770118b51dbe..f01d31f7bd69 100644 --- a/azurerm/resource_arm_automation_variable_bool_test.go +++ b/azurerm/resource_arm_automation_variable_bool_test.go @@ -9,7 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { +func TestAccAzureRMAutomationVariableBool_basic(t *testing.T) { resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -17,12 +17,12 @@ func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationBoolVariableExists(resourceName), + testCheckAzureRMAutomationVariableBoolExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "false"), ), }, @@ -35,7 +35,7 @@ func TestAccAzureRMAutomationBoolVariable_basic(t *testing.T) { }) } -func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { +func TestAccAzureRMAutomationVariableBool_complete(t *testing.T) { resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -43,12 +43,12 @@ func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationBoolVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableBool_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationBoolVariableExists(resourceName), + testCheckAzureRMAutomationVariableBoolExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "true"), ), @@ -62,7 +62,7 @@ func TestAccAzureRMAutomationBoolVariable_complete(t *testing.T) { }) } -func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { +func TestAccAzureRMAutomationVariableBool_basicCompleteUpdate(t *testing.T) { resourceName := "azurerm_automation_variable_bool.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -70,27 +70,27 @@ func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationBoolVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationBoolVariableExists(resourceName), + testCheckAzureRMAutomationVariableBoolExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "false"), ), }, { - Config: testAccAzureRMAutomationBoolVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableBool_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationBoolVariableExists(resourceName), + testCheckAzureRMAutomationVariableBoolExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "true"), ), }, { - Config: testAccAzureRMAutomationBoolVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationBoolVariableExists(resourceName), + testCheckAzureRMAutomationVariableBoolExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "false"), ), }, @@ -98,15 +98,15 @@ func TestAccAzureRMAutomationBoolVariable_basicCompleteUpdate(t *testing.T) { }) } -func testCheckAzureRMAutomationBoolVariableExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMAutomationVariableBoolExists(resourceName string) resource.TestCheckFunc { return testCheckAzureRMAutomationVariableExists(resourceName, "Bool") } -func testCheckAzureRMAutomationBoolVariableDestroy(s *terraform.State) error { +func testCheckAzureRMAutomationVariableBoolDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "Bool") } -func testAccAzureRMAutomationBoolVariable_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableBool_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -132,7 +132,7 @@ resource "azurerm_automation_variable_bool" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAutomationBoolVariable_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableBool_complete(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" diff --git a/azurerm/resource_arm_automation_variable_datetime_test.go b/azurerm/resource_arm_automation_variable_datetime_test.go index 32386b643197..935d006a77d7 100644 --- a/azurerm/resource_arm_automation_variable_datetime_test.go +++ b/azurerm/resource_arm_automation_variable_datetime_test.go @@ -9,7 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { +func TestAccAzureRMAutomationVariableDateTime_basic(t *testing.T) { resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -17,12 +17,12 @@ func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + testCheckAzureRMAutomationVariableDateTimeExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, @@ -35,7 +35,7 @@ func TestAccAzureRMAutomationDatetimeVariable_basic(t *testing.T) { }) } -func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { +func TestAccAzureRMAutomationVariableDateTime_complete(t *testing.T) { resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -43,12 +43,12 @@ func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDatetimeVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + testCheckAzureRMAutomationVariableDateTimeExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), ), @@ -62,7 +62,7 @@ func TestAccAzureRMAutomationDatetimeVariable_complete(t *testing.T) { }) } -func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) { +func TestAccAzureRMAutomationVariableDateTime_basicCompleteUpdate(t *testing.T) { resourceName := "azurerm_automation_variable_datetime.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -70,27 +70,27 @@ func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationDatetimeVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + testCheckAzureRMAutomationVariableDateTimeExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, { - Config: testAccAzureRMAutomationDatetimeVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + testCheckAzureRMAutomationVariableDateTimeExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), ), }, { - Config: testAccAzureRMAutomationDatetimeVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDatetimeVariableExists(resourceName), + testCheckAzureRMAutomationVariableDateTimeExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, @@ -98,15 +98,15 @@ func TestAccAzureRMAutomationDatetimeVariable_basicCompleteUpdate(t *testing.T) }) } -func testCheckAzureRMAutomationDatetimeVariableExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMAutomationVariableDateTimeExists(resourceName string) resource.TestCheckFunc { return testCheckAzureRMAutomationVariableExists(resourceName, "Datetime") } -func testCheckAzureRMAutomationDatetimeVariableDestroy(s *terraform.State) error { +func testCheckAzureRMAutomationVariableDateTimeDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "Datetime") } -func testAccAzureRMAutomationDatetimeVariable_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableDateTime_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -132,7 +132,7 @@ resource "azurerm_automation_variable_datetime" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAutomationDatetimeVariable_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableDateTime_complete(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" diff --git a/azurerm/resource_arm_automation_variable_int_test.go b/azurerm/resource_arm_automation_variable_int_test.go index 62efa24bbc2b..4cb43fb41cd3 100644 --- a/azurerm/resource_arm_automation_variable_int_test.go +++ b/azurerm/resource_arm_automation_variable_int_test.go @@ -9,7 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { +func TestAccAzureRMAutomationVariableInt_basic(t *testing.T) { resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -17,12 +17,12 @@ func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationIntVariableExists(resourceName), + testCheckAzureRMAutomationVariableIntExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "1234"), ), }, @@ -35,7 +35,7 @@ func TestAccAzureRMAutomationIntVariable_basic(t *testing.T) { }) } -func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { +func TestAccAzureRMAutomationVariableInt_complete(t *testing.T) { resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -43,12 +43,12 @@ func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationIntVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableInt_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationIntVariableExists(resourceName), + testCheckAzureRMAutomationVariableIntExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "12345"), ), @@ -62,7 +62,7 @@ func TestAccAzureRMAutomationIntVariable_complete(t *testing.T) { }) } -func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { +func TestAccAzureRMAutomationVariableInt_basicCompleteUpdate(t *testing.T) { resourceName := "azurerm_automation_variable_int.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -70,27 +70,27 @@ func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationIntVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationIntVariableExists(resourceName), + testCheckAzureRMAutomationVariableIntExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "1234"), ), }, { - Config: testAccAzureRMAutomationIntVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableInt_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationIntVariableExists(resourceName), + testCheckAzureRMAutomationVariableIntExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "12345"), ), }, { - Config: testAccAzureRMAutomationIntVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationIntVariableExists(resourceName), + testCheckAzureRMAutomationVariableIntExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "1234"), ), }, @@ -98,15 +98,15 @@ func TestAccAzureRMAutomationIntVariable_basicCompleteUpdate(t *testing.T) { }) } -func testCheckAzureRMAutomationIntVariableExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMAutomationVariableIntExists(resourceName string) resource.TestCheckFunc { return testCheckAzureRMAutomationVariableExists(resourceName, "Int") } -func testCheckAzureRMAutomationIntVariableDestroy(s *terraform.State) error { +func testCheckAzureRMAutomationVariableIntDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "Int") } -func testAccAzureRMAutomationIntVariable_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableInt_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -132,7 +132,7 @@ resource "azurerm_automation_variable_int" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAutomationIntVariable_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableInt_complete(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" diff --git a/azurerm/resource_arm_automation_variable_string_test.go b/azurerm/resource_arm_automation_variable_string_test.go index db5f9138b4c9..403f204811ef 100644 --- a/azurerm/resource_arm_automation_variable_string_test.go +++ b/azurerm/resource_arm_automation_variable_string_test.go @@ -9,7 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) -func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { +func TestAccAzureRMAutomationVariableString_basic(t *testing.T) { resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -17,12 +17,12 @@ func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationStringVariableExists(resourceName), + testCheckAzureRMAutomationVariableStringExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), ), }, @@ -35,7 +35,7 @@ func TestAccAzureRMAutomationStringVariable_basic(t *testing.T) { }) } -func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { +func TestAccAzureRMAutomationVariableString_complete(t *testing.T) { resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -43,12 +43,12 @@ func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationStringVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableString_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationStringVariableExists(resourceName), + testCheckAzureRMAutomationVariableStringExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), ), @@ -62,7 +62,7 @@ func TestAccAzureRMAutomationStringVariable_complete(t *testing.T) { }) } -func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { +func TestAccAzureRMAutomationVariableString_basicCompleteUpdate(t *testing.T) { resourceName := "azurerm_automation_variable_string.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -70,27 +70,27 @@ func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAutomationStringVariableDestroy, + CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationStringVariableExists(resourceName), + testCheckAzureRMAutomationVariableStringExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), ), }, { - Config: testAccAzureRMAutomationStringVariable_complete(ri, location), + Config: testAccAzureRMAutomationVariableString_complete(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationStringVariableExists(resourceName), + testCheckAzureRMAutomationVariableStringExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), ), }, { - Config: testAccAzureRMAutomationStringVariable_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationStringVariableExists(resourceName), + testCheckAzureRMAutomationVariableStringExists(resourceName), resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), ), }, @@ -98,15 +98,15 @@ func TestAccAzureRMAutomationStringVariable_basicCompleteUpdate(t *testing.T) { }) } -func testCheckAzureRMAutomationStringVariableExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMAutomationVariableStringExists(resourceName string) resource.TestCheckFunc { return testCheckAzureRMAutomationVariableExists(resourceName, "String") } -func testCheckAzureRMAutomationStringVariableDestroy(s *terraform.State) error { +func testCheckAzureRMAutomationVariableStringDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "String") } -func testAccAzureRMAutomationStringVariable_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableString_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -132,7 +132,7 @@ resource "azurerm_automation_variable_string" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAutomationStringVariable_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableString_complete(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" From c12c1c4b2e09f764772ad72188850b8c29b84577 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 10 May 2019 15:11:16 -0700 Subject: [PATCH 25/29] Update azurerm/automation_variable.go --- azurerm/automation_variable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index 8a871acb941e..564489483986 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -18,7 +18,7 @@ import ( func parseAzureAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { - return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource) + return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_variable_null\"", resource) } return nil, nil } From 86cda18ce22c873721f6751d49aeecc8afdc3133 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 10 May 2019 15:11:32 -0700 Subject: [PATCH 26/29] Update azurerm/helpers/azure/automation_variable.go --- azurerm/helpers/azure/automation_variable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 042206256230..0fa4911002de 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -10,7 +10,7 @@ import ( func ParseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_null_variable" { - return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_null_variable\"", resource) + return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_variable_null\"", resource) } return nil, nil } From b49b77e894923c9dd6e410d0aed8c5f1b1289ad5 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 10 May 2019 15:11:46 -0700 Subject: [PATCH 27/29] Update azurerm/automation_variable.go --- azurerm/automation_variable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/automation_variable.go b/azurerm/automation_variable.go index 564489483986..6f04a19e9c13 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/automation_variable.go @@ -17,7 +17,7 @@ import ( func parseAzureAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { - if resource != "azurerm_automation_null_variable" { + if resource != "azurerm_automation_variable_null" { return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_variable_null\"", resource) } return nil, nil From d8dc65ca41b5c4926646ebcc4405b94643c3d40b Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Fri, 10 May 2019 15:12:23 -0700 Subject: [PATCH 28/29] Update azurerm/helpers/azure/automation_variable.go --- azurerm/helpers/azure/automation_variable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/azure/automation_variable.go b/azurerm/helpers/azure/automation_variable.go index 0fa4911002de..906b62c1b0ed 100644 --- a/azurerm/helpers/azure/automation_variable.go +++ b/azurerm/helpers/azure/automation_variable.go @@ -9,7 +9,7 @@ import ( func ParseAzureRmAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { - if resource != "azurerm_automation_null_variable" { + if resource != "azurerm_automation_variable_null" { return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_variable_null\"", resource) } return nil, nil From 3afaddc61805f237cb089a5a294af9f68e8eeeef Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 10 May 2019 15:20:49 -0700 Subject: [PATCH 29/29] fixed datasource doc file names and TOC --- website/azurerm.erb | 16 ++++++++-------- ...wn => automation_variable_bool.html.markdown} | 2 +- ...> automation_variable_datetime.html.markdown} | 2 +- ...own => automation_variable_int.html.markdown} | 2 +- ... => automation_variable_string.html.markdown} | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename website/docs/d/{automation_bool_variable.html.markdown => automation_variable_bool.html.markdown} (95%) rename website/docs/d/{automation_datetime_variable.html.markdown => automation_variable_datetime.html.markdown} (95%) rename website/docs/d/{automation_int_variable.html.markdown => automation_variable_int.html.markdown} (95%) rename website/docs/d/{automation_string_variable.html.markdown => automation_variable_string.html.markdown} (94%) diff --git a/website/azurerm.erb b/website/azurerm.erb index 7cf2b853b750..56df2558ff06 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -95,20 +95,20 @@ azurerm_application_insights - > - azurerm_automation_variable_bool + > + azurerm_automation_variable_bool - > - azurerm_automation_variable_datetime + > + azurerm_automation_variable_datetime - > - azurerm_automation_variable_int + > + azurerm_automation_variable_int - > - azurerm_automation_variable_string + > + azurerm_automation_variable_string > diff --git a/website/docs/d/automation_bool_variable.html.markdown b/website/docs/d/automation_variable_bool.html.markdown similarity index 95% rename from website/docs/d/automation_bool_variable.html.markdown rename to website/docs/d/automation_variable_bool.html.markdown index 238b4a1fd4e8..5821d3da741a 100644 --- a/website/docs/d/automation_bool_variable.html.markdown +++ b/website/docs/d/automation_variable_bool.html.markdown @@ -1,7 +1,7 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_variable_bool" -sidebar_current: "docs-azurerm-datasource-automation-bool-variable" +sidebar_current: "docs-azurerm-datasource-automation-variable-bool" description: |- Gets information about an existing Automation Bool Variable --- diff --git a/website/docs/d/automation_datetime_variable.html.markdown b/website/docs/d/automation_variable_datetime.html.markdown similarity index 95% rename from website/docs/d/automation_datetime_variable.html.markdown rename to website/docs/d/automation_variable_datetime.html.markdown index 4f83d8c98936..b56726739e59 100644 --- a/website/docs/d/automation_datetime_variable.html.markdown +++ b/website/docs/d/automation_variable_datetime.html.markdown @@ -1,7 +1,7 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_variable_datetime" -sidebar_current: "docs-azurerm-datasource-automation-datetime-variable" +sidebar_current: "docs-azurerm-datasource-automation-variable-datetime" description: |- Gets information about an existing Automation Datetime Variable --- diff --git a/website/docs/d/automation_int_variable.html.markdown b/website/docs/d/automation_variable_int.html.markdown similarity index 95% rename from website/docs/d/automation_int_variable.html.markdown rename to website/docs/d/automation_variable_int.html.markdown index b293e861dbeb..bcaf530303bc 100644 --- a/website/docs/d/automation_int_variable.html.markdown +++ b/website/docs/d/automation_variable_int.html.markdown @@ -1,7 +1,7 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_variable_int" -sidebar_current: "docs-azurerm-datasource-automation-int-variable" +sidebar_current: "docs-azurerm-datasource-automation-variable-int" description: |- Gets information about an existing Automation Int Variable --- diff --git a/website/docs/d/automation_string_variable.html.markdown b/website/docs/d/automation_variable_string.html.markdown similarity index 94% rename from website/docs/d/automation_string_variable.html.markdown rename to website/docs/d/automation_variable_string.html.markdown index 1702a355f597..e14aed9d18a5 100644 --- a/website/docs/d/automation_string_variable.html.markdown +++ b/website/docs/d/automation_variable_string.html.markdown @@ -1,7 +1,7 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automation_variable_string" -sidebar_current: "docs-azurerm-datasource-automation-string-variable" +sidebar_current: "docs-azurerm-datasource-automation-variable-string" description: |- Gets information about an existing Automation String Variable ---