-
Notifications
You must be signed in to change notification settings - Fork 8
feat(runtime): add haskell runtime #246
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
Open
Yoda-BZH
wants to merge
47
commits into
master
Choose a base branch
from
haskell-add-runtime
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
b0c0ff7
auto-update documentations
Yoda-BZH b622850
fix(haskell): haskell app deploys in 13 minutes
9af1868
fix(haskell): haskell takes a very long time to deploy
a223c57
Merge branch 'master' into haskell-add-runtime
Yoda-BZH fb3b654
fix(haskell): code cleanup
37c5f0f
Merge branch 'master' into haskell-add-runtime
Yoda-BZH 794d724
fix(haskell): tests for additionnal attributes
ffa7ef6
auto-update documentations
Yoda-BZH 2be5183
fix(haskell): typo
5dc5766
fixt(haskell): fix calls to assertError
b6f4d6f
Merge branch 'master' into haskell-add-runtime
Yoda-BZH 0de1ea4
auto-update documentations
Yoda-BZH e3a03ba
Merge branch 'master' into haskell-add-runtime
Yoda-BZH 8c1bd42
fix(haskell): fix vhosts, fix diags
e25306b
Update pkg/resources/haskell/schema.go
Yoda-BZH 0b4c4a0
fix(haskell): remove useless error checking
abcc695
Merge branch 'haskell-add-runtime' of github.com:CleverCloud/terrafor…
4aca689
fix(haskell): fix haskell-specific options
5263fdf
fix(haskell): completely remove haskell prefix in the options
d978d8f
auto-update documentations
Yoda-BZH ae8b296
Merge branch 'master' into haskell-add-runtime
Yoda-BZH 26f0d4e
fix(haskell): cleanup
b5191db
feat(runtime): add haskell runtime
fd62c40
auto-update documentations
Yoda-BZH ea19813
fix(haskell): haskell app deploys in 13 minutes
0161769
fix(haskell): haskell takes a very long time to deploy
da7a839
fix(haskell): code cleanup
2611079
fix(haskell): tests for additionnal attributes
58ff407
auto-update documentations
Yoda-BZH ccd631e
fix(haskell): typo
2bc69c9
fixt(haskell): fix calls to assertError
a795abc
auto-update documentations
Yoda-BZH 3ea0173
fix(haskell): fix vhosts, fix diags
d66f9ac
Update pkg/resources/haskell/schema.go
Yoda-BZH 7eb534d
fix(haskell): remove useless error checking
3073ac2
fix(haskell): fix haskell-specific options
aa86bd4
fix(haskell): completely remove haskell prefix in the options
2ba7d6a
auto-update documentations
Yoda-BZH 836c798
fix(haskell): cleanup
2b2310e
Merge branch 'haskell-add-runtime' of github.com:CleverCloud/terrafor…
224a0fc
fix(haskell): fix test name
c2345fb
fix(haskell): bad hint for field name in tests
368799c
tests(haskell): use a build instance, increase job timeout
8187937
tests(haskell): typo
e00dea6
Merge branch 'master' into haskell-add-runtime
Yoda-BZH 9ce6a0c
Merge branch 'master' into haskell-add-runtime
Yoda-BZH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.