11package argocd
22
33import (
4+ "context"
45 "fmt"
56 "testing"
67
78 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
89 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
911)
1012
1113func TestAccArgoCDApplication (t * testing.T ) {
@@ -190,6 +192,27 @@ ingress:
190192 ),
191193 ),
192194 },
195+ {
196+ SkipFunc : testAccSkipFeatureIgnoreDiffJQPathExpressions ,
197+ Config : testAccArgoCDApplicationIgnoreDiffJQPathExpressions (
198+ acctest .RandomWithPrefix ("test-acc" )),
199+ Check : resource .ComposeTestCheckFunc (
200+ resource .TestCheckResourceAttrSet (
201+ "argocd_application.ignore_differences_jqpe" ,
202+ "metadata.0.uid" ,
203+ ),
204+ resource .TestCheckResourceAttr (
205+ "argocd_application.ignore_differences_jqpe" ,
206+ "spec.0.ignore_difference.0.jq_path_expressions.0" ,
207+ ".spec.replicas" ,
208+ ),
209+ resource .TestCheckResourceAttr (
210+ "argocd_application.ignore_differences_jqpe" ,
211+ "spec.0.ignore_difference.1.jq_path_expressions.1" ,
212+ ".spec.template.spec.metadata.labels.somelabel" ,
213+ ),
214+ ),
215+ },
193216 },
194217 })
195218}
@@ -482,9 +505,9 @@ resource "argocd_application" "ignore_differences" {
482505 }
483506
484507 ignore_difference {
485- group = "apps"
486- kind = "Deployment"
487- json_pointers = ["/spec/replicas"]
508+ group = "apps"
509+ kind = "Deployment"
510+ json_pointers = ["/spec/replicas"]
488511 }
489512
490513 ignore_difference {
@@ -500,3 +523,64 @@ resource "argocd_application" "ignore_differences" {
500523}
501524 ` , name )
502525}
526+
527+ func testAccArgoCDApplicationIgnoreDiffJQPathExpressions (name string ) string {
528+ return fmt .Sprintf (`
529+ resource "argocd_application" "ignore_differences_jqpe" {
530+ metadata {
531+ name = "%s"
532+ namespace = "argocd"
533+ labels = {
534+ acceptance = "true"
535+ }
536+ }
537+
538+ spec {
539+ source {
540+ repo_url = "https://charts.bitnami.com/bitnami"
541+ chart = "redis"
542+ target_revision = "15.3.0"
543+ }
544+
545+ destination {
546+ server = "https://kubernetes.default.svc"
547+ namespace = "default"
548+ }
549+
550+ ignore_difference {
551+ group = "apps"
552+ kind = "Deployment"
553+ jq_path_expressions = [".spec.replicas"]
554+ }
555+
556+ ignore_difference {
557+ group = "apps"
558+ kind = "StatefulSet"
559+ name = "someStatefulSet"
560+ jq_path_expressions = [
561+ ".spec.replicas",
562+ ".spec.template.spec.metadata.labels.somelabel",
563+ ]
564+ }
565+ }
566+ }
567+ ` , name )
568+ }
569+
570+ func testAccSkipFeatureIgnoreDiffJQPathExpressions () (bool , error ) {
571+ p , _ := testAccProviders ["argocd" ]()
572+ _ = p .Configure (context .Background (), & terraform.ResourceConfig {})
573+ server := p .Meta ().(* ServerInterface )
574+ err := server .initClients ()
575+ if err != nil {
576+ return false , err
577+ }
578+ featureSupported , err := server .isFeatureSupported (featureIgnoreDiffJQPathExpressions )
579+ if err != nil {
580+ return false , err
581+ }
582+ if ! featureSupported {
583+ return true , nil
584+ }
585+ return false , nil
586+ }
0 commit comments