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

Support outbound type migration in aks service #22854

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func resourceApiManagementProductTagCreate(d *pluginsdk.ResourceData, meta inter
if err != nil {
return fmt.Errorf(" creating product tag (id : %s): %+v", id, err)
}
d.SetId(*resp.ID)
tagID, err := parse.TagID(*resp.ID)
if err != nil {
return fmt.Errorf(" creating product tag (id : %s): %+v", id, err)
}
d.SetId(tagID.ID())

return resourceApiManagementProductTagRead(d, meta)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization" // nolint: staticcheck
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -158,7 +159,11 @@ func dataSourceArmRoleDefinitionRead(d *pluginsdk.ResourceData, meta interface{}
if role.ID == nil {
return fmt.Errorf("returned role had a nil ID (id %q, scope %q, name %q)", defId, scope, name)
}
d.SetId(*role.ID)
roleID, err := parse.RoleDefinitionId(*role.ID)
if err != nil {
return fmt.Errorf("failed to parse roleID: %+v", err)
}
d.SetId(roleID.RoleID)

if props := role.RoleDefinitionProperties; props != nil {
d.Set("name", props.RoleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func TestAccKubernetesCluster_outboundTypeLoadBalancer(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.outboundTypeLoadBalancerConfig(data),
Config: r.outboundTypeLoadBalancerConfig(data, data.RandomInteger),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -355,13 +355,37 @@ func TestAccKubernetesCluster_outboundTypeLoadBalancer(t *testing.T) {
})
}

func TestAccKubernetesCluster_outboundTypeMigration(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
index := data.RandomInteger
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.outboundTypeLoadBalancerConfig(data, index),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.natGatewayProfileConfig(data, index, 3, 10),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("network_profile.outbound_type").HasValue("managedNATGateway"),
),
},
data.ImportStep(),
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.natGatewayProfileConfig(data, 3, 10),
Config: r.natGatewayProfileConfig(data, index, 3, 10),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("network_profile.0.nat_gateway_profile.0.managed_outbound_ip_count").HasValue("3"),
Expand All @@ -372,7 +396,7 @@ func TestAccKubernetesCluster_natGatewayProfile(t *testing.T) {
data.ImportStep(),

{
Config: r.natGatewayProfileConfig(data, 4, 5),
Config: r.natGatewayProfileConfig(data, index, 4, 5),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("network_profile.0.nat_gateway_profile.0.managed_outbound_ip_count").HasValue("4"),
Expand Down Expand Up @@ -1744,7 +1768,7 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) natGatewayProfileConfig(data acceptance.TestData, ipCount int, idleTimeOut int) string {
func (KubernetesClusterResource) natGatewayProfileConfig(data acceptance.TestData, index int, ipCount int, idleTimeOut int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -1868,7 +1892,7 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) outboundTypeLoadBalancerConfig(data acceptance.TestData) string {
func (KubernetesClusterResource) outboundTypeLoadBalancerConfig(data acceptance.TestData, index int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -1905,7 +1929,7 @@ resource "azurerm_kubernetes_cluster" "test" {
outbound_type = "loadBalancer"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
`, index, data.Locations.Primary, index, index)
}

func (KubernetesClusterResource) privateClusterConfig(data acceptance.TestData, enablePrivateCluster bool) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
"outbound_type": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
Default: string(managedclusters.OutboundTypeLoadBalancer),
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.OutboundTypeLoadBalancer),
Expand Down Expand Up @@ -2041,7 +2041,14 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("both `loadBalancerProfile` and `natGatewayProfile` are nil in Azure")
}

if key := "network_profile.outbound_type"; d.HasChange(key) {
outboundTypeStr := d.Get(key).(string)
outboundType := managedclusters.OutboundType(outboundTypeStr)
existing.Model.Properties.NetworkProfile.OutboundType = &outboundType
}

if networkProfile.LoadBalancerProfile != nil {

loadBalancerProfile := *networkProfile.LoadBalancerProfile

if key := "network_profile.0.load_balancer_profile.0.effective_outbound_ips"; d.HasChange(key) {
Expand Down