aptible / terraform-provider-aptible

The official Terraform provider for Aptible Deploy
https://registry.terraform.io/providers/aptible/aptible/latest
10 stars 13 forks source link

Add support for container profiles #79

Closed joshraker closed 1 year ago

joshraker commented 1 year ago

https://app.shortcut.com/aptible/story/5186/add-container-profiles-to-terraform

shortcut-integration[bot] commented 1 year ago

This pull request has been linked to Shortcut Story #5186: Add Container Profiles to Terraform.

joshraker commented 1 year ago

Manually verified. No acceptance tests were added using additional container profiles because the test Stack currently doesn't allow them. I will run the existing acceptance tests and post the results.

Terraform:

resource "aptible_database" "test" {
  env_id            = data.aptible_environment.test.env_id
  handle            = "test-database"
  container_profile = "r5"
  container_size    = 4096
}

resource "aptible_app" "test" {
  env_id = data.aptible_environment.test.env_id
  handle = "test-app"
  config = {
    APTIBLE_DOCKER_IMAGE = "nginx:alpine"
    TEST_KEY             = "test_value"
  }
  service {
    process_type           = "cmd"
    container_profile      = "c5"
    container_memory_limit = 4096
  }
}

State:

❯ tf state show aptible_app.test | egrep 'app_id|container_profile'
    app_id   = 46
        container_profile      = "c5"
❯ tf state show aptible_database.test | egrep 'database_id|container_profile'
    container_profile      = "r5"
    database_id            = 32

Confirmed in the API:

[AptibleApi][production] (rails-fantastic-plum) irb(main)> App.find(46).services.first.instance_class
=> "c5"
[AptibleApi][production] (rails-fantastic-plum) irb(main)> Database.find(32).service.instance_class
=> "r5"
joshraker commented 1 year ago

Integration tests are passing

❯ STACK=josh; APTIBLE_API_ROOT_URL="https://api-${STACK}.aptible-sandbox.com" APTIBLE_AUTH_ROOT_URL="https://auth-${STACK}.aptible-sandbox.com" APTIBLE_ACCESS_TOKEN="$(cat "${HOME}/.aptible/tokens.json" | jq ".\"https://auth-${STACK}.aptible-sandbox.com\"" -r)" APTIBLE_ENVIRONMENT_ID=1 make testacc TESTARGS="-run 'TestAccResource(App|Database)'"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run 'TestAccResource(App|Database)' -timeout 120m
?       github.com/aptible/terraform-provider-aptible   [no test files]
=== RUN   TestAccResourceApp_basic
--- PASS: TestAccResourceApp_basic (7.90s)
=== RUN   TestAccResourceApp_deploy
...
--- PASS: TestAccResourceApp_deploy (44.83s)
=== RUN   TestAccResourceApp_updateConfig
...
--- PASS: TestAccResourceApp_updateConfig (81.79s)
=== RUN   TestAccResourceApp_scaleDown
...
--- PASS: TestAccResourceApp_scaleDown (50.58s)
=== RUN   TestAccResourceDatabase_basic
...
--- PASS: TestAccResourceDatabase_basic (213.11s)
=== RUN   TestAccResourceDatabase_redis
...
--- PASS: TestAccResourceDatabase_redis (218.10s)
=== RUN   TestAccResourceDatabase_version
...
--- PASS: TestAccResourceDatabase_version (243.41s)
=== RUN   TestAccResourceDatabase_update
...
--- PASS: TestAccResourceDatabase_update (476.84s)
=== RUN   TestAccResourceDatabase_expectError
--- PASS: TestAccResourceDatabase_expectError (0.38s)
PASS
ok      github.com/aptible/terraform-provider-aptible/aptible   1337.341s
joshraker commented 1 year ago

I'll follow up with a PR with some validation tests and switch the StringInSlice error to a warning.