Skip to content

Commit 5bbf2c9

Browse files
authored
Merge pull request #30 from arangodb-managed/foxx-auth
OAS-3201 | Extended deployment resource to support disable_foxx_authentication setting
2 parents 6c4190c + 9aa7e33 commit 5bbf2c9

File tree

5 files changed

+161
-36
lines changed

5 files changed

+161
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ resource "oasis_deployment" "my_oneshard_deployment" {
6969
security { // this section is optional
7070
ca_certificate = "" // If not set, uses default certificate from project
7171
ip_allowlist = "" // If not set, no allowlist is configured
72+
disable_foxx_authentication = false // If set to true, request to Foxx apps are not authentications.
7273
}
7374
7475
configuration {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/arangodb-managed/terraform-provider-oasis
22

33
require (
4-
github.com/arangodb-managed/apis v0.65.0
4+
github.com/arangodb-managed/apis v0.69.3
55
github.com/arangodb-managed/log-helper v0.2.0
66
github.com/gogo/protobuf v1.3.0
77
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -19,7 +19,7 @@ go 1.16
1919

2020
replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.2.0+incompatible
2121

22-
replace github.com/arangodb/kube-arangodb => github.com/arangodb/kube-arangodb v0.0.0-20210414140129-e66e59938ad5
22+
replace github.com/arangodb/kube-arangodb => github.com/arangodb/kube-arangodb v0.0.0-20210528082542-41972ad9b013
2323

2424
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a
2525

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU
4545
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
4646
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
4747
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
48-
github.com/arangodb-managed/apis v0.65.0 h1:tvsQXVwJmg4UgYIGG6/NemV8EDoq3M7bGtm6XNFciIw=
49-
github.com/arangodb-managed/apis v0.65.0/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
48+
github.com/arangodb-managed/apis v0.69.3 h1:xgY3wtjzuMp9HDwXgmVkc6pA8f8mqpf3uYEqtrbUCUc=
49+
github.com/arangodb-managed/apis v0.69.3/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
5050
github.com/arangodb-managed/log-helper v0.2.0 h1:QK85i0a+mGM++wK625Oe1z4HuXhvaN3vR/Nunwa1qAA=
5151
github.com/arangodb-managed/log-helper v0.2.0/go.mod h1:WJogNCCXWM5OQx/ZYvtRo/1zwm/IpKj+f4QVtM8hNJw=
5252
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

pkg/resource_deployment.go

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// Author Gergely Brautigam
2121
// Author Robert Stam
2222
// Author Marcin Swiderski
23+
// Author Ewout Prangsma
2324
//
2425

2526
package pkg
@@ -37,22 +38,23 @@ import (
3738
)
3839

3940
const (
40-
deplTAndCAcceptedFieldName = "terms_and_conditions_accepted"
41-
deplProjectFieldName = "project"
42-
deplNameFieldName = "name"
43-
deplDescriptionFieldName = "description"
44-
deplLocationFieldName = "location"
45-
deplLocationRegionFieldName = "region"
46-
deplVersionFieldName = "version"
47-
deplVersionDbVersionFieldName = "db_version"
48-
deplSecurityFieldName = "security"
49-
deplSecurityCaCertificateFieldName = "ca_certificate"
50-
deplSecurityIpAllowlistFieldName = "ip_allowlist"
51-
deplConfigurationFieldName = "configuration"
52-
deplConfigurationModelFieldName = "model"
53-
deplConfigurationNodeSizeIdFieldName = "node_size_id"
54-
deplConfigurationNodeCountFieldName = "node_count"
55-
deplConfigurationNodeDiskSizeFieldName = "node_disk_size"
41+
deplTAndCAcceptedFieldName = "terms_and_conditions_accepted"
42+
deplProjectFieldName = "project"
43+
deplNameFieldName = "name"
44+
deplDescriptionFieldName = "description"
45+
deplLocationFieldName = "location"
46+
deplLocationRegionFieldName = "region"
47+
deplVersionFieldName = "version"
48+
deplVersionDbVersionFieldName = "db_version"
49+
deplSecurityFieldName = "security"
50+
deplSecurityCaCertificateFieldName = "ca_certificate"
51+
deplSecurityIpAllowlistFieldName = "ip_allowlist"
52+
deplSecurityDisableFoxxAuthenticationFieldName = "disable_foxx_authentication"
53+
deplConfigurationFieldName = "configuration"
54+
deplConfigurationModelFieldName = "model"
55+
deplConfigurationNodeSizeIdFieldName = "node_size_id"
56+
deplConfigurationNodeCountFieldName = "node_count"
57+
deplConfigurationNodeDiskSizeFieldName = "node_disk_size"
5658
)
5759

5860
func resourceDeployment() *schema.Resource {
@@ -136,6 +138,10 @@ func resourceDeployment() *schema.Resource {
136138
Type: schema.TypeString,
137139
Optional: true, // If not set, no allowlist is configured
138140
},
141+
deplSecurityDisableFoxxAuthenticationFieldName: {
142+
Type: schema.TypeBool,
143+
Optional: true, // If not set, defaults to enabling foxx authentication
144+
},
139145
},
140146
},
141147
},
@@ -307,8 +313,9 @@ type version struct {
307313

308314
// security is a convenient wrapper around the security schema for easy parsing
309315
type securityFields struct {
310-
caCertificate string
311-
ipAllowlist string
316+
caCertificate string
317+
ipAllowlist string
318+
disableFoxxAuthentication bool
312319
}
313320

314321
// configuration is a convenient wrapper around the configuration schema for easy parsing
@@ -366,13 +373,14 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d
366373
}
367374

368375
return &data.Deployment{
369-
Name: name,
370-
Description: description,
371-
ProjectId: project,
372-
RegionId: loc.region,
373-
Version: ver.dbVersion,
374-
Certificates: &data.Deployment_CertificateSpec{CaCertificateId: sec.caCertificate},
375-
IpallowlistId: sec.ipAllowlist,
376+
Name: name,
377+
Description: description,
378+
ProjectId: project,
379+
RegionId: loc.region,
380+
Version: ver.dbVersion,
381+
Certificates: &data.Deployment_CertificateSpec{CaCertificateId: sec.caCertificate},
382+
IpallowlistId: sec.ipAllowlist,
383+
DisableFoxxAuthentication: sec.disableFoxxAuthentication,
376384
Model: &data.Deployment_ModelSpec{
377385
Model: conf.model,
378386
NodeCount: int32(conf.nodeCount),
@@ -418,6 +426,9 @@ func expandSecurity(s []interface{}) (sec securityFields) {
418426
if i, ok := item[deplSecurityIpAllowlistFieldName]; ok {
419427
sec.ipAllowlist = i.(string)
420428
}
429+
if i, ok := item[deplSecurityDisableFoxxAuthenticationFieldName]; ok {
430+
sec.disableFoxxAuthentication = i.(bool)
431+
}
421432
}
422433
return
423434
}
@@ -500,8 +511,9 @@ func flattenVersion(depl *data.Deployment) []interface{} {
500511
func flattenSecurity(depl *data.Deployment) []interface{} {
501512
return []interface{}{
502513
map[string]interface{}{
503-
deplSecurityIpAllowlistFieldName: depl.GetIpallowlistId(),
504-
deplSecurityCaCertificateFieldName: depl.GetCertificates().GetCaCertificateId(),
514+
deplSecurityIpAllowlistFieldName: depl.GetIpallowlistId(),
515+
deplSecurityCaCertificateFieldName: depl.GetCertificates().GetCaCertificateId(),
516+
deplSecurityDisableFoxxAuthenticationFieldName: depl.GetDisableFoxxAuthentication(),
505517
},
506518
}
507519
}

pkg/resource_deployment_test.go

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,62 @@ func TestFlattenDeploymentResource(t *testing.T) {
102102
},
103103
deplSecurityFieldName: []interface{}{
104104
map[string]interface{}{
105-
deplSecurityCaCertificateFieldName: "certificate-id",
106-
deplSecurityIpAllowlistFieldName: "ip-allowlist",
105+
deplSecurityCaCertificateFieldName: "certificate-id",
106+
deplSecurityIpAllowlistFieldName: "ip-allowlist",
107+
deplSecurityDisableFoxxAuthenticationFieldName: false,
108+
},
109+
},
110+
deplConfigurationFieldName: []interface{}{
111+
map[string]interface{}{
112+
deplConfigurationModelFieldName: "oneshard",
113+
deplConfigurationNodeSizeIdFieldName: "a8",
114+
deplConfigurationNodeCountFieldName: 3,
115+
deplConfigurationNodeDiskSizeFieldName: 32,
116+
},
117+
},
118+
}
119+
assert.Equal(t, expected, flattened)
120+
}
121+
122+
func TestFlattenDeploymentResourceDisableFoxxAuth(t *testing.T) {
123+
depl := &data.Deployment{
124+
Name: "test-name",
125+
Description: "test-desc",
126+
ProjectId: "123456789",
127+
RegionId: "gcp-europe-west4",
128+
Version: "3.6.0",
129+
Certificates: &data.Deployment_CertificateSpec{
130+
CaCertificateId: "certificate-id",
131+
},
132+
IpallowlistId: "ip-allowlist",
133+
DisableFoxxAuthentication: true,
134+
Model: &data.Deployment_ModelSpec{
135+
Model: "oneshard",
136+
NodeSizeId: "a8",
137+
NodeCount: 3,
138+
NodeDiskSize: 32,
139+
},
140+
}
141+
flattened := flattenDeployment(depl)
142+
expected := map[string]interface{}{
143+
deplProjectFieldName: "123456789",
144+
deplNameFieldName: "test-name",
145+
deplDescriptionFieldName: "test-desc",
146+
deplLocationFieldName: []interface{}{
147+
map[string]interface{}{
148+
deplLocationRegionFieldName: "gcp-europe-west4",
149+
},
150+
},
151+
deplVersionFieldName: []interface{}{
152+
map[string]interface{}{
153+
deplVersionDbVersionFieldName: "3.6.0",
154+
},
155+
},
156+
deplSecurityFieldName: []interface{}{
157+
map[string]interface{}{
158+
deplSecurityCaCertificateFieldName: "certificate-id",
159+
deplSecurityIpAllowlistFieldName: "ip-allowlist",
160+
deplSecurityDisableFoxxAuthenticationFieldName: true,
107161
},
108162
},
109163
deplConfigurationFieldName: []interface{}{
@@ -128,7 +182,8 @@ func TestExpandingDeploymentResource(t *testing.T) {
128182
Certificates: &data.Deployment_CertificateSpec{
129183
CaCertificateId: "certificate-id",
130184
},
131-
IpallowlistId: "ip-allowlist",
185+
IpallowlistId: "ip-allowlist",
186+
DisableFoxxAuthentication: false,
132187
Model: &data.Deployment_ModelSpec{
133188
Model: "oneshard",
134189
NodeSizeId: "a8",
@@ -152,8 +207,65 @@ func TestExpandingDeploymentResource(t *testing.T) {
152207
},
153208
deplSecurityFieldName: []interface{}{
154209
map[string]interface{}{
155-
deplSecurityCaCertificateFieldName: "certificate-id",
156-
deplSecurityIpAllowlistFieldName: "ip-allowlist",
210+
deplSecurityCaCertificateFieldName: "certificate-id",
211+
deplSecurityIpAllowlistFieldName: "ip-allowlist",
212+
deplSecurityDisableFoxxAuthenticationFieldName: false,
213+
},
214+
},
215+
deplConfigurationFieldName: []interface{}{
216+
map[string]interface{}{
217+
deplConfigurationModelFieldName: "oneshard",
218+
deplConfigurationNodeSizeIdFieldName: "a8",
219+
deplConfigurationNodeCountFieldName: 3,
220+
deplConfigurationNodeDiskSizeFieldName: 32,
221+
},
222+
},
223+
}
224+
s := resourceDeployment().Schema
225+
resourceData := schema.TestResourceDataRaw(t, s, raw)
226+
expandedDepl, err := expandDeploymentResource(resourceData, "123456789")
227+
assert.NoError(t, err)
228+
assert.Equal(t, depl, expandedDepl)
229+
}
230+
231+
func TestExpandingDeploymentResourceDisableFoxxAuth(t *testing.T) {
232+
depl := &data.Deployment{
233+
Name: "test-name",
234+
Description: "test-desc",
235+
ProjectId: "123456789",
236+
RegionId: "gcp-europe-west4",
237+
Version: "3.6.0",
238+
Certificates: &data.Deployment_CertificateSpec{
239+
CaCertificateId: "certificate-id",
240+
},
241+
IpallowlistId: "ip-allowlist",
242+
DisableFoxxAuthentication: true,
243+
Model: &data.Deployment_ModelSpec{
244+
Model: "oneshard",
245+
NodeSizeId: "a8",
246+
NodeCount: 3,
247+
NodeDiskSize: 32,
248+
},
249+
}
250+
raw := map[string]interface{}{
251+
deplProjectFieldName: "123456789",
252+
deplNameFieldName: "test-name",
253+
deplDescriptionFieldName: "test-desc",
254+
deplLocationFieldName: []interface{}{
255+
map[string]interface{}{
256+
deplLocationRegionFieldName: "gcp-europe-west4",
257+
},
258+
},
259+
deplVersionFieldName: []interface{}{
260+
map[string]interface{}{
261+
deplVersionDbVersionFieldName: "3.6.0",
262+
},
263+
},
264+
deplSecurityFieldName: []interface{}{
265+
map[string]interface{}{
266+
deplSecurityCaCertificateFieldName: "certificate-id",
267+
deplSecurityIpAllowlistFieldName: "ip-allowlist",
268+
deplSecurityDisableFoxxAuthenticationFieldName: true,
157269
},
158270
},
159271
deplConfigurationFieldName: []interface{}{

0 commit comments

Comments
 (0)