diff --git a/go.mod b/go.mod index fd26121..03daf49 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/terraform-plugin-go v0.21.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.32.0 - github.com/humanitec/humanitec-go-autogen v0.0.0-20240313140210-52935f0baed6 + github.com/humanitec/humanitec-go-autogen v0.0.0-20240409130502-cfb171fe9dc4 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 0f3e1aa..94aad54 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,8 @@ github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbg github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/humanitec/humanitec-go-autogen v0.0.0-20240313140210-52935f0baed6 h1:vvzktUEv99nnWHzzqb6moBiNJaC9I61CUf44l9AofwQ= -github.com/humanitec/humanitec-go-autogen v0.0.0-20240313140210-52935f0baed6/go.mod h1:WqItJ/MhAHcjP7LIhIt2/NrgXeXRbLuxvXlin7qY0j4= +github.com/humanitec/humanitec-go-autogen v0.0.0-20240409130502-cfb171fe9dc4 h1:5Axj0K5JH9YGaKohz8GqL+BcLLBwV5nn16l42p8PnMM= +github.com/humanitec/humanitec-go-autogen v0.0.0-20240409130502-cfb171fe9dc4/go.mod h1:WqItJ/MhAHcjP7LIhIt2/NrgXeXRbLuxvXlin7qY0j4= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= diff --git a/internal/provider/resource_environment_type.go b/internal/provider/resource_environment_type.go index f7febe1..b7a28b4 100644 --- a/internal/provider/resource_environment_type.go +++ b/internal/provider/resource_environment_type.go @@ -148,7 +148,34 @@ func (r *ResourceEnvironmentType) Read(ctx context.Context, req resource.ReadReq } func (r *ResourceEnvironmentType) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - resp.Diagnostics.AddError("UNSUPPORTED_OPERATION", "Updating an environment type is currently not supported") + var data *EnvironmentTypeModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + id := data.ID.ValueString() + + httpResp, err := r.client.UpdateEnvironmentTypeWithResponse(ctx, r.orgId, id, client.UpdateEnvironmentTypeJSONRequestBody{ + Description: data.Description.ValueStringPointer(), + }) + if err != nil { + resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to update environment type, got error: %s", err)) + return + } + + if httpResp.StatusCode() != 200 { + resp.Diagnostics.AddError(HUM_API_ERR, fmt.Sprintf("Unable to update environment type, unexpected status code: %d, body: %s", httpResp.StatusCode(), httpResp.Body)) + return + } + + parseEnvironmentTypeResponse(httpResp.JSON200, data) + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } func (r *ResourceEnvironmentType) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {