Skip to content

Commit

Permalink
Update AKS tests (hashicorp#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev authored Sep 26, 2023
1 parent 7ddc60f commit 0777b81
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/acceptance_tests_aks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
inputs:
location:
description: 'Location'
default: "West Europe"
default: "West US 3"
nodeCount:
description: 'Number of nodes to provision'
default: 2
vmSize:
description: 'The azure machine size for nodes'
default: "Standard_A4_v2"
default: "Standard_A2_v2"
clusterVersion:
description: 'The version of kubernetes'
default: "1.27"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func TestAccKubernetesDataSourceMutatingWebhookConfigurationV1_basic(t *testing.
dataSourceName := fmt.Sprintf("data.%s", resourceName)
name := fmt.Sprintf("acc-test-%v.terraform.io", acctest.RandString(10))
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() {
testAccPreCheck(t)
// AKS sets up some namespaceSelectors and thus we have to skip these tests
skipIfRunningInAks(t)
},
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
10 changes: 10 additions & 0 deletions kubernetes/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ func skipIfNotRunningInEks(t *testing.T) {
}
}

func skipIfRunningInAks(t *testing.T) {
isInAks, err := isRunningInAks()
if err != nil {
t.Fatal(err)
}
if isInAks {
t.Skip("This test cannot be run in AKS cluster")
}
}

func skipIfRunningInEks(t *testing.T) {
isInEks, err := isRunningInEks()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func TestAccKubernetesMutatingWebhookConfiguration_basic(t *testing.T) {
resourceName := "kubernetes_mutating_webhook_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() {
testAccPreCheck(t)
// AKS sets up some namespaceSelectors and thus we have to skip these tests
skipIfRunningInAks(t)
},
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func TestAccKubernetesMutatingWebhookConfigurationV1_basic(t *testing.T) {
resourceName := "kubernetes_mutating_webhook_configuration_v1.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() {
testAccPreCheck(t)
// AKS sets up some namespaceSelectors and thus we have to skip these tests
skipIfRunningInAks(t)
},
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
Expand Down Expand Up @@ -193,8 +197,7 @@ func testAccCheckKubernetesMutatingWebhookConfigurationV1Exists(n string) resour
}

func testAccKubernetesMutatingWebhookConfigurationV1Config_basic(name string) string {
return fmt.Sprintf(`
resource "kubernetes_mutating_webhook_configuration_v1" "test" {
return fmt.Sprintf(`resource "kubernetes_mutating_webhook_configuration_v1" "test" {
metadata {
name = %q
}
Expand Down Expand Up @@ -231,8 +234,7 @@ resource "kubernetes_mutating_webhook_configuration_v1" "test" {
}

func testAccKubernetesMutatingWebhookConfigurationV1Config_modified(name string) string {
return fmt.Sprintf(`
resource "kubernetes_mutating_webhook_configuration_v1" "test" {
return fmt.Sprintf(`resource "kubernetes_mutating_webhook_configuration_v1" "test" {
metadata {
name = %q
}
Expand Down Expand Up @@ -283,8 +285,7 @@ resource "kubernetes_mutating_webhook_configuration_v1" "test" {
}

func testAccKubernetesMutatingWebhookConfigurationV1Config_without_rules(name string) string {
return fmt.Sprintf(`
resource "kubernetes_mutating_webhook_configuration_v1" "test" {
return fmt.Sprintf(`resource "kubernetes_mutating_webhook_configuration_v1" "test" {
metadata {
name = %q
}
Expand Down
13 changes: 9 additions & 4 deletions kubernetes/resource_kubernetes_persistent_volume_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func TestAccKubernetesPersistentVolumeV1_azure_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); skipIfNotRunningInAks(t) },
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
ExternalProviders: testAccExternalProviders,
Expand Down Expand Up @@ -121,7 +120,6 @@ func TestAccKubernetesPersistentVolumeV1_azure_blobStorageDisk(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); skipIfNotRunningInAks(t) },
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
ExternalProviders: testAccExternalProviders,
Expand Down Expand Up @@ -179,7 +177,6 @@ func TestAccKubernetesPersistentVolumeV1_azure_file(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); skipIfNotRunningInAks(t) },
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
ExternalProviders: testAccExternalProviders,
Expand Down Expand Up @@ -987,7 +984,7 @@ func testAccCheckKubernetesPersistentVolumeV1Destroy(s *terraform.State) error {
poll := 1 * time.Second

for _, rs := range s.RootModule().Resources {
if rs.Type != "kubernetes_persistent_volume.test" {
if rs.Type != "kubernetes_persistent_volume_v1.test" {
continue
}
name := rs.Primary.ID
Expand Down Expand Up @@ -1286,13 +1283,15 @@ func testAccKubernetesPersistentVolumeV1Config_azure_managedDisk(name, location
return fmt.Sprintf(`provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = %[1]q
location = %[2]q
tags = {
environment = "terraform-provider-kubernetes-test"
}
}
resource "azurerm_managed_disk" "test" {
name = %[1]q
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -1351,13 +1350,15 @@ func testAccKubernetesPersistentVolumeV1Config_azure_blobStorage(name, location
return fmt.Sprintf(`provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "%s"
location = "%s"
tags = {
environment = "terraform-provider-kubernetes-test"
}
}
resource "azurerm_storage_account" "test" {
name = %[1]q
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -1369,6 +1370,7 @@ resource "azurerm_storage_account" "test" {
environment = "terraform-provider-kubernetes-test"
}
}
resource "azurerm_storage_container" "test" {
name = %[1]q
storage_account_name = azurerm_storage_account.test.name
Expand Down Expand Up @@ -1442,13 +1444,15 @@ func testAccKubernetesPersistentVolumeV1Config_azure_file(name, location string)
return fmt.Sprintf(`provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "%s"
location = "%s"
tags = {
environment = "terraform-provider-kubernetes-test"
}
}
resource "azurerm_storage_account" "test" {
name = %[1]q
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -1462,6 +1466,7 @@ resource "azurerm_storage_account" "test" {
environment = "terraform-provider-kubernetes-test"
}
}
resource "azurerm_storage_share" "test" {
name = %[1]q
storage_account_name = azurerm_storage_account.test.name
Expand Down
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_pod_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestAccKubernetesPodV1_scheduler(t *testing.T) {
PreCheck: func() {
testAccPreCheck(t)
skipIfClusterVersionLessThan(t, "1.22.0")
skipIfRunningInAks(t)
setClusterVersionVar(t, "TF_VAR_scheduler_cluster_version") // should be in format 'vX.Y.Z'
},
ProviderFactories: testAccProviderFactories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func TestAccKubernetesValidatingWebhookConfigurationV1_basic(t *testing.T) {
resourceName := "kubernetes_validating_webhook_configuration_v1.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() {
testAccPreCheck(t)
// AKS sets up some namespaceSelectors and thus we have to skip these tests
skipIfRunningInAks(t)
},
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
Expand Down

0 comments on commit 0777b81

Please sign in to comment.