373 lines
10 KiB
Go
373 lines
10 KiB
Go
package azurerm
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAzureRMContainerService_orchestrationPlatformValidation(t *testing.T) {
|
|
cases := []struct {
|
|
Value string
|
|
ErrCount int
|
|
}{
|
|
{Value: "DCOS", ErrCount: 0},
|
|
{Value: "Kubernetes", ErrCount: 0},
|
|
{Value: "Swarm", ErrCount: 0},
|
|
{Value: "Mesos", ErrCount: 1},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
_, errors := validateArmContainerServiceOrchestrationPlatform(tc.Value, "azurerm_container_service")
|
|
|
|
if len(errors) != tc.ErrCount {
|
|
t.Fatalf("Expected the Azure RM Container Service Orchestration Platform to trigger a validation error")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_masterProfileCountValidation(t *testing.T) {
|
|
cases := []struct {
|
|
Value int
|
|
ErrCount int
|
|
}{
|
|
{Value: 0, ErrCount: 1},
|
|
{Value: 1, ErrCount: 0},
|
|
{Value: 2, ErrCount: 1},
|
|
{Value: 3, ErrCount: 0},
|
|
{Value: 4, ErrCount: 1},
|
|
{Value: 5, ErrCount: 0},
|
|
{Value: 6, ErrCount: 1},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
_, errors := validateArmContainerServiceMasterProfileCount(tc.Value, "azurerm_container_service")
|
|
|
|
if len(errors) != tc.ErrCount {
|
|
t.Fatalf("Expected the Azure RM Container Service Master Profile Count to trigger a validation error")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_agentProfilePoolCountValidation(t *testing.T) {
|
|
cases := []struct {
|
|
Value int
|
|
ErrCount int
|
|
}{
|
|
{Value: 0, ErrCount: 1},
|
|
{Value: 1, ErrCount: 0},
|
|
{Value: 2, ErrCount: 0},
|
|
{Value: 99, ErrCount: 0},
|
|
{Value: 100, ErrCount: 0},
|
|
{Value: 101, ErrCount: 1},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
_, errors := validateArmContainerServiceAgentPoolProfileCount(tc.Value, "azurerm_container_service")
|
|
|
|
if len(errors) != tc.ErrCount {
|
|
t.Fatalf("Expected the Azure RM Container Service Agent Pool Profile Count to trigger a validation error")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_dcosBasic(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMContainerService_dcosBasic, ri, ri, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMContainerServiceDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMContainerServiceExists("azurerm_container_service.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_kubernetesBasic(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMContainerService_kubernetesBasic, ri, ri, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMContainerServiceDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMContainerServiceExists("azurerm_container_service.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_kubernetesComplete(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMContainerService_kubernetesComplete, ri, ri, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMContainerServiceDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMContainerServiceExists("azurerm_container_service.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAzureRMContainerService_swarmBasic(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
config := fmt.Sprintf(testAccAzureRMContainerService_swarmBasic, ri, ri, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckAzureRMContainerServiceDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: config,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testCheckAzureRMContainerServiceExists("azurerm_container_service.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
var testAccAzureRMContainerService_dcosBasic = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestRG-%d"
|
|
location = "East US"
|
|
}
|
|
|
|
resource "azurerm_container_service" "test" {
|
|
name = "acctestcontservice%d"
|
|
location = "${azurerm_resource_group.test.location}"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
orchestration_platform = "DCOS"
|
|
|
|
master_profile {
|
|
count = 1
|
|
dns_prefix = "acctestmaster%d"
|
|
}
|
|
|
|
linux_profile {
|
|
admin_username = "acctestuser%d"
|
|
|
|
ssh_key {
|
|
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld"
|
|
}
|
|
}
|
|
|
|
agent_pool_profile {
|
|
name = "default"
|
|
count = 1
|
|
dns_prefix = "acctestagent%d"
|
|
vm_size = "Standard_A0"
|
|
}
|
|
|
|
diagnostics_profile {
|
|
enabled = false
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMContainerService_kubernetesBasic = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestRG-%d"
|
|
location = "East US"
|
|
}
|
|
|
|
resource "azurerm_container_service" "test" {
|
|
name = "acctestcontservice%d"
|
|
location = "${azurerm_resource_group.test.location}"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
orchestration_platform = "Kubernetes"
|
|
|
|
master_profile {
|
|
count = 1
|
|
dns_prefix = "acctestmaster%d"
|
|
}
|
|
|
|
linux_profile {
|
|
admin_username = "acctestuser%d"
|
|
|
|
ssh_key {
|
|
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld"
|
|
}
|
|
}
|
|
|
|
agent_pool_profile {
|
|
name = "default"
|
|
count = 1
|
|
dns_prefix = "acctestagent%d"
|
|
vm_size = "Standard_A0"
|
|
}
|
|
|
|
service_principal {
|
|
client_id = "00000000-0000-0000-0000-000000000000"
|
|
client_secret = "00000000000000000000000000000000"
|
|
}
|
|
|
|
diagnostics_profile {
|
|
enabled = false
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMContainerService_kubernetesComplete = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestRG-%d"
|
|
location = "East US"
|
|
}
|
|
|
|
resource "azurerm_container_service" "test" {
|
|
name = "acctestcontservice%d"
|
|
location = "${azurerm_resource_group.test.location}"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
orchestration_platform = "Kubernetes"
|
|
|
|
master_profile {
|
|
count = 1
|
|
dns_prefix = "acctestmaster%d"
|
|
}
|
|
|
|
linux_profile {
|
|
admin_username = "acctestuser%d"
|
|
|
|
ssh_key {
|
|
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld"
|
|
}
|
|
}
|
|
|
|
agent_pool_profile {
|
|
name = "default"
|
|
count = 1
|
|
dns_prefix = "acctestagent%d"
|
|
vm_size = "Standard_A0"
|
|
}
|
|
|
|
service_principal {
|
|
client_id = "00000000-0000-0000-0000-000000000000"
|
|
client_secret = "00000000000000000000000000000000"
|
|
}
|
|
|
|
diagnostics_profile {
|
|
enabled = false
|
|
}
|
|
|
|
tags {
|
|
you = "me"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAzureRMContainerService_swarmBasic = `
|
|
resource "azurerm_resource_group" "test" {
|
|
name = "acctestRG-%d"
|
|
location = "East US"
|
|
}
|
|
|
|
resource "azurerm_container_service" "test" {
|
|
name = "acctestcontservice%d"
|
|
location = "${azurerm_resource_group.test.location}"
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
orchestration_platform = "Swarm"
|
|
|
|
master_profile {
|
|
count = 1
|
|
dns_prefix = "acctestmaster%d"
|
|
}
|
|
|
|
linux_profile {
|
|
admin_username = "acctestuser%d"
|
|
|
|
ssh_key {
|
|
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld"
|
|
}
|
|
}
|
|
|
|
agent_pool_profile {
|
|
name = "default"
|
|
count = 1
|
|
dns_prefix = "acctestagent%d"
|
|
vm_size = "Standard_A0"
|
|
}
|
|
|
|
diagnostics_profile {
|
|
enabled = false
|
|
}
|
|
}
|
|
`
|
|
|
|
func testCheckAzureRMContainerServiceExists(name string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
// Ensure we have enough information in state to look up in API
|
|
rs, ok := s.RootModule().Resources[name]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", name)
|
|
}
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
if !hasResourceGroup {
|
|
return fmt.Errorf("Bad: no resource group found in state for Container Service Instance: %s", name)
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).containerServicesClient
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
if err != nil {
|
|
return fmt.Errorf("Bad: Get on containerServicesClient: %s", err)
|
|
}
|
|
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
return fmt.Errorf("Bad: Container Service Instance %q (resource group: %q) does not exist", name, resourceGroup)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testCheckAzureRMContainerServiceDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*ArmClient).containerServicesClient
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "azurerm_container_service" {
|
|
continue
|
|
}
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusNotFound {
|
|
return fmt.Errorf("Container Service Instance still exists:\n%#v", resp)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|