@@ -2621,3 +2621,197 @@ func TestAccCloudflareRuleset_LogCustomFieldRules(t *testing.T) {
2621
2621
},
2622
2622
})
2623
2623
}
2624
+
2625
+ func TestAccCloudflareRuleset_RedirectRules (t * testing.T ) {
2626
+ resource .Test (t , resource.TestCase {
2627
+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
2628
+ ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
2629
+ Steps : []resource.TestStep {
2630
+ {
2631
+ ConfigFile : config .TestNameFile ("1.tf" ),
2632
+ ConfigVariables : configVariables ,
2633
+ ConfigPlanChecks : resource.ConfigPlanChecks {
2634
+ PreApply : []plancheck.PlanCheck {
2635
+ plancheck .ExpectResourceAction (
2636
+ "cloudflare_ruleset.my_ruleset" ,
2637
+ plancheck .ResourceActionCreate ,
2638
+ ),
2639
+ plancheck .ExpectKnownValue (
2640
+ "cloudflare_ruleset.my_ruleset" ,
2641
+ tfjsonpath .New ("rules" ),
2642
+ knownvalue .ListExact ([]knownvalue.Check {
2643
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2644
+ "action" : knownvalue .StringExact ("redirect" ),
2645
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2646
+ "from_list" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2647
+ "key" : knownvalue .StringExact ("http.request.full_uri" ),
2648
+ "name" : knownvalue .StringExact ("my_list" ),
2649
+ }),
2650
+ "from_value" : knownvalue .Null (),
2651
+ }),
2652
+ }),
2653
+ }),
2654
+ ),
2655
+ },
2656
+ },
2657
+ ConfigStateChecks : []statecheck.StateCheck {
2658
+ statecheck .ExpectKnownValue (
2659
+ "cloudflare_ruleset.my_ruleset" ,
2660
+ tfjsonpath .New ("rules" ),
2661
+ knownvalue .ListExact ([]knownvalue.Check {
2662
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2663
+ "action" : knownvalue .StringExact ("redirect" ),
2664
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2665
+ "from_list" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2666
+ "key" : knownvalue .StringExact ("http.request.full_uri" ),
2667
+ "name" : knownvalue .StringExact ("my_list" ),
2668
+ }),
2669
+ "from_value" : knownvalue .Null (),
2670
+ }),
2671
+ }),
2672
+ }),
2673
+ ),
2674
+ },
2675
+ },
2676
+ {
2677
+ ConfigFile : config .TestNameFile ("2.tf" ),
2678
+ ConfigVariables : configVariables ,
2679
+ ConfigPlanChecks : resource.ConfigPlanChecks {
2680
+ PreApply : []plancheck.PlanCheck {
2681
+ plancheck .ExpectResourceAction (
2682
+ "cloudflare_ruleset.my_ruleset" ,
2683
+ plancheck .ResourceActionReplace ,
2684
+ ),
2685
+ plancheck .ExpectKnownValue (
2686
+ "cloudflare_ruleset.my_ruleset" ,
2687
+ tfjsonpath .New ("rules" ),
2688
+ knownvalue .ListExact ([]knownvalue.Check {
2689
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2690
+ "action" : knownvalue .StringExact ("redirect" ),
2691
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2692
+ "from_list" : knownvalue .Null (),
2693
+ "from_value" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2694
+ "preserve_query_string" : knownvalue .Bool (false ),
2695
+ "status_code" : knownvalue .Null (),
2696
+ "target_url" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2697
+ "value" : knownvalue .StringExact ("https://example.com" ),
2698
+ "expression" : knownvalue .Null (),
2699
+ }),
2700
+ }),
2701
+ }),
2702
+ }),
2703
+ }),
2704
+ ),
2705
+ },
2706
+ },
2707
+ ConfigStateChecks : []statecheck.StateCheck {
2708
+ statecheck .ExpectKnownValue (
2709
+ "cloudflare_ruleset.my_ruleset" ,
2710
+ tfjsonpath .New ("rules" ),
2711
+ knownvalue .ListExact ([]knownvalue.Check {
2712
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2713
+ "action" : knownvalue .StringExact ("redirect" ),
2714
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2715
+ "from_list" : knownvalue .Null (),
2716
+ "from_value" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2717
+ "preserve_query_string" : knownvalue .Bool (false ),
2718
+ "status_code" : knownvalue .Null (),
2719
+ "target_url" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2720
+ "value" : knownvalue .StringExact ("https://example.com" ),
2721
+ "expression" : knownvalue .Null (),
2722
+ }),
2723
+ }),
2724
+ }),
2725
+ }),
2726
+ }),
2727
+ ),
2728
+ },
2729
+ },
2730
+ {
2731
+ ConfigFile : config .TestNameFile ("3.tf" ),
2732
+ ConfigVariables : configVariables ,
2733
+ ConfigPlanChecks : resource.ConfigPlanChecks {
2734
+ PreApply : []plancheck.PlanCheck {
2735
+ plancheck .ExpectEmptyPlan (),
2736
+ },
2737
+ },
2738
+ ConfigStateChecks : []statecheck.StateCheck {
2739
+ statecheck .ExpectKnownValue (
2740
+ "cloudflare_ruleset.my_ruleset" ,
2741
+ tfjsonpath .New ("rules" ),
2742
+ knownvalue .ListExact ([]knownvalue.Check {
2743
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2744
+ "action" : knownvalue .StringExact ("redirect" ),
2745
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2746
+ "from_list" : knownvalue .Null (),
2747
+ "from_value" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2748
+ "preserve_query_string" : knownvalue .Bool (false ),
2749
+ "status_code" : knownvalue .Null (),
2750
+ "target_url" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2751
+ "value" : knownvalue .StringExact ("https://example.com" ),
2752
+ "expression" : knownvalue .Null (),
2753
+ }),
2754
+ }),
2755
+ }),
2756
+ }),
2757
+ }),
2758
+ ),
2759
+ },
2760
+ },
2761
+ {
2762
+ ConfigFile : config .TestNameFile ("4.tf" ),
2763
+ ConfigVariables : configVariables ,
2764
+ ConfigPlanChecks : resource.ConfigPlanChecks {
2765
+ PreApply : []plancheck.PlanCheck {
2766
+ plancheck .ExpectResourceAction (
2767
+ "cloudflare_ruleset.my_ruleset" ,
2768
+ plancheck .ResourceActionUpdate ,
2769
+ ),
2770
+ plancheck .ExpectKnownValue (
2771
+ "cloudflare_ruleset.my_ruleset" ,
2772
+ tfjsonpath .New ("rules" ),
2773
+ knownvalue .ListExact ([]knownvalue.Check {
2774
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2775
+ "action" : knownvalue .StringExact ("redirect" ),
2776
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2777
+ "from_list" : knownvalue .Null (),
2778
+ "from_value" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2779
+ "preserve_query_string" : knownvalue .Bool (true ),
2780
+ "status_code" : knownvalue .Int64Exact (301 ),
2781
+ "target_url" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2782
+ "value" : knownvalue .Null (),
2783
+ "expression" : knownvalue .StringExact ("concat(\" https://m.example.com\" , http.request.uri.path)" ),
2784
+ }),
2785
+ }),
2786
+ }),
2787
+ }),
2788
+ }),
2789
+ ),
2790
+ },
2791
+ },
2792
+ ConfigStateChecks : []statecheck.StateCheck {
2793
+ statecheck .ExpectKnownValue (
2794
+ "cloudflare_ruleset.my_ruleset" ,
2795
+ tfjsonpath .New ("rules" ),
2796
+ knownvalue .ListExact ([]knownvalue.Check {
2797
+ knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2798
+ "action" : knownvalue .StringExact ("redirect" ),
2799
+ "action_parameters" : knownvalue .ObjectPartial (map [string ]knownvalue.Check {
2800
+ "from_list" : knownvalue .Null (),
2801
+ "from_value" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2802
+ "preserve_query_string" : knownvalue .Bool (true ),
2803
+ "status_code" : knownvalue .Int64Exact (301 ),
2804
+ "target_url" : knownvalue .ObjectExact (map [string ]knownvalue.Check {
2805
+ "value" : knownvalue .Null (),
2806
+ "expression" : knownvalue .StringExact ("concat(\" https://m.example.com\" , http.request.uri.path)" ),
2807
+ }),
2808
+ }),
2809
+ }),
2810
+ }),
2811
+ }),
2812
+ ),
2813
+ },
2814
+ },
2815
+ },
2816
+ })
2817
+ }
0 commit comments