Skip to content

Commit

Permalink
chore: Drop "bytes" and "text/template" dependency and use common cod…
Browse files Browse the repository at this point in the history
…e style
  • Loading branch information
mkilchhofer committed Jan 10, 2023
1 parent 4735a7a commit af2d767
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions internal/services/containers/kubernetes_cluster_resource_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package containers_test

import (
"bytes"
"context"
"fmt"
"net/http"
"testing"
"text/template"

"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2022-09-02-preview/agentpools"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2022-09-02-preview/managedclusters"
Expand Down Expand Up @@ -536,20 +534,28 @@ resource "azurerm_kubernetes_cluster" "test" {
}

func (KubernetesClusterResource) azureKeyVaultKms(data acceptance.TestData, controlPlaneVersion string, enabled bool) string {
const hcl = `
kmsBlock := ""
if enabled {
kmsBlock = `
key_management_service {
key_vault_key_id = azurerm_key_vault_key.test.id
}`
}

return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-{{.randomInteger}}"
location = "{{.location}}"
name = "acctestRG-aks-%[1]d"
location = "%[2]s"
}
resource "azurerm_key_vault" "test" {
name = substr("acctest{{.randomInteger}}", 0, 24)
name = substr("acctest%[1]d", 0, 24)
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
tenant_id = data.azurerm_client_config.current.tenant_id
Expand Down Expand Up @@ -580,18 +586,18 @@ resource "azurerm_key_vault_key" "test" {
}
resource "azurerm_user_assigned_identity" "test" {
name = "acctest{{.randomInteger}}"
name = "acctest%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks{{.randomInteger}}"
name = "acctestaks%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
node_resource_group = "${azurerm_resource_group.test.name}-infra"
dns_prefix = "acctestaks{{.randomInteger}}"
kubernetes_version = "{{.controlPlaneVersion}}"
dns_prefix = "acctestaks%[1]d"
kubernetes_version = %[3]q
default_node_pool {
name = "default"
Expand All @@ -603,25 +609,9 @@ resource "azurerm_kubernetes_cluster" "test" {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
{{ if .enabled }}
key_management_service {
key_vault_key_id = azurerm_key_vault_key.test.id
}
{{ end }}
%[4]s
}
`
tpl, _ := template.New("hcl").Parse(hcl)

var tplBuffer bytes.Buffer
tpl.Execute(&tplBuffer, map[string]interface{}{
"enabled": enabled,
"randomInteger": data.RandomInteger,
"location": data.Locations.Primary,
"controlPlaneVersion": controlPlaneVersion,
})

return tplBuffer.String()
`, data.RandomInteger, data.Locations.Primary, controlPlaneVersion, kmsBlock)
}

func (KubernetesClusterResource) storageProfile(data acceptance.TestData, controlPlaneVersion string) string {
Expand Down

0 comments on commit af2d767

Please sign in to comment.