Skip to content

Commit 228adb3

Browse files
committed
Add storage_profile resource
1 parent 8c65bd7 commit 228adb3

File tree

10 files changed

+450
-11
lines changed

10 files changed

+450
-11
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "dbsnapper_storage_profile" "tf_sp_example" {
2+
name = "tf_sp_example"
3+
sp_provider = "s3" # s3, r2
4+
5+
region = "us-east-1"
6+
account_id = "" # for cloudflare
7+
8+
access_key = "AKIAxxxxxxxxxxxx"
9+
secret_key = "xxxxxxxxxxxxxxxxxxxx"
10+
11+
bucket = "dbsnapper-test-s3"
12+
prefix = "terraform"
13+
}
14+
15+
output "sp_id" {
16+
value = dbsnapper_storage_profile.tf_sp_example.id
17+
}
18+
output "sp_status" {
19+
value = dbsnapper_storage_profile.tf_sp_example.status
20+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ require (
181181
gopkg.in/yaml.v3 v3.0.1 // indirect
182182
)
183183

184-
// replace github.com/joescharf/dbsnapper/v2 v2.7.1 => /Users/joescharf/app/dbsnapper/agent
184+
replace github.com/joescharf/dbsnapper/v2 v2.7.2 => /Users/joescharf/app/dbsnapper/agent

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
22
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
33
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
44
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
5-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM=
6-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo=
5+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA=
77
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
88
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo=
99
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
@@ -261,8 +261,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
261261
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
262262
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
263263
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
264-
github.com/joescharf/dbsnapper/v2 v2.7.2 h1:UY04FpAjZ71nvsiyiIj8pZtus478O/RbDk3hWPJgAGU=
265-
github.com/joescharf/dbsnapper/v2 v2.7.2/go.mod h1:3BkEHh0p9LxCTnxqow7ubCvr6YDh+sIQc++OktBZsAc=
266264
github.com/joescharf/go-datapipe v0.0.2 h1:KPIE5d9Z0h0rwQdqHpIy6J4zqhnPfff02X4yaQo/Jwg=
267265
github.com/joescharf/go-datapipe v0.0.2/go.mod h1:NUzn7qmljZ34PqXferGM0NegowHomIg4XBEYJ5DP7TM=
268266
github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM=

internal/provider/dbsnapper_client.go renamed to internal/client/dbsnapper_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package provider
1+
package client
22

33
import (
44
"github.com/joescharf/dbsnapper/v2/apiv1"

internal/provider/provider.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package provider
66
import (
77
"context"
88
"os"
9+
"terraform-provider-dbsnapper/internal/client"
910

1011
"github.com/hashicorp/terraform-plugin-framework/datasource"
1112
"github.com/hashicorp/terraform-plugin-framework/function"
@@ -104,7 +105,7 @@ func (p *dbSnapperProvider) Configure(ctx context.Context, req provider.Configur
104105
}
105106

106107
// Create client with configuration values
107-
dbs := NewDBSnapper(authtoken, baseURL)
108+
dbs := client.NewDBSnapper(authtoken, baseURL)
108109
if !dbs.IsReady {
109110
resp.Diagnostics.AddError("Failed to create DBSnapper API client", "API Not Ready")
110111
return
@@ -115,9 +116,14 @@ func (p *dbSnapperProvider) Configure(ctx context.Context, req provider.Configur
115116

116117
}
117118

119+
type Resourcer interface {
120+
GetResource() *resource.Resource
121+
}
122+
118123
func (p *dbSnapperProvider) Resources(ctx context.Context) []func() resource.Resource {
119124
return []func() resource.Resource{
120125
NewTargetResource,
126+
NewStorageProviderResource,
121127
}
122128
}
123129

internal/provider/sp_common.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/google/uuid"
7+
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/hashicorp/terraform-plugin-log/tflog"
9+
"github.com/joescharf/dbsnapper/v2/storage"
10+
)
11+
12+
func TFToSPResourceModel(ctx context.Context, tf *StorageProfileResourceModel) (*StorageProfileResourceModel, error) {
13+
14+
// There are no sub-structs to initialize, so we can return the input
15+
16+
return tf, nil
17+
}
18+
19+
func SPResourceModelToAPIRequest(ctx context.Context, resourceModel *StorageProfileResourceModel) (*storage.StorageProfile, error) {
20+
spRequest := new(storage.StorageProfile)
21+
22+
uid, _ := uuid.Parse(resourceModel.ID.ValueString())
23+
spRequest.ID = uid
24+
spRequest.Provider = resourceModel.Provider.ValueString()
25+
spRequest.Name = resourceModel.Name.ValueString()
26+
spRequest.Region = resourceModel.Region.ValueString()
27+
spRequest.AccountID = resourceModel.AccountID.ValueString()
28+
spRequest.AccessKey = resourceModel.AccessKey.ValueString()
29+
spRequest.SecretKey = resourceModel.SecretKey.ValueString()
30+
spRequest.Bucket = resourceModel.Bucket.ValueString()
31+
spRequest.Prefix = resourceModel.Prefix.ValueString()
32+
spRequest.Status = resourceModel.Status.ValueString()
33+
34+
ctx = tflog.SetField(ctx, "ID", spRequest.ID.String())
35+
tflog.Debug(ctx, "PlanToApiRequest - storageProfileResource")
36+
37+
return spRequest, nil
38+
}
39+
40+
func APIResponseToSPResourceModel(ctx context.Context, spApiResponse *storage.StorageProfile, resourceModel *StorageProfileResourceModel) (*StorageProfileResourceModel, error) {
41+
resourceModel.ID = types.StringValue(spApiResponse.ID.String())
42+
resourceModel.Name = types.StringValue(spApiResponse.Name)
43+
resourceModel.Provider = types.StringValue(spApiResponse.Provider)
44+
resourceModel.Region = types.StringValue(spApiResponse.Region)
45+
resourceModel.AccountID = types.StringValue(spApiResponse.AccountID)
46+
resourceModel.AccessKey = types.StringValue(spApiResponse.AccessKey)
47+
resourceModel.SecretKey = types.StringValue(spApiResponse.SecretKey)
48+
resourceModel.Bucket = types.StringValue(spApiResponse.Bucket)
49+
resourceModel.Prefix = types.StringValue(spApiResponse.Prefix)
50+
resourceModel.Status = types.StringValue(spApiResponse.Status)
51+
resourceModel.CreatedAt = types.StringValue(spApiResponse.CreatedAt)
52+
resourceModel.UpdatedAt = types.StringValue(spApiResponse.UpdatedAt)
53+
54+
return resourceModel, nil
55+
}

0 commit comments

Comments
 (0)