diff --git a/cloudfoundry/data_source_cf_app.go b/cloudfoundry/data_source_cf_app.go index 5746233c0..fcc0b915a 100644 --- a/cloudfoundry/data_source_cf_app.go +++ b/cloudfoundry/data_source_cf_app.go @@ -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(), }, @@ -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) diff --git a/cloudfoundry/data_source_cf_app_test.go b/cloudfoundry/data_source_cf_app_test.go index bbde36b1e..ee306f80e 100644 --- a/cloudfoundry/data_source_cf_app_test.go +++ b/cloudfoundry/data_source_cf_app_test.go @@ -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"), @@ -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"), diff --git a/cloudfoundry/resource_cf_app.go b/cloudfoundry/resource_cf_app.go index 9302bbda8..b703a2ce8 100644 --- a/cloudfoundry/resource_cf_app.go +++ b/cloudfoundry/resource_cf_app.go @@ -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 { @@ -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" { diff --git a/cloudfoundry/resource_cf_feature_flags.go b/cloudfoundry/resource_cf_feature_flags.go index cb0e24ee9..437bef5b3 100644 --- a/cloudfoundry/resource_cf_feature_flags.go +++ b/cloudfoundry/resource_cf_feature_flags.go @@ -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" @@ -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, + }, }, }, }, diff --git a/cloudfoundry/resource_cf_feature_flags_test.go b/cloudfoundry/resource_cf_feature_flags_test.go index 8aec63aa9..5253cb766 100644 --- a/cloudfoundry/resource_cf_feature_flags_test.go +++ b/cloudfoundry/resource_cf_feature_flags_test.go @@ -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" ) @@ -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"), ), }, @@ -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{ diff --git a/cloudfoundry/structures_app.go b/cloudfoundry/structures_app.go index 1a93febaf..ac58f69f9 100644 --- a/cloudfoundry/structures_app.go +++ b/cloudfoundry/structures_app.go @@ -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{}) { @@ -451,6 +456,7 @@ func AppDeployV3ToResourceData(d *schema.ResourceData, appDeploy v3appdeployers. } _ = d.Set("routes", finalMappings) + _ = d.Set("lifecycle", appDeploy.App.LifecycleType) } diff --git a/docs/data-sources/app.md b/docs/data-sources/app.md index 254c62f93..3d813b66c 100644 --- a/docs/data-sources/app.md +++ b/docs/data-sources/app.md @@ -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). diff --git a/docs/resources/app.md b/docs/resources/app.md index 6d434ee58..14f40f6c3 100644 --- a/docs/resources/app.md +++ b/docs/resources/app.md @@ -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. diff --git a/docs/resources/feature_flag.md b/docs/resources/feature_flag.md index fdf2c8cbc..3a9270c8b 100644 --- a/docs/resources/feature_flag.md +++ b/docs/resources/feature_flag.md @@ -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 } } ``` @@ -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.