diff --git a/internal/services/containers/kubernetes_flux_configuration_resource.go b/internal/services/containers/kubernetes_flux_configuration_resource.go index e329033675f1..c37398aae2b7 100644 --- a/internal/services/containers/kubernetes_flux_configuration_resource.go +++ b/internal/services/containers/kubernetes_flux_configuration_resource.go @@ -904,6 +904,10 @@ func expandKustomizationDefinitionModel(inputList []KustomizationDefinitionModel outputList := make(map[string]fluxconfiguration.KustomizationDefinition) for _, v := range inputList { input := v + // updated item in a set is considered a new item, and the old item still exists in the set but with empty values, so we need to skip it + if input.Name == "" { + continue + } output := fluxconfiguration.KustomizationDefinition{ DependsOn: &input.DependsOn, Force: &input.Force, diff --git a/internal/services/containers/kubernetes_flux_configuration_resource_test.go b/internal/services/containers/kubernetes_flux_configuration_resource_test.go index e9fa1d9cef88..1994992893ff 100644 --- a/internal/services/containers/kubernetes_flux_configuration_resource_test.go +++ b/internal/services/containers/kubernetes_flux_configuration_resource_test.go @@ -210,6 +210,27 @@ func TestAccKubernetesFluxConfiguration_kustomizationPostBuild(t *testing.T) { }) } +func TestAccKubernetesFluxConfiguration_kustomizationPostBuildUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_flux_configuration", "test") + r := KubernetesFluxConfigurationResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.kustomizationPostBuild(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.kustomizationUpdated(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r KubernetesFluxConfigurationResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := fluxconfiguration.ParseScopedFluxConfigurationID(state.ID) if err != nil { @@ -793,3 +814,32 @@ resource "azurerm_kubernetes_flux_configuration" "test" { } `, template, data.RandomInteger) } + +func (r KubernetesFluxConfigurationResource) kustomizationUpdated(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_kubernetes_flux_configuration" "test" { + name = "acctest-fc-%d" + cluster_id = azurerm_kubernetes_cluster.test.id + namespace = "flux" + + git_repository { + url = "https://github.com/Azure/arc-k8s-demo" + reference_type = "branch" + reference_value = "main" + } + + kustomizations { + name = "kustomization-1" + path = "./test/path" + wait = false + } + + depends_on = [ + azurerm_kubernetes_cluster_extension.test + ] +} +`, template, data.RandomInteger) +}