Skip to content

Commit 194dc2d

Browse files
GreenStagestainless-app[bot]
authored andcommitted
Validate zero_trust_access_application.policies.precedence >= 1
1 parent 579f029 commit 194dc2d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

internal/services/zero_trust_access_application/resource_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,25 @@ func TestAccCloudflareAccessApplication_WithReusablePolicies(t *testing.T) {
11241124
})
11251125
}
11261126

1127+
func TestAccCloudflareAccessApplication_WithReusablePolicies_InvalidPrecedence(t *testing.T) {
1128+
rnd := utils.GenerateRandomResourceName()
1129+
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
1130+
resource.Test(t, resource.TestCase{
1131+
PreCheck: func() {
1132+
acctest.TestAccPreCheck(t)
1133+
acctest.TestAccPreCheck_AccountID(t)
1134+
},
1135+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
1136+
CheckDestroy: testAccCheckCloudflareAccessApplicationDestroy,
1137+
Steps: []resource.TestStep{
1138+
{
1139+
Config: testAccCloudflareAccessApplicationConfigWithReusablePoliciesInvalidPrecedence(rnd, domain, accountID),
1140+
ExpectError: regexp.MustCompile(`Attribute policies\[0].precedence value must be at least 1, got: 0`),
1141+
},
1142+
},
1143+
})
1144+
}
1145+
11271146
func TestAccCloudflareAccessApplication_WithAppLauncherCustomization(t *testing.T) {
11281147
rnd := utils.GenerateRandomResourceName()
11291148
name := fmt.Sprintf("cloudflare_zero_trust_access_application.%s", rnd)
@@ -1609,6 +1628,10 @@ func testAccCloudflareAccessApplicationConfigWithReusablePolicies(rnd, domain st
16091628
return acctest.LoadTestCase("accessapplicationconfigwithreusablepolicies.tf", rnd, domain, accountID)
16101629
}
16111630

1631+
func testAccCloudflareAccessApplicationConfigWithReusablePoliciesInvalidPrecedence(rnd, domain string, accountID string) string {
1632+
return acctest.LoadTestCase("accessapplicationconfigwithreusablepolicies_invalid_precedence.tf", rnd, domain, accountID)
1633+
}
1634+
16121635
func testAccessApplicationWithInvalidSaas(resourceID, accountID string) string {
16131636
return acctest.LoadTestCase("accessapplicationconfigwithinvalidsaas.tf", resourceID, accountID)
16141637
}

internal/services/zero_trust_access_application/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1010
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator"
1111
"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
12+
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
1213
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1314
"github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator"
1415
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
@@ -598,6 +599,9 @@ func ResourceSchema(ctx context.Context) schema.Schema {
598599
Description: "The order of execution for this policy. Must be unique for each policy within an app.",
599600
Optional: true,
600601
Computed: true,
602+
Validators: []validator.Int64{
603+
int64validator.AtLeast(1),
604+
},
601605
},
602606
"decision": schema.StringAttribute{
603607
Description: "The action Access will take if a user matches this policy. Infrastructure application policies can only use the Allow action.\nAvailable values: \"allow\", \"deny\", \"non_identity\", \"bypass\".",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
resource "cloudflare_zero_trust_access_policy" "%[1]s_p1" {
2+
account_id = "%[3]s"
3+
name = "%[1]s"
4+
decision = "allow"
5+
include = [
6+
{
7+
email = { email = "[email protected]" }
8+
}
9+
]
10+
}
11+
12+
resource "cloudflare_zero_trust_access_policy" "%[1]s_p2" {
13+
account_id = "%[3]s"
14+
name = "%[1]s"
15+
decision = "non_identity"
16+
include = [
17+
{
18+
ip = { ip = "127.0.0.1/32" }
19+
}
20+
]
21+
}
22+
23+
resource "cloudflare_zero_trust_access_application" "%[1]s" {
24+
account_id = "%[3]s"
25+
name = "%[1]s"
26+
domain = "%[1]s.%[2]s"
27+
type = "self_hosted"
28+
policies = [
29+
{
30+
id = cloudflare_zero_trust_access_policy.%[1]s_p1.id
31+
precedence = 0
32+
},
33+
{
34+
id = cloudflare_zero_trust_access_policy.%[1]s_p2.id
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)