Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fb10bf0
feat(runtime): add haskell runtime
Sep 18, 2025
b0c0ff7
auto-update documentations
Yoda-BZH Sep 18, 2025
b622850
fix(haskell): haskell app deploys in 13 minutes
Sep 18, 2025
9af1868
fix(haskell): haskell takes a very long time to deploy
Sep 18, 2025
a223c57
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Sep 18, 2025
fb3b654
fix(haskell): code cleanup
Sep 19, 2025
37c5f0f
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Sep 19, 2025
794d724
fix(haskell): tests for additionnal attributes
Sep 19, 2025
ffa7ef6
auto-update documentations
Yoda-BZH Sep 19, 2025
2be5183
fix(haskell): typo
Sep 19, 2025
5dc5766
fixt(haskell): fix calls to assertError
Sep 19, 2025
b6f4d6f
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Sep 25, 2025
0de1ea4
auto-update documentations
Yoda-BZH Sep 25, 2025
e3a03ba
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Oct 1, 2025
8c1bd42
fix(haskell): fix vhosts, fix diags
Oct 1, 2025
e25306b
Update pkg/resources/haskell/schema.go
Yoda-BZH Oct 1, 2025
0b4c4a0
fix(haskell): remove useless error checking
Oct 1, 2025
abcc695
Merge branch 'haskell-add-runtime' of github.com:CleverCloud/terrafor…
Oct 1, 2025
4aca689
fix(haskell): fix haskell-specific options
Oct 1, 2025
5263fdf
fix(haskell): completely remove haskell prefix in the options
Oct 1, 2025
d978d8f
auto-update documentations
Yoda-BZH Oct 1, 2025
ae8b296
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Oct 2, 2025
26f0d4e
fix(haskell): cleanup
Oct 2, 2025
b5191db
feat(runtime): add haskell runtime
Sep 18, 2025
fd62c40
auto-update documentations
Yoda-BZH Sep 18, 2025
ea19813
fix(haskell): haskell app deploys in 13 minutes
Sep 18, 2025
0161769
fix(haskell): haskell takes a very long time to deploy
Sep 18, 2025
da7a839
fix(haskell): code cleanup
Sep 19, 2025
2611079
fix(haskell): tests for additionnal attributes
Sep 19, 2025
58ff407
auto-update documentations
Yoda-BZH Sep 19, 2025
ccd631e
fix(haskell): typo
Sep 19, 2025
2bc69c9
fixt(haskell): fix calls to assertError
Sep 19, 2025
a795abc
auto-update documentations
Yoda-BZH Sep 25, 2025
3ea0173
fix(haskell): fix vhosts, fix diags
Oct 1, 2025
d66f9ac
Update pkg/resources/haskell/schema.go
Yoda-BZH Oct 1, 2025
7eb534d
fix(haskell): remove useless error checking
Oct 1, 2025
3073ac2
fix(haskell): fix haskell-specific options
Oct 1, 2025
aa86bd4
fix(haskell): completely remove haskell prefix in the options
Oct 1, 2025
2ba7d6a
auto-update documentations
Yoda-BZH Oct 1, 2025
836c798
fix(haskell): cleanup
Oct 2, 2025
2b2310e
Merge branch 'haskell-add-runtime' of github.com:CleverCloud/terrafor…
Oct 13, 2025
224a0fc
fix(haskell): fix test name
Oct 13, 2025
c2345fb
fix(haskell): bad hint for field name in tests
Oct 13, 2025
368799c
tests(haskell): use a build instance, increase job timeout
Oct 13, 2025
8187937
tests(haskell): typo
Oct 13, 2025
e00dea6
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Oct 13, 2025
9ce6a0c
Merge branch 'master' into haskell-add-runtime
Yoda-BZH Oct 16, 2025
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
144 changes: 144 additions & 0 deletions docs/resources/haskell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "clevercloud_haskell Resource - terraform-provider-clevercloud"
description: |-
Manage Haskell https://www.haskell.org/ applications.
See Haskell https://www.clever.cloud/developers/doc/applications/haskell/.
Example usage
Basic

resource "clevercloud_haskell" "myapp" {
name = "tf-myapp"
region = "par"
min_instance_count = 1
max_instance_count = 2
smallest_flavor = "XS"
biggest_flavor = "M"
}

Advanced

resource "clevercloud_haskell" "myapp" {
name = "tf-myapp"
region = "par"
min_instance_count = 1
max_instance_count = 2
smallest_flavor = "XS"
biggest_flavor = "M"
dependencies = [
"addon_bcc1d486-90f2-4e89-892d-38dbd8f7bc32"
]
deployment {
repository = "https://github.com/..."
}
}
---

# clevercloud_haskell (Resource)

Manage [Haskell](https://www.haskell.org/) applications.

See [Haskell](https://www.clever.cloud/developers/doc/applications/haskell/).

## Example usage

### Basic

```terraform
resource "clevercloud_haskell" "myapp" {
name = "tf-myapp"
region = "par"
min_instance_count = 1
max_instance_count = 2
smallest_flavor = "XS"
biggest_flavor = "M"
}
```

### Advanced

```terraform
resource "clevercloud_haskell" "myapp" {
name = "tf-myapp"
region = "par"
min_instance_count = 1
max_instance_count = 2
smallest_flavor = "XS"
biggest_flavor = "M"
dependencies = [
"addon_bcc1d486-90f2-4e89-892d-38dbd8f7bc32"
]
deployment {
repository = "https://github.com/..."
}
}
```



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `biggest_flavor` (String) Biggest instance flavor, if different from smallest, enable auto-scaling
- `max_instance_count` (Number) Maximum instance count, if different from min value, enable auto-scaling
- `min_instance_count` (Number) Minimum instance count
- `name` (String) Application name
- `smallest_flavor` (String) Smallest instance flavor

### Optional

- `app_folder` (String) Folder in which the application is located (inside the git repository)
- `build_flavor` (String) Use dedicated instance with given flavor for build phase
- `dependencies` (Set of String) A list of application or add-ons required to run this application.
Can be either app_xxx or postgres_yyy ID format
- `deployment` (Block, Optional) (see [below for nested schema](#nestedblock--deployment))
- `description` (String) Application description
- `environment` (Map of String, Sensitive) Environment variables injected into the application
- `haskell_stack_install_command` (String) Only use this variable to override the default `install` Stack step command.
- `haskell_stack_install_dependencies_command` (String) Only use this variable to override the default `install --only-dependencies` Stack step command
- `haskell_stack_setup_command` (String) Only use this variable to override the default `setup` Stack step command.
- `haskell_stack_target` (String) Specify Stack package target.
- `hooks` (Block, Optional) (see [below for nested schema](#nestedblock--hooks))
- `redirect_https` (Boolean) Redirect client from plain to TLS port
- `region` (String) Geographical region where the database will be deployed
- `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped
- `vhosts` (Attributes Set) List of virtual hosts (see [below for nested schema](#nestedatt--vhosts))

### Read-Only

- `deploy_url` (String) Git URL used to push source code
- `id` (String) Unique identifier generated during application creation

<a id="nestedblock--deployment"></a>
### Nested Schema for `deployment`

Optional:

- `commit` (String) Support multiple syntax like `refs/heads/[BRANCH]` or `[COMMIT]`, in most of the case, you can use `refs/heads/master`
- `repository` (String) The repository URL to deploy, can be 'https://...', 'file://...'


<a id="nestedblock--hooks"></a>
### Nested Schema for `hooks`

Optional:

- `post_build` (String) [CC_POST_BUILD_HOOK](https://www.clever.cloud/developers/doc/develop/build-hooks/#post-build)
- `pre_build` (String) [CC_PRE_BUILD_HOOK](https://www.clever.cloud/developers/doc/develop/build-hooks/#pre-build)
- `pre_run` (String) [CC_PRE_RUN_HOOK](https://www.clever.cloud/developers/doc/develop/build-hooks/#pre-run)
- `run_failed` (String) [CC_RUN_FAILED_HOOK](https://www.clever.cloud/developers/doc/develop/build-hooks/#run-successfail)
- `run_succeed` (String) [CC_RUN_SUCCEEDED_HOOK](https://www.clever.cloud/developers/doc/develop/build-hooks/#run-successfail)


<a id="nestedatt--vhosts"></a>
### Nested Schema for `vhosts`

Required:

- `fqdn` (String) Fully qualified domain name

Optional:

- `path_begin` (String) Any HTTP request starting with this path will be sent to this application
2 changes: 2 additions & 0 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.clever-cloud.com/terraform-provider/pkg/resources/frankenphp"
"go.clever-cloud.com/terraform-provider/pkg/resources/fsbucket"
"go.clever-cloud.com/terraform-provider/pkg/resources/golang"
"go.clever-cloud.com/terraform-provider/pkg/resources/haskell"
"go.clever-cloud.com/terraform-provider/pkg/resources/java"
"go.clever-cloud.com/terraform-provider/pkg/resources/keycloak"
"go.clever-cloud.com/terraform-provider/pkg/resources/materiakv"
Expand Down Expand Up @@ -68,4 +69,5 @@ var Resources = []func() resource.Resource{
pulsar.NewResourcePulsar,
rust.NewResourceRust,
networkgroup.NewResourceNetworkgroup,
haskell.NewResourceHaskell,
}
227 changes: 227 additions & 0 deletions pkg/resources/haskell/crud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package haskell

import (
"context"
"reflect"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
"go.clever-cloud.com/terraform-provider/pkg"
"go.clever-cloud.com/terraform-provider/pkg/application"
"go.clever-cloud.com/terraform-provider/pkg/helper"
"go.clever-cloud.com/terraform-provider/pkg/tmp"
)

// Create a new resource
func (r *ResourceHaskell) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
plan := helper.PlanFrom[Haskell](ctx, req.Plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

vhosts := plan.VHostsAsStrings(ctx, &resp.Diagnostics)

instance := application.LookupInstanceByVariantSlug(ctx, r.Client(), nil, "haskell", resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

environment := plan.toEnv(ctx, resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

dependencies := plan.DependenciesAsString(ctx, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

createReq := application.CreateReq{
Client: r.Client(),
Organization: r.Organization(),
Application: tmp.CreateAppRequest{
Name: plan.Name.ValueString(),
Deploy: "git",
Description: plan.Description.ValueString(),
InstanceType: instance.Type,
InstanceVariant: instance.Variant.ID,
InstanceVersion: instance.Version,
MinFlavor: plan.SmallestFlavor.ValueString(),
MaxFlavor: plan.BiggestFlavor.ValueString(),
MinInstances: plan.MinInstanceCount.ValueInt64(),
MaxInstances: plan.MaxInstanceCount.ValueInt64(),
BuildFlavor: plan.BuildFlavor.ValueString(),
StickySessions: plan.StickySessions.ValueBool(),
ForceHttps: application.FromForceHTTPS(plan.RedirectHTTPS.ValueBool()),
Zone: plan.Region.ValueString(),
},
Environment: environment,
VHosts: vhosts,
Deployment: plan.toDeployment(r.GitAuth()),
Dependencies: dependencies,
}

createRes, diags := application.CreateApp(ctx, createReq)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// TODO set fields
plan.ID = pkg.FromStr(createRes.Application.ID)
plan.DeployURL = pkg.FromStr(createRes.Application.DeployURL)

resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)

createdVhosts := createRes.Application.Vhosts
if plan.VHosts.IsUnknown() { // practitionner does not provide any vhost, return the cleverapps one
plan.VHosts = pkg.FromSetString(createdVhosts.AsString(), &resp.Diagnostics)
} else { // practitionner give it's own vhost, remove cleverapps one

for _, vhost := range pkg.Diff(vhosts, createdVhosts.AsString()) {
deleteVhostRes := tmp.DeleteAppVHost(
ctx,
r.Client(),
r.Organization(),
plan.ID.ValueString(),
vhost,
)
if deleteVhostRes.HasError() {
diags.AddError("failed to remove vhost", deleteVhostRes.Error().Error())
return
}
}
}

resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
}

// Read resource information
func (r *ResourceHaskell) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Debug(ctx, "Haskell READ", map[string]any{"request": req})

state := helper.StateFrom[Haskell](ctx, req.State, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

appRes, diags := application.ReadApp(ctx, r.Client(), r.Organization(), state.ID.ValueString())
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
if appRes.AppIsDeleted {
resp.State.RemoveResource(ctx)
return
}

state.DeployURL = pkg.FromStr(appRes.App.DeployURL)
state.Name = pkg.FromStr(appRes.App.Name)
state.Description = pkg.FromStr(appRes.App.Description)
state.Region = pkg.FromStr(appRes.App.Zone)
state.MinInstanceCount = basetypes.NewInt64Value(int64(appRes.App.Instance.MinInstances))
state.MaxInstanceCount = basetypes.NewInt64Value(int64(appRes.App.Instance.MaxInstances))
state.SmallestFlavor = pkg.FromStr(appRes.App.Instance.MinFlavor.Name)
state.BiggestFlavor = pkg.FromStr(appRes.App.Instance.MaxFlavor.Name)

vhosts := appRes.App.Vhosts.AsString()
state.VHosts = pkg.FromSetString(vhosts, &resp.Diagnostics)

diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}

// Update resource
func (r *ResourceHaskell) Update(ctx context.Context, req resource.UpdateRequest, res *resource.UpdateResponse) {
tflog.Debug(ctx, "ResourceHaskell.Update()")

// Retrieve values from plan and state
plan := helper.PlanFrom[Haskell](ctx, req.Plan, &res.Diagnostics)
if res.Diagnostics.HasError() {
return
}
state := helper.StateFrom[Haskell](ctx, req.State, &res.Diagnostics)
if res.Diagnostics.HasError() {
return
}

// Retrieve instance of the app from context
instance := application.LookupInstanceByVariantSlug(ctx, r.Client(), nil, "haskell", res.Diagnostics)
if res.Diagnostics.HasError() {
return
}

// Retriev all env values by extracting ctx env viriables and merge it with the app env variables
planEnvironment := plan.toEnv(ctx, res.Diagnostics)
if res.Diagnostics.HasError() {
return
}
stateEnvironment := state.toEnv(ctx, res.Diagnostics)
if res.Diagnostics.HasError() {
return
}

// Same as env but with vhosts
vhosts := plan.VHostsAsStrings(ctx, &res.Diagnostics)
dependencies := plan.DependenciesAsString(ctx, &res.Diagnostics)

// Get the updated values from plan and instance
updateAppReq := application.UpdateReq{
ID: state.ID.ValueString(),
Client: r.Client(),
Organization: r.Organization(),
Application: tmp.UpdateAppReq{
Name: plan.Name.ValueString(),
Deploy: "git",
Description: plan.Description.ValueString(),
InstanceType: instance.Type,
InstanceVariant: instance.Variant.ID,
InstanceVersion: instance.Version,
BuildFlavor: plan.BuildFlavor.ValueString(),
MinFlavor: plan.SmallestFlavor.ValueString(),
MaxFlavor: plan.BiggestFlavor.ValueString(),
MinInstances: plan.MinInstanceCount.ValueInt64(),
MaxInstances: plan.MaxInstanceCount.ValueInt64(),
StickySessions: plan.StickySessions.ValueBool(),
ForceHttps: application.FromForceHTTPS(plan.RedirectHTTPS.ValueBool()),
Zone: plan.Region.ValueString(),
CancelOnPush: false,
},
Environment: planEnvironment,
VHosts: vhosts,
Dependencies: dependencies,
Deployment: plan.toDeployment(r.GitAuth()),
TriggerRestart: !reflect.DeepEqual(planEnvironment, stateEnvironment),
}

updatedApp, diags := application.UpdateApp(ctx, updateAppReq)
res.Diagnostics.Append(diags...)
if res.Diagnostics.HasError() {
return
}

plan.VHosts = pkg.FromSetString(updatedApp.Application.Vhosts.AsString(), &res.Diagnostics)
res.Diagnostics.Append(res.State.Set(ctx, plan)...)
}

// Delete resource
func (r *ResourceHaskell) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
state := helper.StateFrom[Haskell](ctx, req.State, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
tflog.Debug(ctx, "Haskell DELETE", map[string]any{"app": state.ID.ValueString()})

res := tmp.DeleteApp(ctx, r.Client(), r.Organization(), state.ID.ValueString())
if res.IsNotFoundError() {
resp.State.RemoveResource(ctx)
return
}
if res.HasError() {
resp.Diagnostics.AddError("failed to delete app", res.Error().Error())
return
}

resp.State.RemoveResource(ctx)
}
Loading