Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api_server_authorized_ip_ranges deprecated #1254

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/adapters/terraform/azure/container/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ func adaptCluster(resource *terraform.Block) container.KubernetesCluster {
privateClusterEnabledAttr := resource.GetAttribute("private_cluster_enabled")
cluster.EnablePrivateCluster = privateClusterEnabledAttr.AsBoolValueOrDefault(false, resource)

apiServerAuthorizedIPRangesAttr := resource.GetAttribute("api_server_authorized_ip_ranges")
cluster.APIServerAuthorizedIPRanges = apiServerAuthorizedIPRangesAttr.AsStringValues()
if apiServerBlock := resource.GetBlock("api_server_access_profile"); apiServerBlock.IsNotNil() {
authorizedIPRangesAttr := apiServerBlock.GetAttribute("authorized_ip_ranges")
cluster.APIServerAuthorizedIPRanges = authorizedIPRangesAttr.AsStringValues()
}

addonProfileBlock := resource.GetBlock("addon_profile")
if addonProfileBlock.IsNotNil() {
Expand Down
48 changes: 30 additions & 18 deletions internal/adapters/terraform/azure/container/adapt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ func Test_adaptCluster(t *testing.T) {
network_policy = "calico"
}

api_server_authorized_ip_ranges = [
api_server_access_profile {

authorized_ip_ranges = [
"1.2.3.4/32"
]
]

}

addon_profile {
oms_agent {
Expand Down Expand Up @@ -171,10 +175,14 @@ func TestLines(t *testing.T) {
network_profile {
network_policy = "calico"
}

api_server_access_profile {

api_server_authorized_ip_ranges = [
authorized_ip_ranges = [
"1.2.3.4/32"
]
]

}

addon_profile {
oms_agent {
Expand Down Expand Up @@ -202,23 +210,23 @@ func TestLines(t *testing.T) {
assert.Equal(t, 6, cluster.NetworkProfile.NetworkPolicy.GetMetadata().Range().GetStartLine())
assert.Equal(t, 6, cluster.NetworkProfile.NetworkPolicy.GetMetadata().Range().GetEndLine())

assert.Equal(t, 9, cluster.APIServerAuthorizedIPRanges[0].GetMetadata().Range().GetStartLine())
assert.Equal(t, 11, cluster.APIServerAuthorizedIPRanges[0].GetMetadata().Range().GetEndLine())
assert.Equal(t, 11, cluster.APIServerAuthorizedIPRanges[0].GetMetadata().Range().GetStartLine())
assert.Equal(t, 13, cluster.APIServerAuthorizedIPRanges[0].GetMetadata().Range().GetEndLine())

assert.Equal(t, 13, cluster.AddonProfile.Metadata.Range().GetStartLine())
assert.Equal(t, 17, cluster.AddonProfile.Metadata.Range().GetEndLine())
assert.Equal(t, 17, cluster.AddonProfile.Metadata.Range().GetStartLine())
assert.Equal(t, 21, cluster.AddonProfile.Metadata.Range().GetEndLine())

assert.Equal(t, 14, cluster.AddonProfile.OMSAgent.Metadata.Range().GetStartLine())
assert.Equal(t, 16, cluster.AddonProfile.OMSAgent.Metadata.Range().GetEndLine())
assert.Equal(t, 18, cluster.AddonProfile.OMSAgent.Metadata.Range().GetStartLine())
assert.Equal(t, 20, cluster.AddonProfile.OMSAgent.Metadata.Range().GetEndLine())

assert.Equal(t, 15, cluster.AddonProfile.OMSAgent.Enabled.GetMetadata().Range().GetStartLine())
assert.Equal(t, 15, cluster.AddonProfile.OMSAgent.Enabled.GetMetadata().Range().GetEndLine())
assert.Equal(t, 19, cluster.AddonProfile.OMSAgent.Enabled.GetMetadata().Range().GetStartLine())
assert.Equal(t, 19, cluster.AddonProfile.OMSAgent.Enabled.GetMetadata().Range().GetEndLine())

assert.Equal(t, 19, cluster.RoleBasedAccessControl.Metadata.Range().GetStartLine())
assert.Equal(t, 21, cluster.RoleBasedAccessControl.Metadata.Range().GetEndLine())
assert.Equal(t, 23, cluster.RoleBasedAccessControl.Metadata.Range().GetStartLine())
assert.Equal(t, 25, cluster.RoleBasedAccessControl.Metadata.Range().GetEndLine())

assert.Equal(t, 20, cluster.RoleBasedAccessControl.Enabled.GetMetadata().Range().GetStartLine())
assert.Equal(t, 20, cluster.RoleBasedAccessControl.Enabled.GetMetadata().Range().GetEndLine())
assert.Equal(t, 24, cluster.RoleBasedAccessControl.Enabled.GetMetadata().Range().GetStartLine())
assert.Equal(t, 24, cluster.RoleBasedAccessControl.Enabled.GetMetadata().Range().GetEndLine())
}

func TestWithLocals(t *testing.T) {
Expand All @@ -235,9 +243,13 @@ locals {

resource "azurerm_kubernetes_cluster" "aks" {
# not working
api_server_authorized_ip_ranges = local.ip_whitelist
api_server_access_profile {
authorized_ip_ranges = local.ip_whitelist
}
# working
# api_server_authorized_ip_ranges = concat(var.ip_whitelist, split(",", data.azurerm_public_ip.example.ip_address))
api_server_access_profile {
authorized_ip_ranges = concat(var.ip_whitelist, split(",", data.azurerm_public_ip.example.ip_address))
}
}`

modules := tftestutil.CreateModulesFromSource(t, src, ".tf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package container
var terraformLimitAuthorizedIpsGoodExamples = []string{
`
resource "azurerm_kubernetes_cluster" "good_example" {
api_server_authorized_ip_ranges = [
api_server_access_profile {
authorized_ip_ranges = [
"1.2.3.4/32"
]

}

}
`,
}
Expand Down