1
1
package argocd
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"testing"
6
7
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9
11
)
10
12
11
13
func TestAccArgoCDApplication (t * testing.T ) {
@@ -190,6 +192,27 @@ ingress:
190
192
),
191
193
),
192
194
},
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
+ },
193
216
},
194
217
})
195
218
}
@@ -482,9 +505,9 @@ resource "argocd_application" "ignore_differences" {
482
505
}
483
506
484
507
ignore_difference {
485
- group = "apps"
486
- kind = "Deployment"
487
- json_pointers = ["/spec/replicas"]
508
+ group = "apps"
509
+ kind = "Deployment"
510
+ json_pointers = ["/spec/replicas"]
488
511
}
489
512
490
513
ignore_difference {
@@ -500,3 +523,64 @@ resource "argocd_application" "ignore_differences" {
500
523
}
501
524
` , name )
502
525
}
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