@@ -56,6 +56,7 @@ var githubOAuthService = "github"
5656func CreateApp (ctx context.Context , req CreateReq ) (* CreateRes , diag.Diagnostics ) {
5757 diags := diag.Diagnostics {}
5858 res := & CreateRes {}
59+ tflog .Info (ctx , "CREATE APPLICATION" )
5960
6061 req .Application .SeparateBuild = req .Application .BuildFlavor != ""
6162
@@ -93,7 +94,7 @@ func CreateApp(ctx context.Context, req CreateReq) (*CreateRes, diag.Diagnostics
9394 res .Application = * appRes .Payload ()
9495
9596 // Environment
96- envRes := tmp . UpdateAppEnv (ctx , req .Client , req .Organization , res .Application .ID , req .Environment )
97+ envRes := UpdateAppEnv (ctx , req .Client , req .Organization , res .Application .ID , req .Environment , & diags )
9798 if envRes .HasError () {
9899 diags .AddError ("failed to configure application environment" , envRes .Error ().Error ())
99100 }
@@ -167,3 +168,38 @@ func Create[T RuntimePlan](ctx context.Context, resource RuntimeResource, plan T
167168
168169 return diags
169170}
171+
172+ // this version of UpdateAppEnv first try with Env var validation reports warning
173+ // and perform the update without validation in order to not break anything
174+ // diag parameter only reports warnings, no error
175+ //
176+ // {
177+ // "id":557,
178+ // "message":"Application environment is invalid",
179+ // "type":"error",
180+ // "fields":{
181+ // "CC_TROUBLESHOOT":"must be one of: [troubleshoot, true, 1, yes, enable, enabled, on] (= true) or [off, disable, no, false, disabled, 0] (= false)"
182+ // }
183+ // }
184+ func UpdateAppEnv (ctx context.Context , cc * client.Client , organisationID , applicationID string , envs map [string ]string , diags * diag.Diagnostics ) client.Response [any ] {
185+ res := tmp .UpdateAppEnv (ctx , cc , organisationID , applicationID , envs , true )
186+ if ! res .HasError () {
187+ return res
188+ }
189+
190+ tflog .Info (ctx , "DEBUG" )
191+ // report errors
192+ if apiErr , ok := res .Error ().(* client.APIError ); res .StatusCode () == 400 && ok {
193+ tflog .Info (ctx , "ERR" , map [string ]any {"err" : apiErr })
194+ for key , value := range apiErr .Context {
195+ if key == "type" {
196+ continue
197+ }
198+
199+ diags .AddWarning (
200+ fmt .Sprintf ("Invalid value for %s" , key ), fmt .Sprintf ("%v" , value ))
201+ }
202+ }
203+
204+ return tmp .UpdateAppEnv (ctx , cc , organisationID , applicationID , envs , false )
205+ }
0 commit comments