Skip to content

Commit

Permalink
feat(res-def): allow update of driver_type
Browse files Browse the repository at this point in the history
  • Loading branch information
delca85 committed Jun 3, 2024
1 parent 166071a commit 34418bd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.22.2
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/humanitec/humanitec-go-autogen v0.0.0-20240523102513-6cf639116144
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603082519-115161f20ad9
github.com/stretchr/testify v1.9.0
sigs.k8s.io/yaml v1.4.0
)
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ 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-20240523102513-6cf639116144 h1:h1HURx3DvUaYFxGEFF+iK4eQ4mvKFJtRVnDBHeEZNBM=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240523102513-6cf639116144/go.mod h1:WqItJ/MhAHcjP7LIhIt2/NrgXeXRbLuxvXlin7qY0j4=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603070908-7238c5b8e347 h1:n9z9/D70zwIlCD8ZBbmgEoWzVPdzwsqRy28GyehcGPw=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603070908-7238c5b8e347/go.mod h1:WqItJ/MhAHcjP7LIhIt2/NrgXeXRbLuxvXlin7qY0j4=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603075120-ae3761a21090 h1:0XuXgyY2qAYNNYk57PnpPI6UUAnF6WRSZ0+L6cEOByI=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603075120-ae3761a21090/go.mod h1:WqItJ/MhAHcjP7LIhIt2/NrgXeXRbLuxvXlin7qY0j4=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603082519-115161f20ad9 h1:5U+pJQYYGHUaLEt7knTLnSADEXUcIe2tB1TXIssMJIY=
github.com/humanitec/humanitec-go-autogen v0.0.0-20240603082519-115161f20ad9/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=
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_definition_criteria_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (r *ResourceDefinitionCriteriaResource) Read(ctx context.Context, req resou
return
}

httpResp, err := r.client().GetResourceDefinitionWithResponse(ctx, r.orgId(), data.ResourceDefinitionID.ValueString())
httpResp, err := r.client().GetResourceDefinitionWithResponse(ctx, r.orgId(), data.ResourceDefinitionID.ValueString(), &client.GetResourceDefinitionParams{toPtr(false)})
if err != nil {
resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to read resource definition, got error: %s", err))
return
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/resource_definition_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (r *ResourceDefinitionResource) Read(ctx context.Context, req resource.Read
return
}

httpResp, err := r.client().GetResourceDefinitionWithResponse(ctx, r.orgId(), data.ID.ValueString())
httpResp, err := r.client().GetResourceDefinitionWithResponse(ctx, r.orgId(), data.ID.ValueString(), &client.GetResourceDefinitionParams{Deleted: toPtr(false)})
if err != nil {
resp.Diagnostics.AddError(HUM_CLIENT_ERR, fmt.Sprintf("Unable to read resource definition, got error: %s", err))
return
Expand Down Expand Up @@ -459,6 +459,7 @@ func (r *ResourceDefinitionResource) Update(ctx context.Context, req resource.Up
provision := provisionFromModel(data.Provision)

httpResp, err := r.client().UpdateResourceDefinitionWithResponse(ctx, r.orgId(), defID, client.UpdateResourceDefinitionRequestRequest{
DriverType: data.DriverType.ValueStringPointer(),
DriverAccount: data.DriverAccount.ValueStringPointer(),
DriverInputs: driverInputs,
Name: name,
Expand Down
32 changes: 32 additions & 0 deletions internal/provider/resource_definition_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ func TestAccResourceDefinition(t *testing.T) {
resourceAttrNameUpdateValue2 string
importStateVerifyIgnore []string
}{
{
name: "S3 - update driver_type",
configCreate: func() string {
return testAccResourceDefinitionS3Resource(fmt.Sprintf("s3-test-%d", timestamp), "us-east-1")
},
resourceAttrNameIDValue: fmt.Sprintf("s3-test-%d", timestamp),
resourceAttrNameUpdateKey: "driver_type",
resourceAttrNameUpdateValue1: "humanitec/s3",
resourceAttrName: "humanitec_resource_definition.s3_test",
configUpdate: func() string {
return testAccResourceDefinitionS3ResourceWithDifferentDriver(fmt.Sprintf("s3-test-%d", timestamp), "us-east-1", "humanitec/terraform")
},
resourceAttrNameUpdateValue2: "humanitec/terraform",
importStateVerifyIgnore: []string{"driver_inputs.secrets_string", "force_delete"},
},
{
name: "S3",
configCreate: func() string {
Expand Down Expand Up @@ -280,6 +295,23 @@ resource "humanitec_resource_definition" "s3_test" {
`, id, region)
}

func testAccResourceDefinitionS3ResourceWithDifferentDriver(id, region, driver_type string) string {
return fmt.Sprintf(`
resource "humanitec_resource_definition" "s3_test" {
id = "%s"
name = "s3-test"
type = "s3"
driver_type = "%s"
driver_inputs = {
values_string = jsonencode({
"region" = "%s"
})
}
}
`, id, driver_type, region)
}

func testAccResourceDefinitionPostgresResource(id, name string) string {
return fmt.Sprintf(`
resource "humanitec_resource_definition" "postgres_test" {
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ func readConfig(data HumanitecProviderModel) (config Config, diags diag.Diagnost
}
return
}

func toPtr[T any](value T) *T {
return &value
}

0 comments on commit 34418bd

Please sign in to comment.