Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - http_proxy_config supports update (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu authored Oct 31, 2023
1 parent bb31e33 commit 4ad2b98
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,38 @@ func TestAccKubernetesCluster_httpProxyConfig(t *testing.T) {
})
}

func TestAccKubernetesCluster_httpProxyConfigUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
noProxy := "\"localhost\", \"127.0.0.1\", \"mcr.microsoft.com\""
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.httpProxyConfig(data, noProxy),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
ExpectNonEmptyPlan: true,
},
data.ImportStep(),
{
Config: r.httpProxyConfigUpdate(data, noProxy),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
ExpectNonEmptyPlan: true,
},
data.ImportStep(),
{
Config: r.httpProxyConfig(data, noProxy),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
ExpectNonEmptyPlan: true,
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_httpProxyConfigWithTrustedCa(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
Expand Down Expand Up @@ -3191,6 +3223,173 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, currentKubernetesVersion, data.RandomInteger)
}

func (KubernetesClusterResource) httpProxyConfigUpdate(data acceptance.TestData, noProxy string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvirtnet%d"
address_space = ["10.1.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_subnet" "test" {
name = "acctestsubnet%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.1.0.0/24"]
}
resource "azurerm_public_ip" "test_proxy" {
name = "acceptanceTestPublicIp1"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_public_ip" "test_proxy2" {
name = "acceptanceTestPublicIp3"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_public_ip" "test_aks" {
name = "acceptanceTestPublicIp2"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_network_security_group" "test" {
name = "acceptanceTestSecurityGroup1"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
security_rule {
name = "AllowProxyAccessOn8888"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8888"
source_address_prefix = "${azurerm_public_ip.test_aks.ip_address}/32"
destination_address_prefix = "*"
}
}
resource "azurerm_network_interface" "test" {
name = "test-nic%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.test_proxy2.id
}
}
resource "azurerm_network_interface_security_group_association" "test" {
network_interface_id = azurerm_network_interface.test.id
network_security_group_id = azurerm_network_security_group.test.id
}
locals {
custom_data = <<CUSTOM_DATA
#!/bin/sh
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
sudo apt-get update
sudo apt-get install tinyproxy -y
sudo echo "Allow ${azurerm_public_ip.test_aks.ip_address}/32" >> /etc/tinyproxy/tinyproxy.conf
systemctl restart tinyproxy
CUSTOM_DATA
}
resource "azurerm_linux_virtual_machine" "test" {
name = "vm-test-proxy%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_B1s"
admin_username = "adminuser"
admin_password = "P@ssW0RD1234"
custom_data = base64encode(local.custom_data)
disable_password_authentication = false
network_interface_ids = [
azurerm_network_interface.test.id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-focal"
sku = "20_04-lts-gen2"
version = "latest"
}
}
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"
kubernetes_version = "%s"
linux_profile {
admin_username = "acctestuser%d"
ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt [email protected]"
}
}
default_node_pool {
name = "default"
node_count = 2
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "azure"
load_balancer_sku = "standard"
load_balancer_profile {
outbound_ip_address_ids = [azurerm_public_ip.test_aks.id]
}
}
http_proxy_config {
http_proxy = "http://${azurerm_public_ip.test_proxy2.ip_address}:8888/"
https_proxy = "http://${azurerm_public_ip.test_proxy2.ip_address}:8888/"
no_proxy = [%s]
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, currentKubernetesVersion, data.RandomInteger, noProxy)
}

func (KubernetesClusterResource) httpProxyConfig(data acceptance.TestData, noProxy string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -3228,6 +3427,14 @@ resource "azurerm_public_ip" "test_proxy" {
sku = "Standard"
}
resource "azurerm_public_ip" "test_proxy2" {
name = "acceptanceTestPublicIp3"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
allocation_method = "Static"
sku = "Standard"
}
resource "azurerm_public_ip" "test_aks" {
name = "acceptanceTestPublicIp2"
resource_group_name = azurerm_resource_group.test.name
Expand Down
2 changes: 0 additions & 2 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,10 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
"http_proxy": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
},
"https_proxy": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
},
"no_proxy": {
Type: pluginsdk.TypeSet,
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,9 @@ A `workload_autoscaler_profile` block supports the following:

A `http_proxy_config` block supports the following:

* `http_proxy` - (Optional) The proxy address to be used when communicating over HTTP. Changing this forces a new resource to be created.
* `http_proxy` - (Optional) The proxy address to be used when communicating over HTTP.

* `https_proxy` - (Optional) The proxy address to be used when communicating over HTTPS. Changing this forces a new resource to be created.
* `https_proxy` - (Optional) The proxy address to be used when communicating over HTTPS.

* `no_proxy` - (Optional) The list of domains that will not use the proxy for communication.

Expand Down

0 comments on commit 4ad2b98

Please sign in to comment.