Skip to content

Commit ca191e2

Browse files
authored
feat(datastore): Support disabling pass key (#13)
* feat(datastore): Support disabling pass key * fix bool nill value * use consistent naming * fix more things * simplify by inferring * add redeploy for disable key * stop inferring * always require a replace
1 parent fb18bdb commit ca191e2

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

examples/network/main.tf

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
terraform {
22
required_providers {
3-
aws = {
4-
source = "hashicorp/aws"
5-
version = "5.50.0"
6-
}
7-
83
dfcloud = {
94
source = "registry.terraform.io/dragonflydb/dfcloud"
105
}
116
}
127
}
138

14-
provider "aws" {
15-
# Configuration options
16-
}
17-
189
provider "dfcloud" {
1910
# Configuration options
2011
}
2112

22-
data "aws_caller_identity" "current" {}
23-
24-
# client VPC
25-
resource "aws_vpc" "client" {
26-
cidr_block = "10.0.0.0/16"
27-
28-
tags = {
29-
Name = "client"
30-
}
31-
}
3213

3314
# private network
3415
resource "dfcloud_network" "network" {
@@ -40,23 +21,20 @@ resource "dfcloud_network" "network" {
4021
cidr_block = "192.168.0.0/16"
4122
}
4223

43-
# private connection
44-
resource "dfcloud_connection" "connection" {
45-
depends_on = [aws_vpc.client, dfcloud_network.network]
24+
resource "dfcloud_datastore" "datastore" {
25+
name = "tf-test-no-pass"
4626

47-
name = "connection"
48-
peer = {
49-
account_id = data.aws_caller_identity.current.account_id
50-
region = "us-east-1"
51-
vpc_id = aws_vpc.client.id
27+
tier = {
28+
max_memory_bytes = 3000000000
29+
performance_tier = "dev"
30+
replicas = 1
5231
}
5332

54-
network_id = dfcloud_network.network.id
55-
}
56-
57-
resource "aws_vpc_peering_connection_accepter" "accepter" {
58-
depends_on = [dfcloud_connection.connection]
33+
location = {
34+
region = "us-east-1"
35+
provider = "aws"
36+
}
5937

60-
vpc_peering_connection_id = dfcloud_connection.connection.peer_connection_id
61-
auto_accept = true
38+
disable_pass_key = true
39+
network_id = dfcloud_network.network.id
6240
}

internal/provider/datastore.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"fmt"
66
"time"
77

8-
dfcloud "github.com/dragonflydb/terraform-provider-dfcloud/internal/sdk"
98
"github.com/dragonflydb/terraform-provider-dfcloud/internal/resource_model"
9+
dfcloud "github.com/dragonflydb/terraform-provider-dfcloud/internal/sdk"
1010
"github.com/hashicorp/terraform-plugin-framework/resource"
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
13+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1214
"github.com/hashicorp/terraform-plugin-framework/types"
1315
"github.com/hashicorp/terraform-plugin-log/tflog"
1416
)
@@ -41,8 +43,18 @@ func (r *datastoreResource) Schema(_ context.Context, _ resource.SchemaRequest,
4143
MarkdownDescription: "The timestamp when the datastore was created.",
4244
Computed: true,
4345
},
46+
"disable_pass_key": schema.BoolAttribute{
47+
MarkdownDescription: "Disable the passkey for the datastore.",
48+
Optional: true,
49+
PlanModifiers: []planmodifier.Bool{
50+
boolplanmodifier.RequiresReplace(),
51+
},
52+
},
53+
// password cant be set by a user
4454
"password": schema.StringAttribute{
4555
MarkdownDescription: "The password for the datastore.",
56+
Optional: false,
57+
Required: false,
4658
Computed: true,
4759
Sensitive: true,
4860
},
@@ -251,8 +263,8 @@ func (r *datastoreResource) Update(ctx context.Context, req resource.UpdateReque
251263
return
252264
}
253265

254-
datastore := resource_model.IntoDatastoreConfig(plan)
255-
respDatastore, err = r.client.UpdateDatastore(ctx, state.ID.ValueString(), &datastore.Config)
266+
updateDatastore := resource_model.IntoDatastoreConfig(plan)
267+
respDatastore, err = r.client.UpdateDatastore(ctx, state.ID.ValueString(), &updateDatastore.Config)
256268
if err != nil {
257269
resp.Diagnostics.AddError("Error Updating Datastore", err.Error())
258270
return

internal/resource_model/datastore.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212

1313
// Datastore maps the resource schema data.
1414
type Datastore struct {
15-
ID types.String `tfsdk:"id"`
16-
Name types.String `tfsdk:"name"`
17-
NetworkId types.String `tfsdk:"network_id"`
18-
Location DatastoreLocation `tfsdk:"location"`
19-
Tier DatastoreTier `tfsdk:"tier"`
20-
Dragonfly types.Object `tfsdk:"dragonfly"`
21-
CreatedAt types.Int64 `tfsdk:"created_at"`
22-
Password types.String `tfsdk:"password"`
23-
Addr types.String `tfsdk:"addr"`
15+
ID types.String `tfsdk:"id"`
16+
Name types.String `tfsdk:"name"`
17+
NetworkId types.String `tfsdk:"network_id"`
18+
Location DatastoreLocation `tfsdk:"location"`
19+
Tier DatastoreTier `tfsdk:"tier"`
20+
Dragonfly types.Object `tfsdk:"dragonfly"`
21+
CreatedAt types.Int64 `tfsdk:"created_at"`
22+
Password types.String `tfsdk:"password"`
23+
Addr types.String `tfsdk:"addr"`
24+
DisablePassKey types.Bool `tfsdk:"disable_pass_key"`
2425
}
2526

2627
type DatastoreLocation struct {
@@ -99,6 +100,10 @@ func IntoDatastoreConfig(in Datastore) *dfcloud.Datastore {
99100
datastore.Config.NetworkID = in.NetworkId.ValueString()
100101
}
101102

103+
if in.DisablePassKey.ValueBool() {
104+
datastore.Config.DisablePasskey = in.DisablePassKey.ValueBool()
105+
}
106+
102107
if in.Dragonfly.IsNull() {
103108
in.Dragonfly = types.ObjectValueMust(map[string]attr.Type{
104109
"cache_mode": types.BoolType,

internal/sdk/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (c *Client) GetDatastore(ctx context.Context, id string) (*Datastore, error
117117
if err := json.NewDecoder(r).Decode(&datastore); err != nil {
118118
return nil, fmt.Errorf("decode response: %w", err)
119119
}
120+
120121
return datastore, nil
121122
}
122123

@@ -133,6 +134,7 @@ func (c *Client) CreateDatastore(ctx context.Context, config *DatastoreConfig) (
133134
if err := json.NewDecoder(r).Decode(&datastore); err != nil {
134135
return nil, fmt.Errorf("decode response: %w", err)
135136
}
137+
136138
return &datastore, nil
137139
}
138140

@@ -149,6 +151,7 @@ func (c *Client) UpdateDatastore(ctx context.Context, id string, config *Datasto
149151
if err := json.NewDecoder(r).Decode(&datastore); err != nil {
150152
return nil, fmt.Errorf("decode response: %w", err)
151153
}
154+
152155
return &datastore, nil
153156
}
154157

internal/sdk/datastore.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const (
88
CloudProviderAzure CloudProvider = "azure"
99
)
1010

11-
1211
// DatastoreLocation represents where the datastore should be provisioned.
1312
type DatastoreLocation struct {
1413
Provider CloudProvider `json:"provider"`

0 commit comments

Comments
 (0)