Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions cloudfoundry/data_source_cf_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func dataSourceApp() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"lifecycle": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
labelsKey: labelsSchema(),
annotationsKey: annotationsSchema(),
},
Expand Down Expand Up @@ -206,6 +210,8 @@ func dataSourceAppRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("health_check_type", proc.HealthCheckType)
}

d.Set("lifecycle", app.LifecycleType)

err = metadataRead(appMetadata, d, meta, true)
if err != nil {
return diag.FromErr(err)
Expand Down
2 changes: 2 additions & 0 deletions cloudfoundry/data_source_cf_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestAccDataSourceApp_normal(t *testing.T) {
resource.TestCheckResourceAttr(refs[0], "state", "STARTED"),
resource.TestCheckResourceAttr(refs[0], "health_check_type", "port"),
resource.TestCheckResourceAttr(refs[0], "health_check_timeout", "180"),
resource.TestCheckResourceAttr(refs[0], "lifecycle", "buildpack"),
resource.TestCheckResourceAttr(refs[0], "buildpacks.0", "staticfile_buildpack"),
resource.TestCheckResourceAttr(refs[0], "buildpacks.1", "binary_buildpack"),
resource.TestCheckResourceAttr(refs[0], "environment.%", "2"),
Expand All @@ -116,6 +117,7 @@ func TestAccDataSourceApp_normal(t *testing.T) {
resource.TestCheckResourceAttr(refs[1], "state", "STARTED"),
resource.TestCheckResourceAttr(refs[1], "health_check_type", "port"),
resource.TestCheckResourceAttr(refs[1], "health_check_timeout", "180"),
resource.TestCheckResourceAttr(refs[1], "lifecycle", "buildpack"),
resource.TestCheckResourceAttr(refs[1], "buildpacks.0", "staticfile_buildpack"),
resource.TestCheckResourceAttr(refs[1], "buildpacks.1", "binary_buildpack"),
resource.TestCheckResourceAttr(refs[1], "environment.%", "2"),
Expand Down
15 changes: 15 additions & 0 deletions cloudfoundry/resource_cf_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ func resourceApp() *schema.Resource {
},
labelsKey: labelsSchema(),
annotationsKey: annotationsSchema(),
"lifecycle": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateAppLifecycle,
},
},

CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error {
Expand Down Expand Up @@ -284,6 +291,14 @@ func validateAppV3HealthCheckType(v interface{}, k string) (ws []string, errs []
return ws, errs
}

func validateAppLifecycle(v interface{}, k string) (ws []string, errs []error) {
value := v.(string)
if value != "buildpack" && value != "docker" && value != "cnb" {
errs = append(errs, fmt.Errorf("%q must be one of 'buildpack', 'docker' or 'cnb'", k))
}
return ws, errs
}

func validateV3Strategy(v interface{}, k string) (ws []string, errs []error) {
value := strings.ToLower(v.(string))
if value == "none" {
Expand Down
9 changes: 8 additions & 1 deletion cloudfoundry/resource_cf_feature_flags.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cloudfoundry

import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"context"
"fmt"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"

Expand Down Expand Up @@ -135,6 +136,12 @@ func resourceConfig() *schema.Resource {
Optional: true,
Computed: true,
},
"diego_cnb": &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validateFeatureFlagValue,
Optional: true,
Computed: true,
},
},
},
},
Expand Down
11 changes: 10 additions & 1 deletion cloudfoundry/resource_cf_feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cloudfoundry

import (
"fmt"
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
"testing"

"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand Down Expand Up @@ -72,6 +73,10 @@ func TestAccResConfig_normal(t *testing.T) {
resConfig, "feature_flags.0.service_instance_sharing", "enabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.hide_marketplace_from_unauthenticated_users", "disabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.resource_matching", "enabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.diego_cnb", "disabled"),
),
},

Expand Down Expand Up @@ -109,6 +114,10 @@ func TestAccResConfig_normal(t *testing.T) {
resConfig, "feature_flags.0.service_instance_sharing", "enabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.hide_marketplace_from_unauthenticated_users", "disabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.resource_matching", "enabled"),
resource.TestCheckResourceAttr(
resConfig, "feature_flags.0.diego_cnb", "disabled"),
),
},
resource.TestStep{
Expand Down
6 changes: 6 additions & 0 deletions cloudfoundry/structures_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ func ResourceDataToAppDeployV3(d *schema.ResourceData) (v3appdeployers.AppDeploy
State: stateAsk,
}

// Set lifecycle type if provided
if lifecycle, ok := d.GetOk("lifecycle"); ok {
app.LifecycleType = v3Constants.AppLifecycleType(lifecycle.(string))
}

if bpkgs, ok := d.GetOk("buildpacks"); ok {
buildpacks := make([]string, 0)
for _, bpkg := range bpkgs.([]interface{}) {
Expand Down Expand Up @@ -451,6 +456,7 @@ func AppDeployV3ToResourceData(d *schema.ResourceData, appDeploy v3appdeployers.

}
_ = d.Set("routes", finalMappings)
_ = d.Set("lifecycle", appDeploy.App.LifecycleType)

}

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ The following attributes are exported:
* `health_check_http_endpoint` - The endpoint for the http health check type.
* `health_check_type` - The health check type which can be one of "`port`", "`process`", "`http`" or "`none`".
* `health_check_timeout` - The timeout in seconds for the health check.
* `lifecycle` - The lifecycle type for the application (`buildpack`, `docker`, or `cnb`).
* `labels` - Labels as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object).
* `annotations` - Annotations as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object).
1 change: 1 addition & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The following arguments are supported:
* `buildpacks` - (Optional, List) Multiple `buildpacks` used to stage the application. When both `buildpack` and `buildpacks` are set, `buildpacks` wins. There are multiple options to choose from:
* a Git URL (e.g. [https://github.com/cloudfoundry/java-buildpack.git](https://github.com/cloudfoundry/java-buildpack.git)) or a Git URL with a branch or tag (e.g. [https://github.com/cloudfoundry/java-buildpack.git#v3.3.0](https://github.com/cloudfoundry/java-buildpack.git#v3.3.0) for v3.3.0 tag)
* an installed admin buildpack name (e.g. my-buildpack)
* `lifecycle` - (Optional, String) The lifecycle type for the application. Valid values are `buildpack`, `docker`, and `cnb` (Cloud Native Buildpacks). If not specified, Cloud Foundry will automatically determine the lifecycle type based on the application configuration. **Note:** Changing this value will force the application to be deleted and recreated.
* `command` - (Optional, String) A custom start command for the application. This overrides the start command provided by the buildpack.
* `enable_ssh` - (Optional, Boolean) Whether to enable or disable SSH access to the container. Default is `true` unless disabled globally.
* `timeout` - (Optional, Number) Max wait time for app instance startup, in seconds. Defaults to 60 seconds.
Expand Down
34 changes: 21 additions & 13 deletions docs/resources/feature_flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ The following is an example updates Cloud Foundry feature flags. Each of the fla
resource "cloudfoundry_feature_flags" "config" {

feature_flags {
user_org_creation = false
private_domain_creation = true
app_bits_upload = true
app_scaling = true
route_creation = true
service_instance_creation = true
diego_docker = false
set_roles_by_username = true
unset_roles_by_username = true
task_creation = true
env_var_visibility = true
space_scoped_private_broker_creation = true
space_developer_env_var_visibility = true
user_org_creation = false
private_domain_creation = true
app_bits_upload = true
app_scaling = true
route_creation = true
service_instance_creation = true
diego_docker = false
set_roles_by_username = true
unset_roles_by_username = true
task_creation = true
env_var_visibility = true
space_scoped_private_broker_creation = true
space_developer_env_var_visibility = true
service_instance_sharing = true
hide_marketplace_from_unauthenticated_users = false
resource_matching = true
diego_cnb = true
}
}
```
Expand All @@ -55,6 +59,10 @@ The following arguments are supported:
* `env_var_visibility` - (Optional) All users can view environment variables. Minimum CC API version: 2.58.
* `space_scoped_private_broker_creation` - (Optional) Space Developers can create space-scoped private service brokers. Minimum CC API version: 2.58.
* `space_developer_env_var_visibility` - (Optional) Space Developers can view their v2 environment variables. Org Managers and Space Managers can view their v3 environment variables. Minimum CC API version: 2.58.
* `service_instance_sharing` - (Optional) Space Developers can share service instances between spaces.
* `hide_marketplace_from_unauthenticated_users` - (Optional) Marketplace is hidden from unauthenticated users.
* `resource_matching` - (Optional) Enable resource matching when pushing applications.
* `diego_cnb` - (Optional) Enable Cloud Native Buildpacks (CNB) support in Diego.

When not provided, optional fields are filled with their actual value in Cloud Foundry.

Expand Down