github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/azurerm/resource_arm_container_service_test.go (about) 1 package azurerm 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/acctest" 9 "github.com/hashicorp/terraform/helper/resource" 10 "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func TestAccAzureRMContainerService_orchestrationPlatformValidation(t *testing.T) { 14 cases := []struct { 15 Value string 16 ErrCount int 17 }{ 18 {Value: "DCOS", ErrCount: 0}, 19 {Value: "Kubernetes", ErrCount: 0}, 20 {Value: "Swarm", ErrCount: 0}, 21 {Value: "Mesos", ErrCount: 1}, 22 } 23 24 for _, tc := range cases { 25 _, errors := validateArmContainerServiceOrchestrationPlatform(tc.Value, "azurerm_container_service") 26 27 if len(errors) != tc.ErrCount { 28 t.Fatalf("Expected the Azure RM Container Service Orchestration Platform to trigger a validation error") 29 } 30 } 31 } 32 33 func TestAccAzureRMContainerService_masterProfileCountValidation(t *testing.T) { 34 cases := []struct { 35 Value int 36 ErrCount int 37 }{ 38 {Value: 0, ErrCount: 1}, 39 {Value: 1, ErrCount: 0}, 40 {Value: 2, ErrCount: 1}, 41 {Value: 3, ErrCount: 0}, 42 {Value: 4, ErrCount: 1}, 43 {Value: 5, ErrCount: 0}, 44 {Value: 6, ErrCount: 1}, 45 } 46 47 for _, tc := range cases { 48 _, errors := validateArmContainerServiceMasterProfileCount(tc.Value, "azurerm_container_service") 49 50 if len(errors) != tc.ErrCount { 51 t.Fatalf("Expected the Azure RM Container Service Master Profile Count to trigger a validation error") 52 } 53 } 54 } 55 56 func TestAccAzureRMContainerService_agentProfilePoolCountValidation(t *testing.T) { 57 cases := []struct { 58 Value int 59 ErrCount int 60 }{ 61 {Value: 0, ErrCount: 1}, 62 {Value: 1, ErrCount: 0}, 63 {Value: 2, ErrCount: 0}, 64 {Value: 99, ErrCount: 0}, 65 {Value: 100, ErrCount: 0}, 66 {Value: 101, ErrCount: 1}, 67 } 68 69 for _, tc := range cases { 70 _, errors := validateArmContainerServiceAgentPoolProfileCount(tc.Value, "azurerm_container_service") 71 72 if len(errors) != tc.ErrCount { 73 t.Fatalf("Expected the Azure RM Container Service Agent Pool Profile Count to trigger a validation error") 74 } 75 } 76 } 77 78 func TestAccAzureRMContainerService_dcosBasic(t *testing.T) { 79 ri := acctest.RandInt() 80 config := fmt.Sprintf(testAccAzureRMContainerService_dcosBasic, ri, ri, ri, ri, ri) 81 82 resource.Test(t, resource.TestCase{ 83 PreCheck: func() { testAccPreCheck(t) }, 84 Providers: testAccProviders, 85 CheckDestroy: testCheckAzureRMContainerServiceDestroy, 86 Steps: []resource.TestStep{ 87 { 88 Config: config, 89 Check: resource.ComposeTestCheckFunc( 90 testCheckAzureRMContainerServiceExists("azurerm_container_service.test"), 91 ), 92 }, 93 }, 94 }) 95 } 96 97 func TestAccAzureRMContainerService_kubernetesBasic(t *testing.T) { 98 ri := acctest.RandInt() 99 config := fmt.Sprintf(testAccAzureRMContainerService_kubernetesBasic, ri, ri, ri, ri, ri) 100 101 resource.Test(t, resource.TestCase{ 102 PreCheck: func() { testAccPreCheck(t) }, 103 Providers: testAccProviders, 104 CheckDestroy: testCheckAzureRMContainerServiceDestroy, 105 Steps: []resource.TestStep{ 106 { 107 Config: config, 108 Check: resource.ComposeTestCheckFunc( 109 testCheckAzureRMContainerServiceExists("azurerm_container_service.test"), 110 ), 111 }, 112 }, 113 }) 114 } 115 116 func TestAccAzureRMContainerService_kubernetesComplete(t *testing.T) { 117 ri := acctest.RandInt() 118 config := fmt.Sprintf(testAccAzureRMContainerService_kubernetesComplete, ri, ri, ri, ri, ri) 119 120 resource.Test(t, resource.TestCase{ 121 PreCheck: func() { testAccPreCheck(t) }, 122 Providers: testAccProviders, 123 CheckDestroy: testCheckAzureRMContainerServiceDestroy, 124 Steps: []resource.TestStep{ 125 { 126 Config: config, 127 Check: resource.ComposeTestCheckFunc( 128 testCheckAzureRMContainerServiceExists("azurerm_container_service.test"), 129 ), 130 }, 131 }, 132 }) 133 } 134 135 func TestAccAzureRMContainerService_swarmBasic(t *testing.T) { 136 ri := acctest.RandInt() 137 config := fmt.Sprintf(testAccAzureRMContainerService_swarmBasic, ri, ri, ri, ri, ri) 138 139 resource.Test(t, resource.TestCase{ 140 PreCheck: func() { testAccPreCheck(t) }, 141 Providers: testAccProviders, 142 CheckDestroy: testCheckAzureRMContainerServiceDestroy, 143 Steps: []resource.TestStep{ 144 { 145 Config: config, 146 Check: resource.ComposeTestCheckFunc( 147 testCheckAzureRMContainerServiceExists("azurerm_container_service.test"), 148 ), 149 }, 150 }, 151 }) 152 } 153 154 var testAccAzureRMContainerService_dcosBasic = ` 155 resource "azurerm_resource_group" "test" { 156 name = "acctestRG-%d" 157 location = "West US" 158 } 159 160 resource "azurerm_container_service" "test" { 161 name = "acctestcontservice%d" 162 location = "${azurerm_resource_group.test.location}" 163 resource_group_name = "${azurerm_resource_group.test.name}" 164 orchestration_platform = "DCOS" 165 166 master_profile { 167 count = 1 168 dns_prefix = "acctestmaster%d" 169 } 170 171 linux_profile { 172 admin_username = "acctestuser%d" 173 174 ssh_key { 175 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld" 176 } 177 } 178 179 agent_pool_profile { 180 name = "default" 181 count = 1 182 dns_prefix = "acctestagent%d" 183 vm_size = "Standard_A0" 184 } 185 186 diagnostics_profile { 187 enabled = false 188 } 189 } 190 ` 191 192 var testAccAzureRMContainerService_kubernetesBasic = ` 193 resource "azurerm_resource_group" "test" { 194 name = "acctestRG-%d" 195 location = "West US" 196 } 197 198 resource "azurerm_container_service" "test" { 199 name = "acctestcontservice%d" 200 location = "${azurerm_resource_group.test.location}" 201 resource_group_name = "${azurerm_resource_group.test.name}" 202 orchestration_platform = "Kubernetes" 203 204 master_profile { 205 count = 1 206 dns_prefix = "acctestmaster%d" 207 } 208 209 linux_profile { 210 admin_username = "acctestuser%d" 211 212 ssh_key { 213 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld" 214 } 215 } 216 217 agent_pool_profile { 218 name = "default" 219 count = 1 220 dns_prefix = "acctestagent%d" 221 vm_size = "Standard_A0" 222 } 223 224 service_principal { 225 client_id = "00000000-0000-0000-0000-000000000000" 226 client_secret = "00000000000000000000000000000000" 227 } 228 229 diagnostics_profile { 230 enabled = false 231 } 232 } 233 ` 234 235 var testAccAzureRMContainerService_kubernetesComplete = ` 236 resource "azurerm_resource_group" "test" { 237 name = "acctestRG-%d" 238 location = "West US" 239 } 240 241 resource "azurerm_container_service" "test" { 242 name = "acctestcontservice%d" 243 location = "${azurerm_resource_group.test.location}" 244 resource_group_name = "${azurerm_resource_group.test.name}" 245 orchestration_platform = "Kubernetes" 246 247 master_profile { 248 count = 1 249 dns_prefix = "acctestmaster%d" 250 } 251 252 linux_profile { 253 admin_username = "acctestuser%d" 254 255 ssh_key { 256 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld" 257 } 258 } 259 260 agent_pool_profile { 261 name = "default" 262 count = 1 263 dns_prefix = "acctestagent%d" 264 vm_size = "Standard_A0" 265 } 266 267 service_principal { 268 client_id = "00000000-0000-0000-0000-000000000000" 269 client_secret = "00000000000000000000000000000000" 270 } 271 272 diagnostics_profile { 273 enabled = false 274 } 275 276 tags { 277 you = "me" 278 } 279 } 280 ` 281 282 var testAccAzureRMContainerService_swarmBasic = ` 283 resource "azurerm_resource_group" "test" { 284 name = "acctestRG-%d" 285 location = "West US" 286 } 287 288 resource "azurerm_container_service" "test" { 289 name = "acctestcontservice%d" 290 location = "${azurerm_resource_group.test.location}" 291 resource_group_name = "${azurerm_resource_group.test.name}" 292 orchestration_platform = "Swarm" 293 294 master_profile { 295 count = 1 296 dns_prefix = "acctestmaster%d" 297 } 298 299 linux_profile { 300 admin_username = "acctestuser%d" 301 302 ssh_key { 303 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld" 304 } 305 } 306 307 agent_pool_profile { 308 name = "default" 309 count = 1 310 dns_prefix = "acctestagent%d" 311 vm_size = "Standard_A0" 312 } 313 314 diagnostics_profile { 315 enabled = false 316 } 317 } 318 ` 319 320 func testCheckAzureRMContainerServiceExists(name string) resource.TestCheckFunc { 321 return func(s *terraform.State) error { 322 // Ensure we have enough information in state to look up in API 323 rs, ok := s.RootModule().Resources[name] 324 if !ok { 325 return fmt.Errorf("Not found: %s", name) 326 } 327 328 name := rs.Primary.Attributes["name"] 329 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 330 if !hasResourceGroup { 331 return fmt.Errorf("Bad: no resource group found in state for Container Service Instance: %s", name) 332 } 333 334 conn := testAccProvider.Meta().(*ArmClient).containerServicesClient 335 336 resp, err := conn.Get(resourceGroup, name) 337 if err != nil { 338 return fmt.Errorf("Bad: Get on containerServicesClient: %s", err) 339 } 340 341 if resp.StatusCode == http.StatusNotFound { 342 return fmt.Errorf("Bad: Container Service Instance %q (resource group: %q) does not exist", name, resourceGroup) 343 } 344 345 return nil 346 } 347 } 348 349 func testCheckAzureRMContainerServiceDestroy(s *terraform.State) error { 350 conn := testAccProvider.Meta().(*ArmClient).containerServicesClient 351 352 for _, rs := range s.RootModule().Resources { 353 if rs.Type != "azurerm_container_service" { 354 continue 355 } 356 357 name := rs.Primary.Attributes["name"] 358 resourceGroup := rs.Primary.Attributes["resource_group_name"] 359 360 resp, err := conn.Get(resourceGroup, name) 361 362 if err != nil { 363 return nil 364 } 365 366 if resp.StatusCode != http.StatusNotFound { 367 return fmt.Errorf("Container Service Instance still exists:\n%#v", resp) 368 } 369 } 370 371 return nil 372 }