2015-04-24 18:18:24 +02:00
|
|
|
package azure
|
2015-05-28 00:50:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
"github.com/Azure/azure-sdk-for-go/management"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/management/virtualmachine"
|
2015-05-28 00:50:45 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAzureInstance_basic(t *testing.T) {
|
|
|
|
var dpmt virtualmachine.DeploymentResponse
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2015-06-26 14:48:55 +02:00
|
|
|
CheckDestroy: testAccCheckAzureInstanceDestroyed(""),
|
2015-05-28 00:50:45 +02:00
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureInstance_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
2015-06-26 14:48:55 +02:00
|
|
|
"azure_instance.foo", "", &dpmt),
|
2015-05-28 00:50:45 +02:00
|
|
|
testAccCheckAzureInstanceBasicAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "name", "terraform-test"),
|
2015-06-26 14:48:55 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "hosted_service_name", "terraform-test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "location", "West US"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.2462817782.public_port", "22"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureInstance_separateHostedService(t *testing.T) {
|
|
|
|
var dpmt virtualmachine.DeploymentResponse
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAzureInstanceDestroyed(testAccHostedServiceName),
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureInstance_seperateHostedService,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
|
|
|
"azure_instance.foo", testAccHostedServiceName, &dpmt),
|
|
|
|
testAccCheckAzureInstanceBasicAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "name", "terraform-test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "hosted_service_name", "terraform-testing-service"),
|
2015-05-28 00:50:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "location", "West US"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.2462817782.public_port", "22"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureInstance_advanced(t *testing.T) {
|
|
|
|
var dpmt virtualmachine.DeploymentResponse
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2015-06-26 14:48:55 +02:00
|
|
|
CheckDestroy: testAccCheckAzureInstanceDestroyed(""),
|
2015-05-28 00:50:45 +02:00
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureInstance_advanced,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
2015-06-26 14:48:55 +02:00
|
|
|
"azure_instance.foo", "", &dpmt),
|
2015-05-28 00:50:45 +02:00
|
|
|
testAccCheckAzureInstanceAdvancedAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "name", "terraform-test1"),
|
2015-06-26 14:48:55 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "hosted_service_name", "terraform-test1"),
|
2015-05-28 00:50:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "size", "Basic_A1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "subnet", "subnet1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "virtual_network", "terraform-vnet"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "security_group", "terraform-security-group1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.1814039778.public_port", "3389"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureInstance_update(t *testing.T) {
|
|
|
|
var dpmt virtualmachine.DeploymentResponse
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2015-06-26 14:48:55 +02:00
|
|
|
CheckDestroy: testAccCheckAzureInstanceDestroyed(""),
|
2015-05-28 00:50:45 +02:00
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureInstance_advanced,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
2015-06-26 14:48:55 +02:00
|
|
|
"azure_instance.foo", "", &dpmt),
|
2015-05-28 00:50:45 +02:00
|
|
|
testAccCheckAzureInstanceAdvancedAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "name", "terraform-test1"),
|
2015-06-26 14:48:55 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "hosted_service_name", "terraform-test1"),
|
2015-05-28 00:50:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "size", "Basic_A1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "subnet", "subnet1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "virtual_network", "terraform-vnet"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "security_group", "terraform-security-group1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.1814039778.public_port", "3389"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAzureInstance_update,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
2015-06-26 14:48:55 +02:00
|
|
|
"azure_instance.foo", "", &dpmt),
|
2015-05-28 00:50:45 +02:00
|
|
|
testAccCheckAzureInstanceUpdatedAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "size", "Basic_A2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "security_group", "terraform-security-group2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.1814039778.public_port", "3389"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azure_instance.foo", "endpoint.3713350066.public_port", "5985"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAzureInstanceExists(
|
|
|
|
n string,
|
2015-06-26 14:48:55 +02:00
|
|
|
hostedServiceName string,
|
2015-05-28 00:50:45 +02:00
|
|
|
dpmt *virtualmachine.DeploymentResponse) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No instance ID is set")
|
|
|
|
}
|
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
// if not hosted service was provided; it means that we expect it
|
|
|
|
// to be identical with the name of the instance; which is in the ID.
|
|
|
|
var serviceName string
|
|
|
|
if hostedServiceName == "" {
|
|
|
|
serviceName = rs.Primary.ID
|
|
|
|
} else {
|
|
|
|
serviceName = hostedServiceName
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:54:52 +02:00
|
|
|
vmClient := testAccProvider.Meta().(*Client).vmClient
|
2015-06-26 14:48:55 +02:00
|
|
|
vm, err := vmClient.GetDeployment(serviceName, rs.Primary.ID)
|
2015-05-28 00:50:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if vm.Name != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("Instance not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*dpmt = vm
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAzureInstanceBasicAttributes(
|
|
|
|
dpmt *virtualmachine.DeploymentResponse) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
|
|
|
if dpmt.Name != "terraform-test" {
|
|
|
|
return fmt.Errorf("Bad name: %s", dpmt.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(dpmt.RoleList) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of roles: %d", dpmt.Name, len(dpmt.RoleList))
|
|
|
|
}
|
|
|
|
|
|
|
|
if dpmt.RoleList[0].RoleSize != "Basic_A1" {
|
|
|
|
return fmt.Errorf("Bad size: %s", dpmt.RoleList[0].RoleSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAzureInstanceAdvancedAttributes(
|
|
|
|
dpmt *virtualmachine.DeploymentResponse) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
|
|
|
if dpmt.Name != "terraform-test1" {
|
|
|
|
return fmt.Errorf("Bad name: %s", dpmt.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if dpmt.VirtualNetworkName != "terraform-vnet" {
|
|
|
|
return fmt.Errorf("Bad virtual network: %s", dpmt.VirtualNetworkName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(dpmt.RoleList) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of roles: %d", dpmt.Name, len(dpmt.RoleList))
|
|
|
|
}
|
|
|
|
|
|
|
|
if dpmt.RoleList[0].RoleSize != "Basic_A1" {
|
|
|
|
return fmt.Errorf("Bad size: %s", dpmt.RoleList[0].RoleSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range dpmt.RoleList[0].ConfigurationSets {
|
|
|
|
if c.ConfigurationSetType == virtualmachine.ConfigurationSetTypeNetwork {
|
|
|
|
if len(c.InputEndpoints) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of endpoints %d",
|
|
|
|
dpmt.Name, len(c.InputEndpoints))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.InputEndpoints[0].Name != "RDP" {
|
|
|
|
return fmt.Errorf("Bad endpoint name: %s", c.InputEndpoints[0].Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.InputEndpoints[0].Port != 3389 {
|
|
|
|
return fmt.Errorf("Bad endpoint port: %d", c.InputEndpoints[0].Port)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.SubnetNames) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of associated subnets %d",
|
|
|
|
dpmt.Name, len(c.SubnetNames))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SubnetNames[0] != "subnet1" {
|
|
|
|
return fmt.Errorf("Bad subnet: %s", c.SubnetNames[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.NetworkSecurityGroup != "terraform-security-group1" {
|
|
|
|
return fmt.Errorf("Bad security group: %s", c.NetworkSecurityGroup)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAzureInstanceUpdatedAttributes(
|
|
|
|
dpmt *virtualmachine.DeploymentResponse) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
|
|
|
if dpmt.Name != "terraform-test1" {
|
|
|
|
return fmt.Errorf("Bad name: %s", dpmt.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if dpmt.VirtualNetworkName != "terraform-vnet" {
|
|
|
|
return fmt.Errorf("Bad virtual network: %s", dpmt.VirtualNetworkName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(dpmt.RoleList) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of roles: %d", dpmt.Name, len(dpmt.RoleList))
|
|
|
|
}
|
|
|
|
|
|
|
|
if dpmt.RoleList[0].RoleSize != "Basic_A2" {
|
|
|
|
return fmt.Errorf("Bad size: %s", dpmt.RoleList[0].RoleSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range dpmt.RoleList[0].ConfigurationSets {
|
|
|
|
if c.ConfigurationSetType == virtualmachine.ConfigurationSetTypeNetwork {
|
|
|
|
if len(c.InputEndpoints) != 2 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of endpoints %d",
|
|
|
|
dpmt.Name, len(c.InputEndpoints))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.InputEndpoints[1].Name != "WINRM" {
|
|
|
|
return fmt.Errorf("Bad endpoint name: %s", c.InputEndpoints[1].Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.InputEndpoints[1].Port != 5985 {
|
|
|
|
return fmt.Errorf("Bad endpoint port: %d", c.InputEndpoints[1].Port)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.SubnetNames) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Instance %s has an unexpected number of associated subnets %d",
|
|
|
|
dpmt.Name, len(c.SubnetNames))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SubnetNames[0] != "subnet1" {
|
|
|
|
return fmt.Errorf("Bad subnet: %s", c.SubnetNames[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.NetworkSecurityGroup != "terraform-security-group2" {
|
|
|
|
return fmt.Errorf("Bad security group: %s", c.NetworkSecurityGroup)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
func testAccCheckAzureInstanceDestroyed(hostedServiceName string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "azure_instance" {
|
|
|
|
continue
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No instance ID is set")
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
// if not hosted service was provided; it means that we expect it
|
|
|
|
// to be identical with the name of the instance; which is in the ID.
|
|
|
|
var serviceName string
|
|
|
|
if hostedServiceName == "" {
|
|
|
|
serviceName = rs.Primary.ID
|
|
|
|
} else {
|
|
|
|
serviceName = hostedServiceName
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
_, err := hostedServiceClient.GetHostedService(serviceName)
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Instance %s still exists", rs.Primary.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !management.IsResourceNotFoundError(err) {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
return nil
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAzureInstance_basic = fmt.Sprintf(`
|
|
|
|
resource "azure_instance" "foo" {
|
|
|
|
name = "terraform-test"
|
|
|
|
image = "Ubuntu Server 14.04 LTS"
|
|
|
|
size = "Basic_A1"
|
2015-06-05 16:12:21 +02:00
|
|
|
storage_service_name = "%s"
|
2015-05-28 00:50:45 +02:00
|
|
|
location = "West US"
|
|
|
|
username = "terraform"
|
|
|
|
password = "Pass!admin123"
|
|
|
|
|
|
|
|
endpoint {
|
|
|
|
name = "SSH"
|
|
|
|
protocol = "tcp"
|
|
|
|
public_port = 22
|
|
|
|
private_port = 22
|
|
|
|
}
|
2015-06-05 16:12:21 +02:00
|
|
|
}`, testAccStorageServiceName)
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-26 14:48:55 +02:00
|
|
|
var testAccAzureInstance_seperateHostedService = fmt.Sprintf(`
|
|
|
|
resource "azure_hosted_service" "foo" {
|
|
|
|
name = "%s"
|
|
|
|
location = "West US"
|
|
|
|
ephemeral_contents = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_instance" "foo" {
|
|
|
|
name = "terraform-test"
|
|
|
|
hosted_service_name = "${azure_hosted_service.foo.name}"
|
|
|
|
image = "Ubuntu Server 14.04 LTS"
|
|
|
|
size = "Basic_A1"
|
|
|
|
storage_service_name = "%s"
|
|
|
|
location = "West US"
|
|
|
|
username = "terraform"
|
|
|
|
password = "Pass!admin123"
|
|
|
|
|
|
|
|
endpoint {
|
|
|
|
name = "SSH"
|
|
|
|
protocol = "tcp"
|
|
|
|
public_port = 22
|
|
|
|
private_port = 22
|
|
|
|
}
|
|
|
|
}`, testAccHostedServiceName, testAccStorageServiceName)
|
|
|
|
|
2015-05-28 00:50:45 +02:00
|
|
|
var testAccAzureInstance_advanced = fmt.Sprintf(`
|
|
|
|
resource "azure_virtual_network" "foo" {
|
|
|
|
name = "terraform-vnet"
|
|
|
|
address_space = ["10.1.2.0/24"]
|
|
|
|
location = "West US"
|
|
|
|
|
|
|
|
subnet {
|
|
|
|
name = "subnet1"
|
|
|
|
address_prefix = "10.1.2.0/25"
|
|
|
|
}
|
|
|
|
|
|
|
|
subnet {
|
|
|
|
name = "subnet2"
|
|
|
|
address_prefix = "10.1.2.128/25"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_security_group" "foo" {
|
|
|
|
name = "terraform-security-group1"
|
|
|
|
location = "West US"
|
2015-06-05 16:12:21 +02:00
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
resource "azure_security_group_rule" "foo" {
|
|
|
|
name = "rdp"
|
2015-06-25 20:56:46 +02:00
|
|
|
security_group_names = ["${azure_security_group.foo.name}"]
|
2015-06-05 16:12:21 +02:00
|
|
|
priority = 101
|
|
|
|
source_address_prefix = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
destination_port_range = "3389"
|
2015-06-11 20:26:49 +02:00
|
|
|
action = "Deny"
|
|
|
|
type = "Inbound"
|
2015-06-05 16:12:21 +02:00
|
|
|
protocol = "TCP"
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_instance" "foo" {
|
|
|
|
name = "terraform-test1"
|
|
|
|
image = "Windows Server 2012 R2 Datacenter, April 2015"
|
|
|
|
size = "Basic_A1"
|
2015-06-05 16:12:21 +02:00
|
|
|
storage_service_name = "%s"
|
2015-05-28 00:50:45 +02:00
|
|
|
location = "West US"
|
|
|
|
time_zone = "America/Los_Angeles"
|
|
|
|
subnet = "subnet1"
|
|
|
|
virtual_network = "${azure_virtual_network.foo.name}"
|
|
|
|
security_group = "${azure_security_group.foo.name}"
|
|
|
|
username = "terraform"
|
|
|
|
password = "Pass!admin123"
|
|
|
|
|
|
|
|
endpoint {
|
|
|
|
name = "RDP"
|
|
|
|
protocol = "tcp"
|
|
|
|
public_port = 3389
|
|
|
|
private_port = 3389
|
|
|
|
}
|
2015-06-05 16:12:21 +02:00
|
|
|
}`, testAccStorageServiceName)
|
2015-05-28 00:50:45 +02:00
|
|
|
|
|
|
|
var testAccAzureInstance_update = fmt.Sprintf(`
|
|
|
|
resource "azure_virtual_network" "foo" {
|
|
|
|
name = "terraform-vnet"
|
|
|
|
address_space = ["10.1.2.0/24"]
|
|
|
|
location = "West US"
|
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
subnet {
|
2015-05-28 00:50:45 +02:00
|
|
|
name = "subnet1"
|
2015-06-05 16:12:21 +02:00
|
|
|
address_prefix = "10.1.2.0/25"
|
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
subnet {
|
2015-05-28 00:50:45 +02:00
|
|
|
name = "subnet2"
|
2015-06-05 16:12:21 +02:00
|
|
|
address_prefix = "10.1.2.128/25"
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_security_group" "foo" {
|
|
|
|
name = "terraform-security-group1"
|
|
|
|
location = "West US"
|
2015-06-05 16:12:21 +02:00
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
resource "azure_security_group_rule" "foo" {
|
|
|
|
name = "rdp"
|
2015-06-25 20:56:46 +02:00
|
|
|
security_group_names = ["${azure_security_group.foo.name}"]
|
2015-06-05 16:12:21 +02:00
|
|
|
priority = 101
|
|
|
|
source_address_prefix = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
destination_port_range = "3389"
|
2015-06-11 20:26:49 +02:00
|
|
|
type = "Inbound"
|
|
|
|
action = "Deny"
|
2015-06-05 16:12:21 +02:00
|
|
|
protocol = "TCP"
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_security_group" "bar" {
|
|
|
|
name = "terraform-security-group2"
|
|
|
|
location = "West US"
|
2015-06-05 16:12:21 +02:00
|
|
|
}
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-06-05 16:12:21 +02:00
|
|
|
resource "azure_security_group_rule" "bar" {
|
|
|
|
name = "rdp"
|
2015-06-25 20:56:46 +02:00
|
|
|
security_group_names = ["${azure_security_group.bar.name}"]
|
2015-06-05 16:12:21 +02:00
|
|
|
priority = 101
|
|
|
|
source_address_prefix = "192.168.0.0/24"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
destination_port_range = "3389"
|
2015-06-11 20:26:49 +02:00
|
|
|
type = "Inbound"
|
|
|
|
action = "Deny"
|
2015-06-05 16:12:21 +02:00
|
|
|
protocol = "TCP"
|
2015-05-28 00:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_instance" "foo" {
|
|
|
|
name = "terraform-test1"
|
|
|
|
image = "Windows Server 2012 R2 Datacenter, April 2015"
|
|
|
|
size = "Basic_A2"
|
2015-06-05 16:12:21 +02:00
|
|
|
storage_service_name = "%s"
|
2015-05-28 00:50:45 +02:00
|
|
|
location = "West US"
|
|
|
|
time_zone = "America/Los_Angeles"
|
|
|
|
subnet = "subnet1"
|
|
|
|
virtual_network = "${azure_virtual_network.foo.name}"
|
|
|
|
security_group = "${azure_security_group.bar.name}"
|
|
|
|
username = "terraform"
|
|
|
|
password = "Pass!admin123"
|
|
|
|
|
|
|
|
endpoint {
|
|
|
|
name = "RDP"
|
|
|
|
protocol = "tcp"
|
|
|
|
public_port = 3389
|
|
|
|
private_port = 3389
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint {
|
|
|
|
name = "WINRM"
|
|
|
|
protocol = "tcp"
|
|
|
|
public_port = 5985
|
|
|
|
private_port = 5985
|
|
|
|
}
|
2015-06-05 16:12:21 +02:00
|
|
|
}`, testAccStorageServiceName)
|