klothoplatform / klotho

Klotho - write AWS applications at lightning speed
https://klo.dev
Apache License 2.0
1.13k stars 38 forks source link

Allow region change #997

Closed gordon-klotho closed 2 months ago

gordon-klotho commented 2 months ago

Preview (no deployed resources, allowed)

klotho ❯ AWS_REGION=us-east-2 go run ./cmd/klotho up -n ./pkg/k2/language_host/python/samples/starter/infra-api.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

default-network Success (dry run)
   my-container Success (dry run)
         my-api Success (dry run)
              └ Endpoint: <aws:api_stage:my-api-api:my-api-stage#InvokeUrl>

klotho ❯ AWS_REGION=us-west-2 go run ./cmd/klotho up -n ./pkg/k2/language_host/python/samples/starter/infra-api.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

default-network Success (dry run)
   my-container Success (dry run)
         my-api Success (dry run)
              └ Endpoint: <aws:api_stage:my-api-api:my-api-stage#InvokeUrl>

Deploy switch region (disallowed)

klotho ❯ AWS_REGION=us-east-1 go run ./cmd/klotho up ./pkg/k2/language_host/python/samples/func/infra.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

my-function         Success
          ├ FunctionName: my-function-function-13c70c2
          └ FunctionArn: arn:aws:lambda:us-west-2:338991950301:function:my-function-function-13c70c2
klotho ❯ AWS_REGION=us-east-2 go run ./cmd/klotho up ./pkg/k2/language_host/python/samples/func/infra.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
 894ms ERR > Failed to execute command
  ↳ error=error running up command
          .cause=error resolving initial state
                 .cause=cannot change region (us-west-2 -> us-east-2) with deployed resources: map[my-function:create_complete]
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

exit status 1
gordon-klotho commented 2 months ago

Tested with up -> down -> change region -> up

klotho ❯ AWS_REGION=us-east-2 klotho up pkg/k2/language_host/python/samples/starter/infra.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

default-network         Success
   my-container         Success

klotho ❯ AWS_REGION=us-east-2 klotho down pkg/k2/language_host/python/samples/starter/infra.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

   my-container          Success
default-network          Success

klotho ❯ AWS_REGION=ca-central-1 klotho up pkg/k2/language_host/python/samples/starter/infra.py
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

default-network         Success
   my-container         Success