-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timezone
field to Virtual Machine (Windows Configuration)
#1265
Changes from 12 commits
a93f50b
e5ded08
18f8a0f
dddcff6
ca106c2
9a9f793
a01fcf3
54bcf17
fd5e54b
1969f35
3621a38
0d72242
7575a7a
6a55d7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ package azurerm | |
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
@@ -68,3 +70,106 @@ func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { | |
|
||
return nil | ||
} | ||
|
||
func TestAccAzureRMVirtualMachine_winTimeZone(t *testing.T) { | ||
resourceName := "azurerm_virtual_machine.test" | ||
var vm compute.VirtualMachine | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMVirtualMachine_winTimeZone(ri, testLocation()) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMVirtualMachineDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), | ||
resource.TestCheckResourceAttr(resourceName, "os_profile_windows_config.2277357006.timezone", "Pacific Standard Time"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAzureRMVirtualMachine_winTimeZone(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_virtual_network" "test" { | ||
name = "acctvn-%d" | ||
address_space = ["10.0.0.0/16"] | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
|
||
resource "azurerm_subnet" "test" { | ||
name = "acctsub-%d" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
virtual_network_name = "${azurerm_virtual_network.test.name}" | ||
address_prefix = "10.0.2.0/24" | ||
} | ||
|
||
resource "azurerm_network_interface" "test" { | ||
name = "acctni-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
|
||
ip_configuration { | ||
name = "testconfiguration1" | ||
subnet_id = "${azurerm_subnet.test.id}" | ||
private_ip_address_allocation = "dynamic" | ||
} | ||
} | ||
|
||
resource "azurerm_storage_account" "test" { | ||
name = "accsa%d" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
location = "${azurerm_resource_group.test.location}" | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
} | ||
|
||
resource "azurerm_storage_container" "test" { | ||
name = "vhds" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
storage_account_name = "${azurerm_storage_account.test.name}" | ||
container_access_type = "private" | ||
} | ||
|
||
resource "azurerm_virtual_machine" "test" { | ||
name = "acctvm-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
network_interface_ids = ["${azurerm_network_interface.test.id}"] | ||
vm_size = "Standard_D1_v2" | ||
|
||
storage_image_reference { | ||
publisher = "MicrosoftWindowsServer" | ||
offer = "WindowsServer" | ||
sku = "2012-Datacenter" | ||
version = "latest" | ||
} | ||
|
||
storage_os_disk { | ||
name = "myosdisk1" | ||
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" | ||
caching = "ReadWrite" | ||
create_option = "FromImage" | ||
} | ||
|
||
os_profile { | ||
computer_name = "winhost01" | ||
admin_username = "testadmin" | ||
admin_password = "Password1234!" | ||
} | ||
|
||
os_profile_windows_config { | ||
timezone = "Pacific Standard Time" | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make the spacing consistent here? we use spaces for indentation for terraform configurations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
`, rInt, location, rInt, rInt, rInt, rInt, rInt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
|
||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/satori/uuid" | ||
) | ||
|
||
|
@@ -76,6 +77,122 @@ func validateIso8601Duration() schema.SchemaValidateFunc { | |
} | ||
} | ||
|
||
func validateAzureVirtualMachineTimeZone(acceptEmpty bool) schema.SchemaValidateFunc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is only used in a single place, we can assume this is the case - I'll push a commit to remove this. |
||
// Candidates are listed here: http://jackstromberg.com/2017/01/list-of-time-zones-consumed-by-azure/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a Microsoft source for this information? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. I didn't find any official Azure list. But I tried that list, seems to be the correct one. And of course we don't need to provide the validation here, because the API call will return error. So what is the best practice? Waiting the API to return error code or provide client-side validation? |
||
candidates := []string{ | ||
"Afghanistan Standard Time", | ||
"Alaskan Standard Time", | ||
"Arab Standard Time", | ||
"Arabian Standard Time", | ||
"Arabic Standard Time", | ||
"Argentina Standard Time", | ||
"Atlantic Standard Time", | ||
"AUS Central Standard Time", | ||
"AUS Eastern Standard Time", | ||
"Azerbaijan Standard Time", | ||
"Azores Standard Time", | ||
"Bahia Standard Time", | ||
"Bangladesh Standard Time", | ||
"Belarus Standard Time", | ||
"Canada Central Standard Time", | ||
"Cape Verde Standard Time", | ||
"Caucasus Standard Time", | ||
"Cen. Australia Standard Time", | ||
"Central America Standard Time", | ||
"Central Asia Standard Time", | ||
"Central Brazilian Standard Time", | ||
"Central Europe Standard Time", | ||
"Central European Standard Time", | ||
"Central Pacific Standard Time", | ||
"Central Standard Time (Mexico)", | ||
"Central Standard Time", | ||
"China Standard Time", | ||
"Dateline Standard Time", | ||
"E. Africa Standard Time", | ||
"E. Australia Standard Time", | ||
"E. Europe Standard Time", | ||
"E. South America Standard Time", | ||
"Eastern Standard Time (Mexico)", | ||
"Eastern Standard Time", | ||
"Egypt Standard Time", | ||
"Ekaterinburg Standard Time", | ||
"Fiji Standard Time", | ||
"FLE Standard Time", | ||
"Georgian Standard Time", | ||
"GMT Standard Time", | ||
"Greenland Standard Time", | ||
"Greenwich Standard Time", | ||
"GTB Standard Time", | ||
"Hawaiian Standard Time", | ||
"India Standard Time", | ||
"Iran Standard Time", | ||
"Israel Standard Time", | ||
"Jordan Standard Time", | ||
"Kaliningrad Standard Time", | ||
"Korea Standard Time", | ||
"Libya Standard Time", | ||
"Line Islands Standard Time", | ||
"Magadan Standard Time", | ||
"Mauritius Standard Time", | ||
"Middle East Standard Time", | ||
"Montevideo Standard Time", | ||
"Morocco Standard Time", | ||
"Mountain Standard Time (Mexico)", | ||
"Mountain Standard Time", | ||
"Myanmar Standard Time", | ||
"N. Central Asia Standard Time", | ||
"Namibia Standard Time", | ||
"Nepal Standard Time", | ||
"New Zealand Standard Time", | ||
"Newfoundland Standard Time", | ||
"North Asia East Standard Time", | ||
"North Asia Standard Time", | ||
"Pacific SA Standard Time", | ||
"Pacific Standard Time (Mexico)", | ||
"Pacific Standard Time", | ||
"Pakistan Standard Time", | ||
"Paraguay Standard Time", | ||
"Romance Standard Time", | ||
"Russia Time Zone 10", | ||
"Russia Time Zone 11", | ||
"Russia Time Zone 3", | ||
"Russian Standard Time", | ||
"SA Eastern Standard Time", | ||
"SA Pacific Standard Time", | ||
"SA Western Standard Time", | ||
"Samoa Standard Time", | ||
"SE Asia Standard Time", | ||
"Singapore Standard Time", | ||
"South Africa Standard Time", | ||
"Sri Lanka Standard Time", | ||
"Syria Standard Time", | ||
"Taipei Standard Time", | ||
"Tasmania Standard Time", | ||
"Tokyo Standard Time", | ||
"Tonga Standard Time", | ||
"Turkey Standard Time", | ||
"Ulaanbaatar Standard Time", | ||
"US Eastern Standard Time", | ||
"US Mountain Standard Time", | ||
"UTC", | ||
"UTC+12", | ||
"UTC-02", | ||
"UTC-11", | ||
"Venezuela Standard Time", | ||
"Vladivostok Standard Time", | ||
"W. Australia Standard Time", | ||
"W. Central Africa Standard Time", | ||
"W. Europe Standard Time", | ||
"West Asia Standard Time", | ||
"West Pacific Standard Time", | ||
"Yakutsk Standard Time", | ||
} | ||
if acceptEmpty { | ||
candidates = append(candidates, "") | ||
} | ||
return validation.StringInSlice(candidates, true) | ||
} | ||
|
||
// intBetweenDivisibleBy returns a SchemaValidateFunc which tests if the provided value | ||
// is of type int and is between min and max (inclusive) and is divisible by a given number | ||
func validateIntBetweenDivisibleBy(min, max, divisor int) schema.SchemaValidateFunc { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also needs a state migration to update the
resourceArmVirtualMachineStorageOsProfileWindowsConfigHash
function and a default value (UTC)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Is there any samples? I found one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that'll do as an example, there's a few in the codebase - this value also needs to be added to the Hash function, otherwise this won't be detected as ForceNew for existing Virtual Machines (which is why the state migrations needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.