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

Managed HTTPS Endpoints + Import resources #17

Closed almathew closed 4 years ago

almathew commented 4 years ago

For better or worse, I'm combining two features and a ton of style changes into one PR.

This adds support for Managed HTTPS endpoints and adds support for importing existing resources. I've been testing using the following config:

variable "branch" {
  type = string
  default = ""
}

resource "aptible_app" "demo" {
    env_id = "3724"
    handle = "demo${var.branch}"
    config = {
        "APTIBLE_DOCKER_IMAGE" = "quay.io/aptible/deploy-demo-app"
        "DATABASE_URL" = aptible_db.postgresql.connection_url
        "REDIS_URL" = aptible_db.redis.connection_url
        "FORCE_SSL" = "true"
        "IDLE_TIMEOUT" = 30
    }
}

resource "aptible_endpoint" "demo-https" {
  env_id = "3724"

  service_name = "cmd"
  resource_id = aptible_app.demo.app_id

  default_domain = true
  endpoint_type = "https"
  internal = false
  platform = "alb"
  container_port = 5000
}

resource "aptible_endpoint" "demo-https-custom" {
  env_id = "3724"

  service_name = "cmd"
  resource_id = aptible_app.demo.app_id

  default_domain = false
  managed = true
  domain = "www.aptible-test-leeroy.com"

  endpoint_type = "https"
  internal = false
  platform = "alb"
  container_port = 5000
}

resource "aptible_db" "postgresql" {
  env_id = "3724"
  handle = "postgresql${var.branch}"
  db_type = "postgresql"
  container_size = "512"
  disk_size = "10"
}

resource "aptible_db" "redis" {
  env_id = "3724"
  handle = "redis${var.branch}"
  db_type = "redis"
  container_size = "512"
  disk_size = "10"
}

resource "aptible_replica" "postgresql-replica" {
  env_id = "3724"
  primary_db_id = aptible_db.postgresql.db_id
  handle = "postgresql-replica${var.branch}"
  disk_size = 30
}

Quick import looks something like this (ids replaceable, of course):

terraform import aptible_db.postgresql 39597 && terraform import aptible_db.redis 39596 && terraform import aptible_app.demo 20866 && terraform import aptible_endpoint.demo-https-custom 25906 && terraform import aptible_endpoint.demo-https 25905 && terraform import aptible_replica.postgresql-replica 39598

Pairs with this PR:

almathew commented 4 years ago

Updated to use the correct go-deploy commit now that those changes are squashed + merged

almathew commented 4 years ago

I didn't functionally change tests 😬

robertfairhead commented 4 years ago

@almathew Just checking on this. I think an acceptance test here is needed. Do you want to merge this as is and I can open other PR with that? Or did you want to add here yourself?

almathew commented 4 years ago

I can grab the tests.

almathew commented 4 years ago

Ok, turns out I did miss something stupid (because of course I did). So this PR is now required: https://github.com/aptible/go-deploy/pull/20

Once that's merged, I'll update go.mod, but acceptance tests should pass.

almathew commented 4 years ago

Ok, tests only take a century to run, but they should finally be fixed, updated, and good to go:

PASS
ok      github.com/aptible/terraform-provider-aptible/aptible   3226.310s

I'm going to stop adding bonus stuff to this PR now. It's already way bigger than it should have ever been.