digitalocean_app

Provides a DigitalOcean App resource.

Example Usage

To create an app, provide a DigitalOcean app spec specifying the app's components.

Basic Example

resource "digitalocean_app" "golang-sample" {
  spec {
    name   = "golang-sample"
    region = "ams"

    service {
      name               = "go-service"
      environment_slug   = "go"
      instance_count     = 1
      instance_size_slug = "professional-xs"

      git {
        repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
        branch         = "main"
      }
    }
  }
}

Static Site Example

resource "digitalocean_app" "static-site-example" {
  spec {
    name   = "static-site-example"
    region = "ams"

    static_site {
      name          = "sample-jekyll"
      build_command = "bundle exec jekyll build -d ./public"
      output_dir    = "/public"

      git {
        repo_clone_url = "https://github.com/digitalocean/sample-jekyll.git"
        branch         = "main"
      }
    }
  }
}

Multiple Components Example

resource "digitalocean_app" "mono-repo-example" {
  spec {
    name   = "mono-repo-example"
    region = "ams"
    domain {
      name = "foo.example.com"
    }

    alert {
      rule = "DEPLOYMENT_FAILED"
    }

    # Build a Go project in the api/ directory that listens on port 3000
    # and serves it at https://foo.example.com/api
    service {
      name               = "api"
      environment_slug   = "go"
      instance_count     = 2
      instance_size_slug = "professional-xs"

      github {
        branch         = "main"
        deploy_on_push = true
        repo           = "username/repo"
      }

      source_dir = "api/"
      http_port  = 3000

      alert {
        value    = 75
        operator = "GREATER_THAN"
        window   = "TEN_MINUTES"
        rule     = "CPU_UTILIZATION"
      }

      log_destination {
        name = "MyLogs"
        papertrail {
          endpoint = "syslog+tls://example.com:12345"
        }
      }

      run_command = "bin/api"
    }

    # Builds a static site in the project's root directory
    # and serves it at https://foo.example.com/
    static_site {
      name          = "web"
      build_command = "npm run build"

      github {
        branch         = "main"
        deploy_on_push = true
        repo           = "username/repo"
      }
    }

    database {
      name       = "starter-db"
      engine     = "PG"
      production = false
    }

    ingress {
      rule {
        component {
          name = "api"
        }
        match {
          path {
            prefix = "/api"
          }
        }
      }

      rule {
        component {
          name = "web"
        }

        match {
          path {
            prefix = "/"
          }
        }
      }
    }
  }
}

Argument Reference

The following arguments are supported:

A spec can contain multiple components.

A service can contain:

A static_site can contain:

A worker can contain:

A job can contain:

A function component can contain:

A database can contain:

This resource supports customized create timeouts. The default timeout is 30 minutes.

Attributes Reference

In addition to the above attributes, the following are exported:

Import

An app can be imported using its id, e.g.

terraform import digitalocean_app.myapp fb06ad00-351f-45c8-b5eb-13523c438661