Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - maintenance_window_* added (#21760)
Browse files Browse the repository at this point in the history
* `azurerm_kubernetes_cluster` - `maintenance_window_*` added

* Remodeling

* Fix RelativeMonthly frequency

* Some extra validation

* make terrafmt

* Update internal/services/containers/kubernetes_cluster_resource.go

* Update internal/services/containers/kubernetes_cluster_resource.go

* Duration as int

* Duration as int 2

* Prevent duration == 0

* Make duration required

* Fix

* Make start_date computed

* fix

* Fixx

* Merge maps..

* Complete tests

* Format start/end

* All dates to RFC3339

* Test fixes

* Fix update test

* }}}}

* Improve clarity

* Fix comments

Co-authored-by: stephybun <[email protected]>

* Add docs

* Spelling fix Saterday

---------

Co-authored-by: stephybun <[email protected]>
  • Loading branch information
aristosvo and stephybun authored Jun 28, 2023
1 parent 532b628 commit b915ee4
Show file tree
Hide file tree
Showing 3 changed files with 774 additions and 20 deletions.
297 changes: 287 additions & 10 deletions internal/services/containers/kubernetes_cluster_other_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,43 @@ func TestAccKubernetesCluster_upgradeChannel(t *testing.T) {
})
}

func TestAccKubernetesCluster_basicMaintenanceConfig(t *testing.T) {
func TestAccKubernetesCluster_basicMaintenanceConfigAutoUpgrade(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicMaintenanceConfig(data),
Config: r.basicMaintenanceConfigAutoUpgrade(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_basicMaintenanceConfigDefault(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicMaintenanceConfigDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_basicMaintenanceConfigNodeOs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicMaintenanceConfigNodeOs(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -529,13 +559,43 @@ func TestAccKubernetesCluster_capacityReservationGroup(t *testing.T) {
})
}

func TestAccKubernetesCluster_completeMaintenanceConfig(t *testing.T) {
func TestAccKubernetesCluster_completeMaintenanceConfigAutoUpgrade(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeMaintenanceConfig(data),
Config: r.completeMaintenanceConfigAutoUpgrade(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_completeMaintenanceConfigDefault(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeMaintenanceConfigDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_completeMaintenanceConfigNodeOs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.completeMaintenanceConfigNodeOs(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -550,21 +610,64 @@ func TestAccKubernetesCluster_updateMaintenanceConfig(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicMaintenanceConfig(data),
Config: r.basicMaintenanceConfigDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.completeMaintenanceConfig(data),
Config: r.completeMaintenanceConfigDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicMaintenanceConfig(data),
Config: r.basicMaintenanceConfigDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicMaintenanceConfigAutoUpgrade(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.completeMaintenanceConfigAutoUpgrade(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicMaintenanceConfigAutoUpgrade(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),

{
Config: r.basicMaintenanceConfigNodeOs(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.completeMaintenanceConfigNodeOs(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basicMaintenanceConfigNodeOs(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -1979,7 +2082,43 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, controlPlaneVersion, upgradeChannel)
}

func (KubernetesClusterResource) basicMaintenanceConfig(data acceptance.TestData) string {
func (KubernetesClusterResource) basicMaintenanceConfigAutoUpgrade(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
maintenance_window_auto_upgrade {
frequency = "Weekly"
interval = 1
day_of_week = "Monday"
start_time = "07:00"
utc_offset = "+01:00"
duration = 8
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) basicMaintenanceConfigDefault(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -2013,6 +2152,41 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) basicMaintenanceConfigNodeOs(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
maintenance_window_node_os {
frequency = "Daily"
interval = 1
start_time = "07:00"
utc_offset = "+01:00"
duration = 16
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) capacityReservationGroup(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -2077,7 +2251,55 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (KubernetesClusterResource) completeMaintenanceConfig(data acceptance.TestData) string {
func (KubernetesClusterResource) completeMaintenanceConfigAutoUpgrade(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
maintenance_window_auto_upgrade {
frequency = "RelativeMonthly"
interval = 2
duration = 8
day_of_week = "Monday"
week_index = "First"
start_time = "07:00"
utc_offset = "+01:00"
start_date = "2023-11-26T00:00:00Z"
not_allowed {
end = "2023-11-30T00:00:00Z"
start = "2023-11-26T00:00:00Z"
}
not_allowed {
end = "2023-12-30T00:00:00Z"
start = "2023-12-26T00:00:00Z"
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) completeMaintenanceConfigDefault(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -2115,9 +2337,64 @@ resource "azurerm_kubernetes_cluster" "test" {
hours = [1, 2]
}
allowed {
day = "Sunday"
day = "Thursday"
hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
}
allowed {
day = "Friday"
hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
}
allowed {
day = "Saturday"
hours = [10, 11, 12, 13, 14, 15, 16]
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) completeMaintenanceConfigNodeOs(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
maintenance_window_node_os {
frequency = "AbsoluteMonthly"
interval = 1
duration = 9
day_of_month = 5
start_time = "07:00"
utc_offset = "+01:00"
start_date = "2023-11-26T00:00:00Z"
not_allowed {
end = "2023-11-30T00:00:00Z"
start = "2023-11-26T00:00:00Z"
}
not_allowed {
end = "2023-12-30T00:00:00Z"
start = "2023-12-26T00:00:00Z"
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand Down
Loading

0 comments on commit b915ee4

Please sign in to comment.