Skip to content

Commit a1ebd3f

Browse files
authored
azurerm_kubernetes_flux_configuration - fix updating kustomizations (#28590)
1 parent 96cf711 commit a1ebd3f

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

internal/services/containers/kubernetes_flux_configuration_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,10 @@ func expandKustomizationDefinitionModel(inputList []KustomizationDefinitionModel
904904
outputList := make(map[string]fluxconfiguration.KustomizationDefinition)
905905
for _, v := range inputList {
906906
input := v
907+
// 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
908+
if input.Name == "" {
909+
continue
910+
}
907911
output := fluxconfiguration.KustomizationDefinition{
908912
DependsOn: &input.DependsOn,
909913
Force: &input.Force,

internal/services/containers/kubernetes_flux_configuration_resource_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ func TestAccKubernetesFluxConfiguration_kustomizationPostBuild(t *testing.T) {
210210
})
211211
}
212212

213+
func TestAccKubernetesFluxConfiguration_kustomizationPostBuildUpdate(t *testing.T) {
214+
data := acceptance.BuildTestData(t, "azurerm_kubernetes_flux_configuration", "test")
215+
r := KubernetesFluxConfigurationResource{}
216+
data.ResourceTest(t, r, []acceptance.TestStep{
217+
{
218+
Config: r.kustomizationPostBuild(data),
219+
Check: acceptance.ComposeTestCheckFunc(
220+
check.That(data.ResourceName).ExistsInAzure(r),
221+
),
222+
},
223+
data.ImportStep(),
224+
{
225+
Config: r.kustomizationUpdated(data),
226+
Check: acceptance.ComposeTestCheckFunc(
227+
check.That(data.ResourceName).ExistsInAzure(r),
228+
),
229+
},
230+
data.ImportStep(),
231+
})
232+
}
233+
213234
func (r KubernetesFluxConfigurationResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
214235
id, err := fluxconfiguration.ParseScopedFluxConfigurationID(state.ID)
215236
if err != nil {
@@ -793,3 +814,32 @@ resource "azurerm_kubernetes_flux_configuration" "test" {
793814
}
794815
`, template, data.RandomInteger)
795816
}
817+
818+
func (r KubernetesFluxConfigurationResource) kustomizationUpdated(data acceptance.TestData) string {
819+
template := r.template(data)
820+
return fmt.Sprintf(`
821+
%s
822+
823+
resource "azurerm_kubernetes_flux_configuration" "test" {
824+
name = "acctest-fc-%d"
825+
cluster_id = azurerm_kubernetes_cluster.test.id
826+
namespace = "flux"
827+
828+
git_repository {
829+
url = "https://github.com/Azure/arc-k8s-demo"
830+
reference_type = "branch"
831+
reference_value = "main"
832+
}
833+
834+
kustomizations {
835+
name = "kustomization-1"
836+
path = "./test/path"
837+
wait = false
838+
}
839+
840+
depends_on = [
841+
azurerm_kubernetes_cluster_extension.test
842+
]
843+
}
844+
`, template, data.RandomInteger)
845+
}

0 commit comments

Comments
 (0)