Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions examples/network/main.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.50.0"
}

dfcloud = {
source = "registry.terraform.io/dragonflydb/dfcloud"
}
}
}

provider "aws" {
# Configuration options
}

provider "dfcloud" {
# Configuration options
}

data "aws_caller_identity" "current" {}

# client VPC
resource "aws_vpc" "client" {
cidr_block = "10.0.0.0/16"

tags = {
Name = "client"
}
}

# private network
resource "dfcloud_network" "network" {
Expand All @@ -40,23 +21,20 @@ resource "dfcloud_network" "network" {
cidr_block = "192.168.0.0/16"
}

# private connection
resource "dfcloud_connection" "connection" {
depends_on = [aws_vpc.client, dfcloud_network.network]
resource "dfcloud_datastore" "datastore" {
name = "tf-test-no-pass"

name = "connection"
peer = {
account_id = data.aws_caller_identity.current.account_id
region = "us-east-1"
vpc_id = aws_vpc.client.id
tier = {
max_memory_bytes = 3000000000
performance_tier = "dev"
replicas = 1
}

network_id = dfcloud_network.network.id
}

resource "aws_vpc_peering_connection_accepter" "accepter" {
depends_on = [dfcloud_connection.connection]
location = {
region = "us-east-1"
provider = "aws"
}

vpc_peering_connection_id = dfcloud_connection.connection.peer_connection_id
auto_accept = true
disable_pass_key = true
network_id = dfcloud_network.network.id
}
18 changes: 15 additions & 3 deletions internal/provider/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"fmt"
"time"

dfcloud "github.com/dragonflydb/terraform-provider-dfcloud/internal/sdk"
"github.com/dragonflydb/terraform-provider-dfcloud/internal/resource_model"
dfcloud "github.com/dragonflydb/terraform-provider-dfcloud/internal/sdk"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -41,8 +43,18 @@ func (r *datastoreResource) Schema(_ context.Context, _ resource.SchemaRequest,
MarkdownDescription: "The timestamp when the datastore was created.",
Computed: true,
},
"disable_pass_key": schema.BoolAttribute{
MarkdownDescription: "Disable the passkey for the datastore.",
Optional: true,
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.RequiresReplace(),
},
},
// password cant be set by a user
"password": schema.StringAttribute{
MarkdownDescription: "The password for the datastore.",
Optional: false,
Required: false,
Computed: true,
Sensitive: true,
},
Expand Down Expand Up @@ -251,8 +263,8 @@ func (r *datastoreResource) Update(ctx context.Context, req resource.UpdateReque
return
}

datastore := resource_model.IntoDatastoreConfig(plan)
respDatastore, err = r.client.UpdateDatastore(ctx, state.ID.ValueString(), &datastore.Config)
updateDatastore := resource_model.IntoDatastoreConfig(plan)
respDatastore, err = r.client.UpdateDatastore(ctx, state.ID.ValueString(), &updateDatastore.Config)
if err != nil {
resp.Diagnostics.AddError("Error Updating Datastore", err.Error())
return
Expand Down
23 changes: 14 additions & 9 deletions internal/resource_model/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (

// Datastore maps the resource schema data.
type Datastore struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
NetworkId types.String `tfsdk:"network_id"`
Location DatastoreLocation `tfsdk:"location"`
Tier DatastoreTier `tfsdk:"tier"`
Dragonfly types.Object `tfsdk:"dragonfly"`
CreatedAt types.Int64 `tfsdk:"created_at"`
Password types.String `tfsdk:"password"`
Addr types.String `tfsdk:"addr"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
NetworkId types.String `tfsdk:"network_id"`
Location DatastoreLocation `tfsdk:"location"`
Tier DatastoreTier `tfsdk:"tier"`
Dragonfly types.Object `tfsdk:"dragonfly"`
CreatedAt types.Int64 `tfsdk:"created_at"`
Password types.String `tfsdk:"password"`
Addr types.String `tfsdk:"addr"`
DisablePassKey types.Bool `tfsdk:"disable_pass_key"`
}

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

if in.DisablePassKey.ValueBool() {
datastore.Config.DisablePasskey = in.DisablePassKey.ValueBool()
}

if in.Dragonfly.IsNull() {
in.Dragonfly = types.ObjectValueMust(map[string]attr.Type{
"cache_mode": types.BoolType,
Expand Down
3 changes: 3 additions & 0 deletions internal/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (c *Client) GetDatastore(ctx context.Context, id string) (*Datastore, error
if err := json.NewDecoder(r).Decode(&datastore); err != nil {
return nil, fmt.Errorf("decode response: %w", err)
}

return datastore, nil
}

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

return &datastore, nil
}

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

return &datastore, nil
}

Expand Down
1 change: 0 additions & 1 deletion internal/sdk/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const (
CloudProviderAzure CloudProvider = "azure"
)


// DatastoreLocation represents where the datastore should be provisioned.
type DatastoreLocation struct {
Provider CloudProvider `json:"provider"`
Expand Down