2015-04-24 18:18:24 +02:00
|
|
|
package azure
|
2015-05-28 00:50:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-08-03 22:12:30 +02:00
|
|
|
"math/rand"
|
2015-05-28 00:50:45 +02:00
|
|
|
"testing"
|
2015-08-03 22:12:30 +02:00
|
|
|
"time"
|
2015-05-28 00:50:45 +02:00
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2015-08-03 22:12:30 +02:00
|
|
|
var randInt = rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
|
|
|
var instanceName = fmt.Sprintf("terraform-test-%d", randInt)
|
|
|
|
|
2015-05-28 00:50:45 +02:00
|
|
|
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(
|
2015-08-03 22:12:30 +02:00
|
|
|
"azure_instance.foo", "name", instanceName),
|
2015-06-26 14:48:55 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-08-03 22:12:30 +02:00
|
|
|
"azure_instance.foo", "hosted_service_name", instanceName),
|
2015-06-26 14:48:55 +02:00
|
|
|
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{
|
2015-09-11 20:56:20 +02:00
|
|
|
Config: testAccAzureInstance_separateHostedService,
|
2015-06-26 14:48:55 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAzureInstanceExists(
|
|
|
|
"azure_instance.foo", testAccHostedServiceName, &dpmt),
|
|
|
|
testAccCheckAzureInstanceBasicAttributes(&dpmt),
|
|
|
|
resource.TestCheckResourceAttr(
|
2015-11-19 23:28:24 +01:00
|
|
|
"azure_instance.foo", "name", instanceName),
|
2015-06-26 14:48:55 +02:00
|
|
|
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(
|
2016-01-08 02:38:34 +01:00
|
|
|
"azure_instance.foo", "virtual_network", "terraform-vnet-advanced-test"),
|
2015-05-28 00:50:45 +02:00
|
|
|
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(
|
2016-01-08 02:38:34 +01:00
|
|
|
"azure_instance.foo", "virtual_network", "terraform-vnet-advanced-test"),
|
2015-05-28 00:50:45 +02:00
|
|
|
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 {
|
|
|
|
|
2015-08-03 22:12:30 +02:00
|
|
|
if dpmt.Name != instanceName {
|
2015-05-28 00:50:45 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-01-08 16:15:59 +01:00
|
|
|
if dpmt.VirtualNetworkName != "terraform-vnet-advanced-test" {
|
2015-05-28 00:50:45 +02:00
|
|
|
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" {
|
2015-08-03 22:12:30 +02:00
|
|
|
name = "%s"
|
2015-05-28 00:50:45 +02:00
|
|
|
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-08-03 22:12:30 +02:00
|
|
|
}`, instanceName, testAccStorageServiceName)
|
2015-05-28 00:50:45 +02:00
|
|
|
|
2015-09-11 20:56:20 +02:00
|
|
|
var testAccAzureInstance_separateHostedService = fmt.Sprintf(`
|
2015-06-26 14:48:55 +02:00
|
|
|
resource "azure_hosted_service" "foo" {
|
|
|
|
name = "%s"
|
|
|
|
location = "West US"
|
|
|
|
ephemeral_contents = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azure_instance" "foo" {
|
2015-11-19 23:28:24 +01:00
|
|
|
name = "%s"
|
|
|
|
hosted_service_name = "${azure_hosted_service.foo.name}"
|
2015-06-26 14:48:55 +02:00
|
|
|
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
|
|
|
|
}
|
2015-11-19 23:28:24 +01:00
|
|
|
}`, testAccHostedServiceName, instanceName, testAccStorageServiceName)
|
2015-06-26 14:48:55 +02:00
|
|
|
|
2015-05-28 00:50:45 +02:00
|
|
|
var testAccAzureInstance_advanced = fmt.Sprintf(`
|
|
|
|
resource "azure_virtual_network" "foo" {
|
2016-01-07 20:09:40 +01:00
|
|
|
name = "terraform-vnet-advanced-test"
|
2015-05-28 00:50:45 +02:00
|
|
|
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"
|
2015-10-15 04:34:07 +02:00
|
|
|
image = "Windows Server 2012 R2 Datacenter, September 2015"
|
2015-05-28 00:50:45 +02:00
|
|
|
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" {
|
2016-01-07 20:09:40 +01:00
|
|
|
name = "terraform-vnet-update-test"
|
2015-05-28 00:50:45 +02:00
|
|
|
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" {
|
2016-01-07 20:09:40 +01:00
|
|
|
name = "terraform-security-update-group2"
|
2015-05-28 00:50:45 +02:00
|
|
|
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"
|
2015-10-15 04:34:07 +02:00
|
|
|
image = "Windows Server 2012 R2 Datacenter, September 2015"
|
2015-05-28 00:50:45 +02:00
|
|
|
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)
|