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

azurerm_kubernetes_flux_configuration - fix updating kustomizations #28590

Merged
merged 1 commit into from
Jan 27, 2025
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
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)
}
Loading