@@ -49,6 +49,7 @@ func newDeployCommand() *cobra.Command {
4949 if err != nil {
5050 return err
5151 }
52+
5253 environmentId := firstNonEmpty (state .EnvironmentId , slug (state .Name ))
5354 client := newRleClient (resolveControlPlaneEndpoint ("" ))
5455 request := v1EnvironmentRequest {
@@ -62,16 +63,32 @@ func newDeployCommand() *cobra.Command {
6263 if ! created {
6364 action = "Updating"
6465 }
66+
6567 if _ , err := fmt .Fprintf (cmd .OutOrStdout (), "Skipping build; using existing image '%s'.\n " , image ); err != nil {
6668 return err
6769 }
70+
6871 if _ , err := fmt .Fprintf (cmd .OutOrStdout (), "%s environment '%s' (image=%s) ...\n " , action , state .Name , image ); err != nil {
6972 return err
7073 }
7174 if state .EnvironmentId == "" {
7275 environment , err = client .createV1Environment (cmd .Context (), state .Project , request )
7376 } else {
7477 environment , err = client .updateV1Environment (cmd .Context (), state .Project , environmentId , request )
78+ if isNotFoundError (err ) {
79+ // The recorded environment no longer exists in the target project
80+ // (e.g. the project changed or the control plane was reset). Recreate it.
81+ if _ , msgErr := fmt .Fprintf (
82+ cmd .OutOrStdout (),
83+ "Environment '%s' not found in project '%s'; creating a new one.\n " ,
84+ environmentId ,
85+ state .Project ,
86+ ); msgErr != nil {
87+ return msgErr
88+ }
89+ created = true
90+ environment , err = client .createV1Environment (cmd .Context (), state .Project , request )
91+ }
7592 }
7693 if err != nil {
7794 return serviceError (err )
0 commit comments