Skip to content

Commit 8885cfa

Browse files
committed
feat(app): add lifecycle parameter with CNB support
Add lifecycle parameter to app resource/datasource and diego_cnb feature flag. Supports 'buildpack', 'docker', and 'cnb' with validation and tests. BREAKING CHANGE: lifecycle changes force app recreation
1 parent cf8ddd6 commit 8885cfa

File tree

9 files changed

+70
-15
lines changed

9 files changed

+70
-15
lines changed

cloudfoundry/data_source_cf_app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func dataSourceApp() *schema.Resource {
8888
Type: schema.TypeInt,
8989
Computed: true,
9090
},
91+
"lifecycle": &schema.Schema{
92+
Type: schema.TypeString,
93+
Computed: true,
94+
},
9195
labelsKey: labelsSchema(),
9296
annotationsKey: annotationsSchema(),
9397
},
@@ -206,6 +210,8 @@ func dataSourceAppRead(ctx context.Context, d *schema.ResourceData, meta interfa
206210
d.Set("health_check_type", proc.HealthCheckType)
207211
}
208212

213+
d.Set("lifecycle", app.LifecycleType)
214+
209215
err = metadataRead(appMetadata, d, meta, true)
210216
if err != nil {
211217
return diag.FromErr(err)

cloudfoundry/data_source_cf_app_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func TestAccDataSourceApp_normal(t *testing.T) {
100100
resource.TestCheckResourceAttr(refs[0], "state", "STARTED"),
101101
resource.TestCheckResourceAttr(refs[0], "health_check_type", "port"),
102102
resource.TestCheckResourceAttr(refs[0], "health_check_timeout", "180"),
103+
resource.TestCheckResourceAttr(refs[0], "lifecycle", "buildpack"),
103104
resource.TestCheckResourceAttr(refs[0], "buildpacks.0", "staticfile_buildpack"),
104105
resource.TestCheckResourceAttr(refs[0], "buildpacks.1", "binary_buildpack"),
105106
resource.TestCheckResourceAttr(refs[0], "environment.%", "2"),
@@ -116,6 +117,7 @@ func TestAccDataSourceApp_normal(t *testing.T) {
116117
resource.TestCheckResourceAttr(refs[1], "state", "STARTED"),
117118
resource.TestCheckResourceAttr(refs[1], "health_check_type", "port"),
118119
resource.TestCheckResourceAttr(refs[1], "health_check_timeout", "180"),
120+
resource.TestCheckResourceAttr(refs[1], "lifecycle", "buildpack"),
119121
resource.TestCheckResourceAttr(refs[1], "buildpacks.0", "staticfile_buildpack"),
120122
resource.TestCheckResourceAttr(refs[1], "buildpacks.1", "binary_buildpack"),
121123
resource.TestCheckResourceAttr(refs[1], "environment.%", "2"),

cloudfoundry/resource_cf_app.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ func resourceApp() *schema.Resource {
240240
},
241241
labelsKey: labelsSchema(),
242242
annotationsKey: annotationsSchema(),
243+
"lifecycle": &schema.Schema{
244+
Type: schema.TypeString,
245+
Optional: true,
246+
Computed: true,
247+
ForceNew: true,
248+
ValidateFunc: validateAppLifecycle,
249+
},
243250
},
244251

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

294+
func validateAppLifecycle(v interface{}, k string) (ws []string, errs []error) {
295+
value := v.(string)
296+
if value != "buildpack" && value != "docker" && value != "cnb" {
297+
errs = append(errs, fmt.Errorf("%q must be one of 'buildpack', 'docker' or 'cnb'", k))
298+
}
299+
return ws, errs
300+
}
301+
287302
func validateV3Strategy(v interface{}, k string) (ws []string, errs []error) {
288303
value := strings.ToLower(v.(string))
289304
if value == "none" {

cloudfoundry/resource_cf_feature_flags.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package cloudfoundry
22

33
import (
4-
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
54
"context"
65
"fmt"
6+
7+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
910

@@ -135,6 +136,12 @@ func resourceConfig() *schema.Resource {
135136
Optional: true,
136137
Computed: true,
137138
},
139+
"diego_cnb": &schema.Schema{
140+
Type: schema.TypeString,
141+
ValidateFunc: validateFeatureFlagValue,
142+
Optional: true,
143+
Computed: true,
144+
},
138145
},
139146
},
140147
},

cloudfoundry/resource_cf_feature_flags_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package cloudfoundry
22

33
import (
44
"fmt"
5-
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
65
"testing"
76

7+
"github.com/terraform-providers/terraform-provider-cloudfoundry/cloudfoundry/managers"
8+
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1011
)
@@ -72,6 +73,10 @@ func TestAccResConfig_normal(t *testing.T) {
7273
resConfig, "feature_flags.0.service_instance_sharing", "enabled"),
7374
resource.TestCheckResourceAttr(
7475
resConfig, "feature_flags.0.hide_marketplace_from_unauthenticated_users", "disabled"),
76+
resource.TestCheckResourceAttr(
77+
resConfig, "feature_flags.0.resource_matching", "enabled"),
78+
resource.TestCheckResourceAttr(
79+
resConfig, "feature_flags.0.diego_cnb", "disabled"),
7580
),
7681
},
7782

@@ -109,6 +114,10 @@ func TestAccResConfig_normal(t *testing.T) {
109114
resConfig, "feature_flags.0.service_instance_sharing", "enabled"),
110115
resource.TestCheckResourceAttr(
111116
resConfig, "feature_flags.0.hide_marketplace_from_unauthenticated_users", "disabled"),
117+
resource.TestCheckResourceAttr(
118+
resConfig, "feature_flags.0.resource_matching", "enabled"),
119+
resource.TestCheckResourceAttr(
120+
resConfig, "feature_flags.0.diego_cnb", "disabled"),
112121
),
113122
},
114123
resource.TestStep{

cloudfoundry/structures_app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ func ResourceDataToAppDeployV3(d *schema.ResourceData) (v3appdeployers.AppDeploy
240240
State: stateAsk,
241241
}
242242

243+
// Set lifecycle type if provided
244+
if lifecycle, ok := d.GetOk("lifecycle"); ok {
245+
app.LifecycleType = v3Constants.AppLifecycleType(lifecycle.(string))
246+
}
247+
243248
if bpkgs, ok := d.GetOk("buildpacks"); ok {
244249
buildpacks := make([]string, 0)
245250
for _, bpkg := range bpkgs.([]interface{}) {
@@ -451,6 +456,7 @@ func AppDeployV3ToResourceData(d *schema.ResourceData, appDeploy v3appdeployers.
451456

452457
}
453458
_ = d.Set("routes", finalMappings)
459+
_ = d.Set("lifecycle", appDeploy.App.LifecycleType)
454460

455461
}
456462

docs/data-sources/app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ The following attributes are exported:
4444
* `health_check_http_endpoint` - The endpoint for the http health check type.
4545
* `health_check_type` - The health check type which can be one of "`port`", "`process`", "`http`" or "`none`".
4646
* `health_check_timeout` - The timeout in seconds for the health check.
47+
* `lifecycle` - The lifecycle type for the application (`buildpack`, `docker`, or `cnb`).
4748
* `labels` - Labels as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object).
4849
* `annotations` - Annotations as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object).

docs/resources/app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The following arguments are supported:
3838
* `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:
3939
* 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)
4040
* an installed admin buildpack name (e.g. my-buildpack)
41+
* `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.
4142
* `command` - (Optional, String) A custom start command for the application. This overrides the start command provided by the buildpack.
4243
* `enable_ssh` - (Optional, Boolean) Whether to enable or disable SSH access to the container. Default is `true` unless disabled globally.
4344
* `timeout` - (Optional, Number) Max wait time for app instance startup, in seconds. Defaults to 60 seconds.

docs/resources/feature_flag.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ The following is an example updates Cloud Foundry feature flags. Each of the fla
2020
resource "cloudfoundry_feature_flags" "config" {
2121
2222
feature_flags {
23-
user_org_creation = false
24-
private_domain_creation = true
25-
app_bits_upload = true
26-
app_scaling = true
27-
route_creation = true
28-
service_instance_creation = true
29-
diego_docker = false
30-
set_roles_by_username = true
31-
unset_roles_by_username = true
32-
task_creation = true
33-
env_var_visibility = true
34-
space_scoped_private_broker_creation = true
35-
space_developer_env_var_visibility = true
23+
user_org_creation = false
24+
private_domain_creation = true
25+
app_bits_upload = true
26+
app_scaling = true
27+
route_creation = true
28+
service_instance_creation = true
29+
diego_docker = false
30+
set_roles_by_username = true
31+
unset_roles_by_username = true
32+
task_creation = true
33+
env_var_visibility = true
34+
space_scoped_private_broker_creation = true
35+
space_developer_env_var_visibility = true
36+
service_instance_sharing = true
37+
hide_marketplace_from_unauthenticated_users = false
38+
resource_matching = true
39+
diego_cnb = true
3640
}
3741
}
3842
```
@@ -55,6 +59,10 @@ The following arguments are supported:
5559
* `env_var_visibility` - (Optional) All users can view environment variables. Minimum CC API version: 2.58.
5660
* `space_scoped_private_broker_creation` - (Optional) Space Developers can create space-scoped private service brokers. Minimum CC API version: 2.58.
5761
* `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.
62+
* `service_instance_sharing` - (Optional) Space Developers can share service instances between spaces.
63+
* `hide_marketplace_from_unauthenticated_users` - (Optional) Marketplace is hidden from unauthenticated users.
64+
* `resource_matching` - (Optional) Enable resource matching when pushing applications.
65+
* `diego_cnb` - (Optional) Enable Cloud Native Buildpacks (CNB) support in Diego.
5866

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

0 commit comments

Comments
 (0)