Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support features in App spec #1066

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions digitalocean/app/app_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func appSpecSchema(isResource bool) map[string]*schema.Schema {
Computed: true,
Elem: appSpecDomainSchema(),
},
"features": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "List of features which is applied to the app",
},
"domains": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -1003,6 +1009,7 @@ func expandAppSpec(config []interface{}) *godo.AppSpec {
appSpec := &godo.AppSpec{
Name: appSpecConfig["name"].(string),
Region: appSpecConfig["region"].(string),
Features: expandAppSpecFeatures(appSpecConfig["features"].(*schema.Set)),
Services: expandAppSpecServices(appSpecConfig["service"].([]interface{})),
StaticSites: expandAppSpecStaticSites(appSpecConfig["static_site"].([]interface{})),
Workers: expandAppSpecWorkers(appSpecConfig["worker"].([]interface{})),
Expand Down Expand Up @@ -1033,6 +1040,7 @@ func flattenAppSpec(d *schema.ResourceData, spec *godo.AppSpec) []map[string]int
r := make(map[string]interface{})
r["name"] = (*spec).Name
r["region"] = (*spec).Region
r["features"] = (*spec).Features

if len((*spec).Domains) > 0 {
r["domains"] = flattenAppDomainSpec((*spec).Domains)
Expand Down Expand Up @@ -1712,6 +1720,18 @@ func flattenAppSpecStaticSites(sites []*godo.AppStaticSiteSpec) []map[string]int
return result
}

func expandAppSpecFeatures(featuresConfig *schema.Set) []string {
features := []string{}

for _, feature := range featuresConfig.List() {
if featureString, ok := feature.(string); ok {
features = append(features, featureString)
}
}

return features
}

func expandAppSpecWorkers(config []interface{}) []*godo.AppWorkerSpec {
appWorkers := make([]*godo.AppWorkerSpec, 0, len(config))

Expand Down
40 changes: 40 additions & 0 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,27 @@ func testAccCheckDigitalOceanAppExists(n string, app *godo.App) resource.TestChe
}
}

func TestAccDigitalOceanApp_Features(t *testing.T) {
var app godo.App
appName := acceptance.RandomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: testAccCheckDigitalOceanAppDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDigitalOceanAppConfig_withFeatures, appName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanAppExists("digitalocean_app.foobar", &app),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.features.0", "buildpack-stack=ubuntu-18"),
),
},
},
})
}

var testAccCheckDigitalOceanAppConfig_basic = `
resource "digitalocean_app" "foobar" {
spec {
Expand Down Expand Up @@ -918,6 +939,25 @@ resource "digitalocean_app" "foobar" {
}
}`

var testAccCheckDigitalOceanAppConfig_withFeatures = `
resource "digitalocean_app" "foobar" {
spec {
name = "%s"
region = "ams"
features = ["buildpack-stack=ubuntu-18"]

service {
name = "go-service-with-features"
instance_size_slug = "basic-xxs"

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

var testAccCheckDigitalOceanAppConfig_addService = `
resource "digitalocean_app" "foobar" {
spec {
Expand Down
1 change: 1 addition & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The following arguments are supported:
* `spec` - (Required) A DigitalOcean App spec describing the app.
- `name` - (Required) The name of the app. Must be unique across all apps in the same account.
- `region` - The slug for the DigitalOcean data center region hosting the app.
- `features` - A list of the features applied to the app. The default buildpack can be overridden here. List of available buildpacks can be found using the [doctl CLI](https://docs.digitalocean.com/reference/doctl/reference/apps/list-buildpacks/)
- `domain` - Describes a domain where the application will be made available.
* `name` - The hostname for the domain.
* `type` - The domain type, which can be one of the following:
Expand Down
Loading