Skip to content

Commit 8043b45

Browse files
authored
fix(510): set server of argocd_cluster resource to required & force_new (#747)
Signed-off-by: Nathanael Liechti <[email protected]>
1 parent 171af0d commit 8043b45

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

argocd/resource_argocd_cluster_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hashicorp/terraform-plugin-framework/types"
1717
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1818
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1920
"k8s.io/client-go/rest"
2021
"k8s.io/client-go/tools/clientcmd"
2122
"k8s.io/client-go/util/homedir"
@@ -366,6 +367,58 @@ func TestAccArgoCDCluster_outsideDeletion(t *testing.T) {
366367
})
367368
}
368369

370+
func TestAccArgoCDCluster_urlUpdate(t *testing.T) {
371+
resource.Test(t, resource.TestCase{
372+
PreCheck: func() { testAccPreCheck(t) },
373+
ProviderFactories: testAccProviders,
374+
Steps: []resource.TestStep{
375+
{
376+
Config: testAccArgoCDClusterBearerToken_urlChange("https://kubernetes.default.svc.cluster.local"),
377+
Check: resource.ComposeTestCheckFunc(
378+
resource.TestCheckResourceAttr(
379+
"argocd_cluster.check_url_change",
380+
"info.0.connection_state.0.status",
381+
"Successful",
382+
),
383+
resource.TestCheckResourceAttrSet(
384+
"argocd_cluster.check_url_change",
385+
"info.0.server_version",
386+
),
387+
resource.TestCheckResourceAttr(
388+
"argocd_cluster.check_url_change",
389+
"config.0.tls_client_config.0.insecure",
390+
strconv.FormatBool(isInsecure()),
391+
),
392+
),
393+
},
394+
{
395+
Config: testAccArgoCDClusterBearerToken_urlChange("https://kubernetes.default"),
396+
ConfigPlanChecks: resource.ConfigPlanChecks{
397+
PreApply: []plancheck.PlanCheck{
398+
plancheck.ExpectResourceAction("argocd_cluster.check_url_change", plancheck.ResourceActionReplace),
399+
},
400+
},
401+
Check: resource.ComposeTestCheckFunc(
402+
resource.TestCheckResourceAttr(
403+
"argocd_cluster.check_url_change",
404+
"info.0.connection_state.0.status",
405+
"Successful",
406+
),
407+
resource.TestCheckResourceAttrSet(
408+
"argocd_cluster.check_url_change",
409+
"info.0.server_version",
410+
),
411+
resource.TestCheckResourceAttr(
412+
"argocd_cluster.check_url_change",
413+
"config.0.tls_client_config.0.insecure",
414+
strconv.FormatBool(isInsecure()),
415+
),
416+
),
417+
},
418+
},
419+
})
420+
}
421+
369422
func TestAccArgoCDCluster_namespacesErrorWhenEmpty(t *testing.T) {
370423
name := acctest.RandString(10)
371424

@@ -523,6 +576,17 @@ resource "argocd_cluster" "cluster_with_no_trailing_slash" {
523576
}`, getConfig(), getConfig())
524577
}
525578

579+
func testAccArgoCDClusterBearerToken_urlChange(url string) string {
580+
return fmt.Sprintf(`
581+
resource "argocd_cluster" "check_url_change" {
582+
server = "%s"
583+
config {
584+
%s
585+
}
586+
}
587+
`, url, getConfig())
588+
}
589+
526590
func testAccArgoCDClusterMetadata_addLabels(clusterName string) string {
527591
return fmt.Sprintf(`
528592
resource "argocd_cluster" "cluster_metadata" {

argocd/schema_cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func clusterSchema() map[string]*schema.Schema {
2828
Type: schema.TypeString,
2929
Description: "Server is the API server URL of the Kubernetes cluster.",
3030
Optional: true,
31+
ForceNew: true,
3132
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
3233
return oldValue == strings.TrimRight(newValue, "/")
3334
},

0 commit comments

Comments
 (0)