@@ -52,6 +52,14 @@ type environmentVariableValueModel struct {
5252 ContextParameter types.String `tfsdk:"context_parameter"`
5353}
5454
55+ var allScopes = []string {"builds" , "functions" , "runtime" , "post-processing" }
56+ var allScopesValues = []attr.Value {
57+ types .StringValue ("builds" ),
58+ types .StringValue ("functions" ),
59+ types .StringValue ("runtime" ),
60+ types .StringValue ("post-processing" ),
61+ }
62+
5563func (r * environmentVariableResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
5664 resp .TypeName = req .ProviderTypeName + "_environment_variable"
5765}
@@ -110,15 +118,10 @@ func (r *environmentVariableResource) Schema(_ context.Context, _ resource.Schem
110118 Description : "One or more of builds, functions, runtime, and post-processing" ,
111119 Validators : []validator.Set {
112120 setvalidator .ValueStringsAre (
113- stringvalidator .OneOf ("builds" , "functions" , "runtime" , "post-processing" ),
121+ stringvalidator .OneOf (allScopes ... ),
114122 ),
115123 },
116- Default : setdefault .StaticValue (types .SetValueMust (types .StringType , []attr.Value {
117- types .StringValue ("builds" ),
118- types .StringValue ("functions" ),
119- types .StringValue ("runtime" ),
120- types .StringValue ("post-processing" ),
121- })),
124+ Default : setdefault .StaticValue (types .SetValueMust (types .StringType , allScopesValues )),
122125 },
123126 "values" : schema.SetNestedAttribute {
124127 Optional : true ,
@@ -204,6 +207,9 @@ func (r *environmentVariableResource) Create(ctx context.Context, req resource.C
204207 for i , scope := range plan .Scopes {
205208 scopes [i ] = scope .ValueString ()
206209 }
210+ if hasAllScopes (scopes ) {
211+ scopes = nil
212+ }
207213 var values []netlifyapi.EnvVarValue
208214 var isSecret bool
209215 if len (plan .SecretValues ) > 0 {
@@ -306,6 +312,9 @@ func (r *environmentVariableResource) Update(ctx context.Context, req resource.U
306312 for i , scope := range plan .Scopes {
307313 scopes [i ] = scope .ValueString ()
308314 }
315+ if hasAllScopes (scopes ) {
316+ scopes = nil
317+ }
309318 var values []netlifyapi.EnvVarValue
310319 var isSecret bool
311320 if len (plan .SecretValues ) > 0 {
@@ -431,3 +440,19 @@ func parseValues(values []netlifyapi.EnvVarValue) []environmentVariableValueMode
431440 }
432441 return envVarValues
433442}
443+
444+ func hasAllScopes (scopes []string ) bool {
445+ for _ , scope := range allScopes {
446+ found := false
447+ for _ , s := range scopes {
448+ if s == scope {
449+ found = true
450+ break
451+ }
452+ }
453+ if ! found {
454+ return false
455+ }
456+ }
457+ return true
458+ }
0 commit comments