Skip to content

Commit 5f8c724

Browse files
Add support for App Platform edge controls (#1384)
* Update godo version to v1.150.0 to include edge control settings * Add edge controls * Add edge controls test
1 parent ec18353 commit 5f8c724

3 files changed

Lines changed: 127 additions & 13 deletions

File tree

digitalocean/app/app_spec.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ func appSpecSchema(isResource bool) map[string]*schema.Schema {
4040
Optional: true,
4141
Description: "The slug for the DigitalOcean data center region hosting the app",
4242
},
43+
"disable_edge_cache": {
44+
Type: schema.TypeBool,
45+
Optional: true,
46+
Default: false,
47+
Description: "Whether to disable the edge cache for the app. Default is false, which enables the edge cache.",
48+
},
49+
"disable_email_obfuscation": {
50+
Type: schema.TypeBool,
51+
Optional: true,
52+
Default: false,
53+
Description: "Email obfuscation configuration for the app. Default is false, which keeps the email obfuscated.",
54+
},
55+
"enhanced_threat_control_enabled": {
56+
Type: schema.TypeBool,
57+
Optional: true,
58+
Default: false,
59+
Description: "Whether to enable enhanced threat control for the app. Default is false. Set to true to enable enhanced threat control, putting additional security measures for Layer 7 DDoS attacks.",
60+
},
4361
"domain": {
4462
Type: schema.TypeList,
4563
Optional: true,
@@ -1213,19 +1231,22 @@ func expandAppSpec(config []interface{}) *godo.AppSpec {
12131231
appSpecConfig := config[0].(map[string]interface{})
12141232

12151233
appSpec := &godo.AppSpec{
1216-
Name: appSpecConfig["name"].(string),
1217-
Region: appSpecConfig["region"].(string),
1218-
Features: expandAppSpecFeatures(appSpecConfig["features"].(*schema.Set)),
1219-
Services: expandAppSpecServices(appSpecConfig["service"].([]interface{})),
1220-
StaticSites: expandAppSpecStaticSites(appSpecConfig["static_site"].([]interface{})),
1221-
Workers: expandAppSpecWorkers(appSpecConfig["worker"].([]interface{})),
1222-
Jobs: expandAppSpecJobs(appSpecConfig["job"].([]interface{})),
1223-
Functions: expandAppSpecFunctions(appSpecConfig["function"].([]interface{})),
1224-
Databases: expandAppSpecDatabases(appSpecConfig["database"].([]interface{})),
1225-
Envs: expandAppEnvs(appSpecConfig["env"].(*schema.Set).List()),
1226-
Alerts: expandAppAlerts(appSpecConfig["alert"].(*schema.Set).List()),
1227-
Ingress: expandAppIngress(appSpecConfig["ingress"].([]interface{})),
1228-
Egress: expandAppEgress(appSpecConfig["egress"].([]interface{})),
1234+
Name: appSpecConfig["name"].(string),
1235+
Region: appSpecConfig["region"].(string),
1236+
DisableEdgeCache: appSpecConfig["disable_edge_cache"].(bool),
1237+
DisableEmailObfuscation: appSpecConfig["disable_email_obfuscation"].(bool),
1238+
EnhancedThreatControlEnabled: appSpecConfig["enhanced_threat_control_enabled"].(bool),
1239+
Features: expandAppSpecFeatures(appSpecConfig["features"].(*schema.Set)),
1240+
Services: expandAppSpecServices(appSpecConfig["service"].([]interface{})),
1241+
StaticSites: expandAppSpecStaticSites(appSpecConfig["static_site"].([]interface{})),
1242+
Workers: expandAppSpecWorkers(appSpecConfig["worker"].([]interface{})),
1243+
Jobs: expandAppSpecJobs(appSpecConfig["job"].([]interface{})),
1244+
Functions: expandAppSpecFunctions(appSpecConfig["function"].([]interface{})),
1245+
Databases: expandAppSpecDatabases(appSpecConfig["database"].([]interface{})),
1246+
Envs: expandAppEnvs(appSpecConfig["env"].(*schema.Set).List()),
1247+
Alerts: expandAppAlerts(appSpecConfig["alert"].(*schema.Set).List()),
1248+
Ingress: expandAppIngress(appSpecConfig["ingress"].([]interface{})),
1249+
Egress: expandAppEgress(appSpecConfig["egress"].([]interface{})),
12291250
}
12301251

12311252
// Prefer the `domain` block over `domains` if it is set.
@@ -1248,6 +1269,9 @@ func flattenAppSpec(d *schema.ResourceData, spec *godo.AppSpec) []map[string]int
12481269
r["name"] = (*spec).Name
12491270
r["region"] = (*spec).Region
12501271
r["features"] = (*spec).Features
1272+
r["disable_edge_cache"] = (*spec).DisableEdgeCache
1273+
r["disable_email_obfuscation"] = (*spec).DisableEmailObfuscation
1274+
r["enhanced_threat_control_enabled"] = (*spec).EnhancedThreatControlEnabled
12511275

12521276
if len((*spec).Domains) > 0 {
12531277
r["domains"] = flattenAppDomainSpec((*spec).Domains)

digitalocean/app/resource_app_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ func TestAccDigitalOceanApp_Basic(t *testing.T) {
163163
"digitalocean_app.foobar", "spec.0.service.0.log_destination.0.papertrail.0.endpoint", "syslog+tls://example.com:12345"),
164164
),
165165
},
166+
{
167+
Config: fmt.Sprintf(testAccCheckDigitalOceanAppConfig_basic_edge_controls, appName),
168+
Check: resource.ComposeTestCheckFunc(
169+
testAccCheckDigitalOceanAppExists("digitalocean_app.foobar", &app),
170+
resource.TestCheckResourceAttr(
171+
"digitalocean_app.foobar", "spec.0.name", appName),
172+
resource.TestCheckResourceAttrSet(
173+
"digitalocean_app.foobar", "project_id"),
174+
resource.TestCheckResourceAttr(
175+
"digitalocean_app.foobar", "spec.0.disable_edge_cache", "true"),
176+
resource.TestCheckResourceAttr(
177+
"digitalocean_app.foobar", "spec.0.disable_email_obfuscation", "true"),
178+
resource.TestCheckResourceAttr(
179+
"digitalocean_app.foobar", "spec.0.enhanced_threat_control_enabled", "true"),
180+
),
181+
},
166182
},
167183
})
168184
}
@@ -1158,6 +1174,53 @@ resource "digitalocean_app" "foobar" {
11581174
}
11591175
}`
11601176

1177+
var testAccCheckDigitalOceanAppConfig_basic_edge_controls = `
1178+
resource "digitalocean_app" "foobar" {
1179+
spec {
1180+
name = "%s"
1181+
region = "ams"
1182+
enhanced_threat_control_enabled = true
1183+
disable_edge_cache = true
1184+
disable_email_obfuscation = true
1185+
1186+
alert {
1187+
rule = "DEPLOYMENT_FAILED"
1188+
}
1189+
1190+
service {
1191+
name = "go-service"
1192+
environment_slug = "go"
1193+
instance_count = 1
1194+
instance_size_slug = "basic-xxs"
1195+
1196+
git {
1197+
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
1198+
branch = "main"
1199+
}
1200+
1201+
health_check {
1202+
http_path = "/"
1203+
timeout_seconds = 10
1204+
port = 1234
1205+
}
1206+
1207+
alert {
1208+
value = 75
1209+
operator = "GREATER_THAN"
1210+
window = "TEN_MINUTES"
1211+
rule = "CPU_UTILIZATION"
1212+
}
1213+
1214+
log_destination {
1215+
name = "ServiceLogs"
1216+
papertrail {
1217+
endpoint = "syslog+tls://example.com:12345"
1218+
}
1219+
}
1220+
}
1221+
}
1222+
}`
1223+
11611224
var testAccCheckDigitalOceanAppConfig_withTimeout = `
11621225
resource "digitalocean_app" "foobar" {
11631226
timeouts {

docs/resources/app.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ resource "digitalocean_app" "golang-sample" {
183183
}
184184
```
185185

186+
### Edge Controls Example
187+
188+
```hcl
189+
resource "digitalocean_app" "golang-sample" {
190+
spec {
191+
name = "golang-sample"
192+
region = "ams"
193+
disable_edge_cache = true
194+
disable_email_obfuscation = false
195+
enhanced_threat_control_enabled = true
196+
197+
service {
198+
name = "go-service"
199+
instance_count = 1
200+
instance_size_slug = "apps-s-1vcpu-1gb"
201+
202+
git {
203+
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
204+
branch = "main"
205+
}
206+
}
207+
}
208+
}
209+
```
186210
## Argument Reference
187211

188212
The following arguments are supported:
@@ -191,6 +215,9 @@ The following arguments are supported:
191215

192216
* `name` - (Required) The name of the app. Must be unique across all apps in the same account.
193217
* `region` - The slug for the DigitalOcean data center region hosting the app.
218+
* `disable_edge_cache` - A boolean indicating whether to disable the edge cache for this app. Default: `false`. Available only for non-static sites. Requires custom domains and applies to all the domains of the app.
219+
* `disable_email_obfuscation` - A boolean indicating whether to disable email obfuscation for this app. Default: `false`. Requires custom domains and applies to all the domains of the app.
220+
* `enhanced_threat_control_enabled` - A boolean, when set to `true`, enables enhanced analyzing of incoming traffic to prevent layer 7 DDoS attacks. Default: `false`. Requires custom domains and applies to all the domains of the app.
194221
* `features` - A list of the features applied to the app. The default buildpack can be overridden here. List of available buildpacks can be found using the [doctl CLI](https://docs.digitalocean.com/reference/doctl/reference/apps/list-buildpacks/)
195222
* `domain` - Describes a domain where the application will be made available.
196223
- `name` - The hostname for the domain.

0 commit comments

Comments
 (0)