-
Notifications
You must be signed in to change notification settings - Fork 133
feat(inference): add support CRUD deployment #2736
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
Merged
remyleone
merged 50 commits into
scaleway:master
from
Laure-di:feat-add-support-inference
Oct 28, 2024
Merged
Changes from 37 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
6121310
fix templates
Laure-di 769b63a
fix waiters template defaultRetryInterval
Laure-di 3818f52
fix test templates
Laure-di 3ee54d9
fix sweeper test
Laure-di 916049f
fix sweeper test
Laure-di 7664365
separate sweeper
Laure-di bbe296a
fix test resource
Laure-di c4b1b0c
add sweep template and test
Laure-di bebf2f5
fix resource and helper
Laure-di 03e0e9f
fix name resource
Laure-di 7b2f95a
feat(inference): add support
Laure-di 9636658
fix package name
Laure-di b57f7f5
add deployment_resource to provider
Laure-di 28f6b25
fix method name
Laure-di 5168bb9
create deployment fix
Laure-di 215ac39
create deployment finish
Laure-di 2c44fed
add testdata create deployment
Laure-di 531e3a6
dev read deployment
Laure-di c143b3a
Merge branch 'master' into feat-add-support-inference
Laure-di 78b2f01
sweep and sweeper_test
Laure-di d9f50a1
gofumpt
Laure-di 65da5ae
clean import
Laure-di dfcfb4b
organize endpoint create
Laure-di d026fc6
add tests endpoints
Laure-di 06edac4
read set endpoints url
Laure-di d9d061d
manage endpoints read and auth
Laure-di a56e7ad
add create_at and updated_at read
Laure-di ba6c799
gci fix
Laure-di 73e3be9
add checks.go and change tests names
Laure-di 9e587c3
fix type tfprovider-lint
Laure-di c9da181
fix golangci-lint
Laure-di 7feb5e0
fix tests
Laure-di caadd43
fix test compute size
Laure-di 67a5a17
fix golangci
Laure-di f22e85b
Merge branch 'master' into feat-add-support-inference
Laure-di 75b6b6f
Update internal/services/inference/testfuncs/checks.go
Laure-di fc8d29f
fix review
Laure-di 15598f3
change endpoints
Laure-di 713c990
fix endpoints
Laure-di adb9c7d
fix lint
Laure-di 0728de0
Merge branch 'master' into feat-add-support-inference
Laure-di bdb7283
Update internal/services/inference/deployment.go
Laure-di cf8b820
fix update and min_size, max_size
Laure-di 0e5ac6b
add tests
Laure-di 663fd5e
remove default deployment size
Codelax afcbf34
lower retry interval
Codelax 7b1d228
update cassettes
Codelax 5390f89
add doc
Codelax cc2b8aa
improve doc
Codelax 47c753e
Merge branch 'master' into feat-add-support-inference
Laure-di 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
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 |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ package main | |
| import ( | ||
| "log" | ||
| "os" | ||
| "strings" | ||
| "text/template" | ||
|
|
||
| "strings" | ||
| "tftemplate/models" | ||
| ) | ||
|
|
||
|
|
||
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,308 @@ | ||
| package inference | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| inference "github.com/scaleway/scaleway-sdk-go/api/inference/v1beta1" | ||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||
| "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||
| ) | ||
|
|
||
| func ResourceDeployment() *schema.Resource { | ||
| return &schema.Resource{ | ||
| CreateContext: ResourceDeploymentCreate, | ||
| ReadContext: ResourceDeploymentRead, | ||
| UpdateContext: ResourceDeploymentUpdate, | ||
| DeleteContext: ResourceDeploymentDelete, | ||
| Importer: &schema.ResourceImporter{ | ||
| StateContext: schema.ImportStatePassthroughContext, | ||
| }, | ||
| Timeouts: &schema.ResourceTimeout{ | ||
| Create: schema.DefaultTimeout(defaultInferenceDeploymentTimeout), | ||
| Read: schema.DefaultTimeout(defaultInferenceDeploymentTimeout), | ||
| Update: schema.DefaultTimeout(defaultInferenceDeploymentTimeout), | ||
| Delete: schema.DefaultTimeout(defaultInferenceDeploymentTimeout), | ||
| Default: schema.DefaultTimeout(defaultInferenceDeploymentTimeout), | ||
| }, | ||
| SchemaVersion: 0, | ||
| Schema: map[string]*schema.Schema{ | ||
| "name": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Optional: true, | ||
| Description: "The deployment name", | ||
| }, | ||
| "region": regional.Schema(), | ||
| "project_id": account.ProjectIDSchema(), | ||
| "node_type": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: "The node type to use for the deployment", | ||
| }, | ||
| "model_name": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: "The model name to use for the deployment", | ||
| }, | ||
| "model_id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The model id used for the deployment", | ||
| }, | ||
| "accept_eula": { | ||
| Type: schema.TypeBool, | ||
| Optional: true, | ||
| Default: false, | ||
| Description: "Whether or not the deployment is accepting eula", | ||
| }, | ||
| "tags": { | ||
| Type: schema.TypeList, | ||
| Elem: &schema.Schema{Type: schema.TypeString}, | ||
| Optional: true, | ||
| Description: "The tags associated with the deployment", | ||
| }, | ||
| "min_size": { | ||
| Type: schema.TypeInt, | ||
| Optional: true, | ||
| Computed: true, | ||
| Description: "The minimum size of the pool", | ||
| }, | ||
| "max_size": { | ||
| Type: schema.TypeInt, | ||
| Optional: true, | ||
| Computed: true, | ||
| Description: "The maximum size of the pool", | ||
| }, | ||
| "size": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| Description: "The size of the pool", | ||
| }, | ||
| "status": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The status of the deployment", | ||
| }, | ||
| "endpoint_public_url": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The endpoint public URL", | ||
| }, | ||
| "endpoint_private_url": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The endpoint private URL", | ||
| }, | ||
| "disable_auth_private": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
remyleone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Description: "Whether or not the authentication on the private endpoint is disabled.", | ||
| }, | ||
| "endpoint_public_id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The endpoint public ID", | ||
| }, | ||
| "endpoint_private_id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The endpoint private ID", | ||
| }, | ||
| "disable_auth_public": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
remyleone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Description: "Whether or not the authentication on the public endpoint is disabled.", | ||
| }, | ||
| "created_at": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The date and time of the creation of the deployment", | ||
| }, | ||
| "updated_at": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The date and time of the last update of the deployment", | ||
| }, | ||
| "endpoints": { | ||
Laure-di marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Type: schema.TypeList, | ||
| Required: true, | ||
| Description: "List of endpoints", | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "public_endpoint": { | ||
| Type: schema.TypeBool, | ||
| Description: "Set the endpoint as public", | ||
| Optional: true, | ||
| }, | ||
| "private_endpoint": { | ||
| Type: schema.TypeString, | ||
| Description: "The id of the private network", | ||
| Optional: true, | ||
| }, | ||
Laure-di marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "disable_auth": { | ||
Codelax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Type: schema.TypeBool, | ||
| Description: "Disable the authentication on the endpoint.", | ||
| Optional: true, | ||
| Default: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func ResourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
| api, region, err := NewAPIWithRegion(d, m) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| req := &inference.CreateDeploymentRequest{ | ||
| Region: region, | ||
| ProjectID: d.Get("project_id").(string), | ||
| Name: d.Get("name").(string), | ||
| NodeType: d.Get("node_type").(string), | ||
| ModelName: d.Get("model_name").(string), | ||
| Tags: types.ExpandStrings(d.Get("tags")), | ||
| } | ||
|
|
||
| endpoint := inference.EndpointSpec{ | ||
| Public: nil, | ||
| PrivateNetwork: nil, | ||
| DisableAuth: false, | ||
| } | ||
|
|
||
| if _, isEndpoint := d.GetOk("endpoints"); isEndpoint { | ||
| if publicEndpoint := d.Get("endpoints.0.public_endpoint"); publicEndpoint != nil && publicEndpoint.(bool) { | ||
| endpoint.Public = &inference.EndpointSpecPublic{} | ||
| } | ||
| if privateEndpoint := d.Get("endpoints.0.private_endpoint"); privateEndpoint != "" { | ||
| endpoint.PrivateNetwork = &inference.EndpointSpecPrivateNetwork{ | ||
| PrivateNetworkID: regional.ExpandID(privateEndpoint.(string)).ID, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| req.Endpoints = []*inference.EndpointSpec{&endpoint} | ||
Laure-di marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if isAcceptingEula, ok := d.GetOk("accept_eula"); ok { | ||
| req.AcceptEula = scw.BoolPtr(isAcceptingEula.(bool)) | ||
| } | ||
|
|
||
| deployment, err := api.CreateDeployment(req, scw.WithContext(ctx)) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| d.SetId(regional.NewIDString(region, deployment.ID)) | ||
|
|
||
| _, err = waitForDeployment(ctx, api, region, deployment.ID, d.Timeout(schema.TimeoutCreate)) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return ResourceDeploymentRead(ctx, d, m) | ||
| } | ||
|
|
||
| func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
| api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| deployment, err := waitForDeployment(ctx, api, region, id, d.Timeout(schema.TimeoutRead)) | ||
| if err != nil { | ||
| if httperrors.Is404(err) { | ||
| d.SetId("") | ||
| return nil | ||
| } | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| _ = d.Set("name", deployment.Name) | ||
| _ = d.Set("region", deployment.Region) | ||
| _ = d.Set("project_id", deployment.ProjectID) | ||
| _ = d.Set("node_type", deployment.NodeType) | ||
| _ = d.Set("model_name", deployment.ModelName) | ||
| _ = d.Set("min_size", int(deployment.MinSize)) | ||
| _ = d.Set("max_size", int(deployment.MaxSize)) | ||
| _ = d.Set("size", int(deployment.Size)) | ||
| _ = d.Set("status", deployment.Status) | ||
| _ = d.Set("model_id", deployment.ModelID) | ||
| _ = d.Set("created_at", types.FlattenTime(deployment.CreatedAt)) | ||
| _ = d.Set("updated_at", types.FlattenTime(deployment.UpdatedAt)) | ||
|
|
||
| for _, endpoint := range deployment.Endpoints { | ||
Laure-di marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if endpoint.PrivateNetwork != nil { | ||
| _ = d.Set("endpoint_private_url", endpoint.URL) | ||
| _ = d.Set("endpoint_private_id", endpoint.ID) | ||
| _ = d.Set("disable_auth_private", endpoint.DisableAuth) | ||
| } else { | ||
| _ = d.Set("endpoint_public_url", endpoint.URL) | ||
| _ = d.Set("endpoint_public_id", endpoint.ID) | ||
| _ = d.Set("disable_auth_public", endpoint.DisableAuth) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func ResourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
| api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| deployment, err := waitForDeployment(ctx, api, region, id, d.Timeout(schema.TimeoutUpdate)) | ||
| if err != nil { | ||
| if httperrors.Is404(err) { | ||
| d.SetId("") | ||
| return nil | ||
| } | ||
| return diag.FromErr(err) | ||
| } | ||
| req := &inference.UpdateDeploymentRequest{ | ||
| Region: region, | ||
| DeploymentID: deployment.ID, | ||
| } | ||
|
|
||
| if d.HasChange("name") { | ||
| req.Name = types.ExpandUpdatedStringPtr(d.Get("name")) | ||
| } | ||
Codelax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if _, err := api.UpdateDeployment(req, scw.WithContext(ctx)); err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return ResourceDeploymentRead(ctx, d, m) | ||
| } | ||
|
|
||
| func ResourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
| api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| _, err = waitForDeployment(ctx, api, region, id, d.Timeout(schema.TimeoutDelete)) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| _, err = api.DeleteDeployment(&inference.DeleteDeploymentRequest{ | ||
| Region: region, | ||
| DeploymentID: id, | ||
| }, scw.WithContext(ctx)) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| _, err = waitForDeployment(ctx, api, region, id, d.Timeout(schema.TimeoutDelete)) | ||
| if err != nil && !httperrors.Is404(err) { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
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.