Skip to content

Commit 7613cb1

Browse files
Merge pull request #5830 from cloudflare/fix-custom-pages-2
fix: custom pages
2 parents 250737b + bd3c296 commit 7613cb1

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

internal/services/custom_pages/data_source_schema.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ func DataSourceSchema(ctx context.Context) schema.Schema {
2222
return schema.Schema{
2323
Attributes: map[string]schema.Attribute{
2424
"identifier": schema.StringAttribute{
25-
Description: "Error Page Types\nAvailable values: \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
25+
Description: "Error Page Types\nAvailable values: \"under_attack\", \"basic_challenge\", \"waf_challenge\", \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
2626
Required: true,
2727
Validators: []validator.String{
2828
stringvalidator.OneOfCaseInsensitive(
29+
"under_attack",
30+
"basic_challenge",
31+
"waf_challenge",
2932
"waf_block",
3033
"ip_block",
3134
"country_challenge",

internal/services/custom_pages/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type CustomPagesModel struct {
1919
AccountID types.String `tfsdk:"account_id" path:"account_id,optional"`
2020
ZoneID types.String `tfsdk:"zone_id" path:"zone_id,optional"`
2121
State types.String `tfsdk:"state" json:"state,required"`
22-
URL types.String `tfsdk:"url" json:"url,required"`
22+
URL types.String `tfsdk:"url" json:"url,computed_optional"`
2323
CreatedOn timetypes.RFC3339 `tfsdk:"created_on" json:"created_on,computed" format:"date-time"`
2424
Description types.String `tfsdk:"description" json:"description,computed"`
2525
ModifiedOn timetypes.RFC3339 `tfsdk:"modified_on" json:"modified_on,computed" format:"date-time"`

internal/services/custom_pages/resource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func (r *CustomPagesResource) Create(ctx context.Context, req resource.CreateReq
9999
}
100100
data = &env.Result
101101
data.ID = data.Identifier
102+
if env.Result.URL.IsNull() || env.Result.URL.ValueString() == "" || env.Result.URL.ValueString() == "null" {
103+
data.URL = types.StringValue("")
104+
}
102105

103106
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
104107
}
@@ -155,6 +158,9 @@ func (r *CustomPagesResource) Update(ctx context.Context, req resource.UpdateReq
155158
}
156159
data = &env.Result
157160
data.ID = data.Identifier
161+
if env.Result.URL.IsNull() || env.Result.URL.ValueString() == "" || env.Result.URL.ValueString() == "null" {
162+
data.URL = types.StringValue("")
163+
}
158164

159165
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
160166
}
@@ -202,6 +208,9 @@ func (r *CustomPagesResource) Read(ctx context.Context, req resource.ReadRequest
202208
}
203209
data = &env.Result
204210
data.ID = data.Identifier
211+
if env.Result.URL.IsNull() || env.Result.URL.ValueString() == "" || env.Result.URL.ValueString() == "null" {
212+
data.URL = types.StringValue("")
213+
}
205214

206215
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
207216
}

internal/services/custom_pages/resource_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ func TestAccCloudflareCustomPages_AccountBasic(t *testing.T) {
2828
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
2929
Steps: []resource.TestStep{
3030
{
31-
Config: testAccCustomPagesAccountConfig(rnd, accountID, "basic_challenge", "default", "http://www.example.com/custom_page"),
31+
Config: testAccCustomPagesAccountConfig(rnd, accountID, "basic_challenge", "default", ""),
3232
ConfigStateChecks: []statecheck.StateCheck{
3333
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("identifier"), knownvalue.StringExact("basic_challenge")),
3434
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(consts.AccountIDSchemaKey), knownvalue.StringExact(accountID)),
3535
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("state"), knownvalue.StringExact("default")),
36-
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("url"), knownvalue.StringExact("http://www.example.com/custom_page")),
36+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("url"), knownvalue.StringExact("")),
3737
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("zone_id"), knownvalue.Null()),
3838
},
3939
},
4040
{
41-
Config: testAccCustomPagesAccountConfig(rnd, accountID, "basic_challenge", "default", "http://www.example.com/custom_page_2"),
41+
Config: testAccCustomPagesAccountConfig(rnd, accountID, "basic_challenge", "default", ""),
4242
ConfigStateChecks: []statecheck.StateCheck{
4343
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("identifier"), knownvalue.StringExact("basic_challenge")),
4444
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(consts.AccountIDSchemaKey), knownvalue.StringExact(accountID)),
4545
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("state"), knownvalue.StringExact("default")),
46-
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("url"), knownvalue.StringExact("http://www.example.com/custom_page_2")),
46+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("url"), knownvalue.StringExact("")),
4747
},
4848
},
4949
{
@@ -399,6 +399,9 @@ func TestAccCloudflareCustomPages_ZoneRatelimitBlock(t *testing.T) {
399399
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("url"), knownvalue.StringExact("")),
400400
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("account_id"), knownvalue.Null()),
401401
},
402+
ConfigPlanChecks: resource.ConfigPlanChecks{
403+
PostApplyPostRefresh: acctest.LogResourceDrift,
404+
},
402405
},
403406
{
404407
Config: testAccCustomPagesZoneConfig(rnd, zoneID, "ratelimit_block", "customized", "https://custom-pages-waf-challenge.terraform-provider-acceptance-testing.workers.dev/"),

internal/services/custom_pages/schema.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ func ResourceSchema(ctx context.Context) schema.Schema {
2323
Version: 1,
2424
Attributes: map[string]schema.Attribute{
2525
"id": schema.StringAttribute{
26-
Description: "Error Page Types\nAvailable values: \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
26+
Description: "Error Page Types\nAvailable values: \"under_attack\", \"basic_challenge\", \"waf_challenge\", \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
2727
Computed: true,
2828
Validators: []validator.String{
2929
stringvalidator.OneOfCaseInsensitive(
30+
"under_attack",
31+
"basic_challenge",
32+
"waf_challenge",
3033
"waf_block",
3134
"ip_block",
3235
"country_challenge",
@@ -39,10 +42,13 @@ func ResourceSchema(ctx context.Context) schema.Schema {
3942
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown(), stringplanmodifier.RequiresReplace()},
4043
},
4144
"identifier": schema.StringAttribute{
42-
Description: "Error Page Types\nAvailable values: \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
45+
Description: "Error Page Types\nAvailable values: \"under_attack\", \"basic_challenge\", \"waf_challenge\", \"waf_block\", \"ip_block\", \"country_challenge\", \"500_errors\", \"1000_errors\", \"managed_challenge\", \"ratelimit_block\".",
4346
Required: true,
4447
Validators: []validator.String{
4548
stringvalidator.OneOfCaseInsensitive(
49+
"under_attack",
50+
"basic_challenge",
51+
"waf_challenge",
4652
"waf_block",
4753
"ip_block",
4854
"country_challenge",
@@ -73,7 +79,8 @@ func ResourceSchema(ctx context.Context) schema.Schema {
7379
},
7480
"url": schema.StringAttribute{
7581
Description: "The URL associated with the custom page.",
76-
Required: true,
82+
Optional: true,
83+
Computed: true,
7784
},
7885
"created_on": schema.StringAttribute{
7986
Computed: true,

internal/services/custom_pages/testdata/datasource_basic.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ resource "cloudflare_custom_pages" "%[1]s" {
88
data "cloudflare_custom_pages" "%[1]s" {
99
account_id = cloudflare_custom_pages.%[1]s.account_id
1010
identifier = cloudflare_custom_pages.%[1]s.identifier
11-
}
11+
}

0 commit comments

Comments
 (0)