Skip to content

Commit

Permalink
Merge pull request #1651 from broswen/waitingroom-language
Browse files Browse the repository at this point in the history
add default_template_language to cloudflare_waiting_room
  • Loading branch information
jacobbednarz authored May 29, 2022
2 parents bac3f52 + 93de212 commit b2b0fff
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .changelog/1651.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_waiting_room: Add default_template_language field.
```
26 changes: 14 additions & 12 deletions internal/provider/resource_cloudflare_waiting_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ func resourceCloudflareWaitingRoom() *schema.Resource {

func buildWaitingRoom(d *schema.ResourceData) cloudflare.WaitingRoom {
return cloudflare.WaitingRoom{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Suspended: d.Get("suspended").(bool),
Host: d.Get("host").(string),
Path: d.Get("path").(string),
TotalActiveUsers: d.Get("total_active_users").(int),
NewUsersPerMinute: d.Get("new_users_per_minute").(int),
CustomPageHTML: d.Get("custom_page_html").(string),
SessionDuration: d.Get("session_duration").(int),
JsonResponseEnabled: d.Get("json_response_enabled").(bool),
QueueAll: d.Get("queue_all").(bool),
DisableSessionRenewal: d.Get("disable_session_renewal").(bool),
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Suspended: d.Get("suspended").(bool),
Host: d.Get("host").(string),
Path: d.Get("path").(string),
TotalActiveUsers: d.Get("total_active_users").(int),
NewUsersPerMinute: d.Get("new_users_per_minute").(int),
CustomPageHTML: d.Get("custom_page_html").(string),
DefaultTemplateLanguage: d.Get("default_template_language").(string),
SessionDuration: d.Get("session_duration").(int),
JsonResponseEnabled: d.Get("json_response_enabled").(bool),
QueueAll: d.Get("queue_all").(bool),
DisableSessionRenewal: d.Get("disable_session_renewal").(bool),
}
}

Expand Down Expand Up @@ -92,6 +93,7 @@ func resourceCloudflareWaitingRoomRead(ctx context.Context, d *schema.ResourceDa
d.Set("session_duration", waitingRoom.SessionDuration)
d.Set("disable_session_renewal", waitingRoom.DisableSessionRenewal)
d.Set("custom_page_html", waitingRoom.CustomPageHTML)
d.Set("default_template_language", waitingRoom.DefaultTemplateLanguage)
d.Set("json_response_enabled", waitingRoom.JsonResponseEnabled)
return nil
}
Expand Down
54 changes: 27 additions & 27 deletions internal/provider/resource_cloudflare_waiting_room_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,36 @@ func testAccCheckCloudflareWaitingRoomEventDestroy(s *terraform.State) error {
func testAccCloudflareWaitingRoomEvent(resourceName, waitingRoomEventName, zoneID, waitingRoomID string, startTime, endTime time.Time, domain, waitingRoomName string) string {
return fmt.Sprintf(`
resource "cloudflare_waiting_room" "%[1]s" {
name = "%[8]s"
zone_id = "%[3]s"
host = "www.%[7]s"
new_users_per_minute = 400
total_active_users = 405
path = "/foobar"
session_duration = 10
custom_page_html = "foobar"
description = "my desc"
disable_session_renewal = true
suspended = true
queue_all = false
json_response_enabled = true
name = "%[8]s"
zone_id = "%[3]s"
host = "www.%[7]s"
new_users_per_minute = 400
total_active_users = 405
path = "/foobar"
session_duration = 10
custom_page_html = "foobar"
description = "my desc"
disable_session_renewal = true
suspended = true
queue_all = false
json_response_enabled = true
}
resource "cloudflare_waiting_room_event" "%[1]s" {
name = "%[2]s"
zone_id = "%[3]s"
waiting_room_id = cloudflare_waiting_room.%[1]s.id
event_start_time = "%[5]s"
event_end_time = "%[6]s"
total_active_users = 405
new_users_per_minute = 400
custom_page_html = "foobar"
queueing_method = "fifo"
shuffle_at_event_start = false
disable_session_renewal = true
suspended = true
description = "my desc"
session_duration = 10
name = "%[2]s"
zone_id = "%[3]s"
waiting_room_id = cloudflare_waiting_room.%[1]s.id
event_start_time = "%[5]s"
event_end_time = "%[6]s"
total_active_users = 405
new_users_per_minute = 400
custom_page_html = "foobar"
queueing_method = "fifo"
shuffle_at_event_start = false
disable_session_renewal = true
suspended = true
description = "my desc"
session_duration = 10
}
`, resourceName, waitingRoomEventName, zoneID, waitingRoomID, startTime.Format(time.RFC3339), endTime.Format(time.RFC3339), domain, waitingRoomName)
}
28 changes: 15 additions & 13 deletions internal/provider/resource_cloudflare_waiting_room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccCloudflareWaitingRoom_Create(t *testing.T) {
resource.TestCheckResourceAttr(name, "name", waitingRoomName),
resource.TestCheckResourceAttr(name, "description", "my desc"),
resource.TestCheckResourceAttr(name, "custom_page_html", "foobar"),
resource.TestCheckResourceAttr(name, "default_template_language", "en-US"),
resource.TestCheckResourceAttr(name, "disable_session_renewal", "true"),
resource.TestCheckResourceAttr(name, "suspended", "true"),
resource.TestCheckResourceAttr(name, "queue_all", "false"),
Expand Down Expand Up @@ -64,19 +65,20 @@ func testAccCheckCloudflareWaitingRoomDestroy(s *terraform.State) error {
func testAccCloudflareWaitingRoom(resourceName, waitingRoomName, zoneID, domain, path string) string {
return fmt.Sprintf(`
resource "cloudflare_waiting_room" "%[1]s" {
name = "%[2]s"
zone_id = "%[3]s"
host = "www.%[4]s"
new_users_per_minute = 400
total_active_users = 405
path = "%[5]s"
session_duration = 10
custom_page_html = "foobar"
description = "my desc"
disable_session_renewal = true
suspended = true
queue_all = false
json_response_enabled = true
name = "%[2]s"
zone_id = "%[3]s"
host = "www.%[4]s"
new_users_per_minute = 400
total_active_users = 405
path = "%[5]s"
session_duration = 10
custom_page_html = "foobar"
default_template_language = "en-US"
description = "my desc"
disable_session_renewal = true
suspended = true
queue_all = false
json_response_enabled = true
}
`, resourceName, waitingRoomName, zoneID, domain, path)
}
23 changes: 23 additions & 0 deletions internal/provider/schema_cloudflare_waiting_room.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -51,6 +52,28 @@ func resourceCloudflareWaitingRoomSchema() map[string]*schema.Schema {
Optional: true,
},

"default_template_language": {
Type: schema.TypeString,
Optional: true,
Default: "en-US",
ValidateFunc: validation.StringInSlice([]string{
"de-DE",
"es-ES",
"en-US",
"fr-FR",
"id-ID",
"it-IT",
"ja-JP",
"ko-KR",
"nl-NL",
"pl-PL",
"pt-BR",
"tr-TR",
"zh-CN",
"zh-TW",
}, false),
},

"queue_all": {
Type: schema.TypeBool,
Optional: true,
Expand Down
19 changes: 19 additions & 0 deletions website/docs/r/waiting_room.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,32 @@ The following arguments are supported:
* `total_active_users` - (Required) The total number of active user sessions on the route at a point in time.
* `new_users_per_minute` - (Required) The number of new users that will be let into the route every minute.
* `custom_page_html` - (Optional) This a templated html file that will be rendered at the edge.
* `default_template_language` - (Optional) The language to use for the default waiting room page (refer to the [nested schema](#nestedblock--default-template-language)).
* `queue_all` - (Optional) If queue_all is true all the traffic that is coming to a route will be sent to the waiting room. Default: false.
* `disable_session_renewal` - (Optional) Disables automatic renewal of session cookies. Default: false.
* `suspended` - (Optional) If suspended, the traffic doesn't go to the waiting room. Default: false.
* `description` - (Optional) A description to let users add more details about the waiting room.
* `session_duration` - (Optional) Lifetime of a cookie (in minutes) set by Cloudflare for users who get access to the route. Default: 5
* `json_response_enabled` - (Optional) If true, requests to the waiting room with the header Accept: application/json will receive a JSON response object.

<a id="nestedblock--default-template-language"></a>
**Nested schema for `default_template_language`**

* `de-DE` - German
* `en-US` - English
* `es-ES` - Spanish
* `fr-FR` - French
* `id-ID` - Indonesian
* `it-IT` - Italian
* `ja-JP` - Japanese
* `ko-KR` - Korean
* `nl-NL` - Dutch
* `pl-PL` - Polish
* `pt-BR` - Portuguese
* `tr-TR` - Turkish
* `zh-CN` - Chinese (Simplified)
* `zh-TW` - Chinese (Traditional)

## Attributes Reference

The following attributes are exported:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/waiting_room_event.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Provides a Cloudflare Waiting Room Event resource.
## Example Usage

```hcl
resource "cloudflare_waiting_room_vent" "example" {
resource "cloudflare_waiting_room_event" "example" {
zone_id = "ae36f999674d196762efcc5abb06b345"
waiting_room_id = "d41d8cd98f00b204e9800998ecf8427e"
name = "foo"
Expand Down

0 comments on commit b2b0fff

Please sign in to comment.