@@ -36,6 +36,12 @@ const (
3636 organizationNameFieldName = "name"
3737 organizationDescriptionFieldName = "description"
3838 organizationLockFieldName = "locked"
39+ authenticationProvidersFieldName = "authentication_providers"
40+ enableGithubFieldName = "enable_github"
41+ enableGoogleFieldName = "enable_google"
42+ enableUsernamePasswordFieldName = "enable_username_password"
43+ enableMicrosoftFieldName = "enable_microsoft"
44+ enableSso = "enable_sso"
3945)
4046
4147// resourceOrganization defines an Organization Oasis resource.
@@ -63,6 +69,47 @@ func resourceOrganization() *schema.Resource {
6369 Description : "Organization Resource Organization Lock field" ,
6470 Optional : true ,
6571 },
72+ authenticationProvidersFieldName : {
73+ Type : schema .TypeList ,
74+ Description : "Authentication Provider field" ,
75+ Computed : true ,
76+ Optional : true ,
77+ Elem : & schema.Resource {
78+ Schema : map [string ]* schema.Schema {
79+
80+ enableGithubFieldName : {
81+ Type : schema .TypeBool ,
82+ Description : "Organization Resource Enable Github Login field" ,
83+ Optional : true ,
84+ Default : false ,
85+ },
86+ enableGoogleFieldName : {
87+ Type : schema .TypeBool ,
88+ Description : "Organization Resource Enable Google Login field" ,
89+ Optional : true ,
90+ Default : false ,
91+ },
92+ enableUsernamePasswordFieldName : {
93+ Type : schema .TypeBool ,
94+ Description : "Organization Resource Enable Username Password Login field" ,
95+ Optional : true ,
96+ Default : false ,
97+ },
98+ enableMicrosoftFieldName : {
99+ Type : schema .TypeBool ,
100+ Description : "Organization Resource Enable Microsoft Login field" ,
101+ Optional : true ,
102+ Default : false ,
103+ },
104+ enableSso : {
105+ Type : schema .TypeBool ,
106+ Description : "Organization Resource Enable Single Sign On(SSO) Login field" ,
107+ Optional : true ,
108+ Default : false ,
109+ },
110+ },
111+ },
112+ },
66113 },
67114 }
68115}
@@ -132,7 +179,9 @@ func expandOrganizationResource(d *schema.ResourceData) (*rm.Organization, error
132179 if v , ok := d .GetOk (organizationLockFieldName ); ok {
133180 ret .Locked = v .(bool )
134181 }
135-
182+ if v , ok := d .GetOk (authenticationProvidersFieldName ); ok {
183+ ret .AuthenticationProviders = expandAuthenticationProviders (v .([]interface {}))
184+ }
136185 return ret , nil
137186}
138187
@@ -178,7 +227,9 @@ func resourceOrganizationUpdate(ctx context.Context, d *schema.ResourceData, m i
178227 if d .HasChange (organizationLockFieldName ) {
179228 organization .Locked = d .Get (organizationLockFieldName ).(bool )
180229 }
181-
230+ if v , ok := d .GetOk (authenticationProvidersFieldName ); ok {
231+ organization .AuthenticationProviders = expandAuthenticationProviders (v .([]interface {}))
232+ }
182233 res , err := rmc .UpdateOrganization (client .ctxWithToken , organization )
183234 if err != nil {
184235 client .log .Error ().Err (err ).Msg ("Failed to update Organization" )
@@ -191,9 +242,50 @@ func resourceOrganizationUpdate(ctx context.Context, d *schema.ResourceData, m i
191242
192243// flattenOrganizationResource will take an Organization object and turn it into a flat map for terraform digestion.
193244func flattenOrganizationResource (organization * rm.Organization ) map [string ]interface {} {
194- return map [string ]interface {}{
245+ result := map [string ]interface {}{
195246 organizationNameFieldName : organization .GetName (),
196247 organizationDescriptionFieldName : organization .GetDescription (),
197248 organizationLockFieldName : organization .GetLocked (),
198249 }
250+ if organization .GetAuthenticationProviders () != nil {
251+ result [authenticationProvidersFieldName ] = flattenAuthenticationProviders (organization .GetAuthenticationProviders ())
252+ }
253+ return result
254+ }
255+
256+ // flattenAuthenticationProviders will take a AuthenticationProviders Spec object and turn it into a flat map for terraform digestion.
257+ func flattenAuthenticationProviders (p * rm.AuthenticationProviders ) []interface {} {
258+ providers := make (map [string ]interface {})
259+ providers [enableGithubFieldName ] = p .GetEnableGithub ()
260+ providers [enableGoogleFieldName ] = p .GetEnableGoogle ()
261+ providers [enableMicrosoftFieldName ] = p .GetEnableMicrosoft ()
262+ providers [enableUsernamePasswordFieldName ] = p .GetEnableUsernamePassword ()
263+ providers [enableSso ] = p .GetEnableSso ()
264+ return []interface {}{
265+ providers ,
266+ }
267+ }
268+
269+ // expandAuthenticationProviders will take a terraform flat map schema data and turn it into an ArangoGraph AuthenticationProviders.
270+ func expandAuthenticationProviders (p []interface {}) * rm.AuthenticationProviders {
271+ result := & rm.AuthenticationProviders {}
272+ for _ , v := range p {
273+ item := v .(map [string ]interface {})
274+ if i , ok := item [enableGithubFieldName ]; ok {
275+ result .EnableGithub = i .(bool )
276+ }
277+ if i , ok := item [enableGoogleFieldName ]; ok {
278+ result .EnableGoogle = i .(bool )
279+ }
280+ if i , ok := item [enableMicrosoftFieldName ]; ok {
281+ result .EnableMicrosoft = i .(bool )
282+ }
283+ if i , ok := item [enableUsernamePasswordFieldName ]; ok {
284+ result .EnableUsernamePassword = i .(bool )
285+ }
286+ if i , ok := item [enableSso ]; ok {
287+ result .EnableSso = i .(bool )
288+ }
289+ }
290+ return result
199291}
0 commit comments