Skip to content

Commit

Permalink
azurerm_kubernetes_flux_configuration - fix updating kustomizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Jan 24, 2025
1 parent ce9d7aa commit e063422
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit e063422

Please sign in to comment.