Skip to content

Commit

Permalink
added default local port option for AWS_RDS users (#144)
Browse files Browse the repository at this point in the history
* added default local port option for AWS_RDS users

* Generate documentation

* removed accidental commit of git hash in update-sdk.sh

---------

Co-authored-by: VigneshSelvaraj96 <[email protected]>
  • Loading branch information
VigneshSelvaraj96 and VigneshSelvaraj96 authored Nov 4, 2024
1 parent c5784f4 commit d25996a
Show file tree
Hide file tree
Showing 7 changed files with 1,279 additions and 981 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-balloons-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@common-fate/terraform-provider-commonfate": minor
---

added default_local_port option for AWS_RDS Users
1 change: 1 addition & 0 deletions docs/resources/proxy_rds_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Required:

Optional:

- `default_local_port` (Number) The default local port to use for the user when running `granted rds proxy`
- `endpoint` (String) Override default endpoint behaviour by specifying a endpoint on a per user basis.


2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.4
require (
connectrpc.com/connect v1.14.0
github.com/common-fate/grab v1.1.0
github.com/common-fate/sdk v1.67.0
github.com/common-fate/sdk v1.68.0
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-log v0.9.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ github.com/common-fate/clio v1.2.3 h1:hHwUYZjn66qGYDpgANl0EB/92hyi/Jsnd07qB09rvn
github.com/common-fate/clio v1.2.3/go.mod h1:NkozaS15SA+6Y9zb+82eIj1i41aWShorTqA01GKQ7A8=
github.com/common-fate/grab v1.1.0 h1:HLZPtltdHScYu6qtt/UC78rvwylCTWuyoZoiQXV4QHc=
github.com/common-fate/grab v1.1.0/go.mod h1:L0qa03RwqOMZz9PrrWw9eI145i5FQRf+iLtNSJypQvY=
github.com/common-fate/sdk v1.65.2 h1:vBwqcC7t+jZmXz2XN+MqCh07/DakFhqmGrktzuwlcGk=
github.com/common-fate/sdk v1.65.2/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.66.1-0.20241023023921-3a7d752bd08a h1:cWFbvXGQDNbRFyj7UDEbTydfV3LGSfGH/NAwqo5e/lQ=
github.com/common-fate/sdk v1.66.1-0.20241023023921-3a7d752bd08a/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.67.0 h1:e7+NATjCQqC/wWkGSvRn9H69WHlU/sfgqDK0q10FlS0=
github.com/common-fate/sdk v1.67.0/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.68.0 h1:Dh4C7oDlmiHRmeDI4TkVkQtM/eAoFqJERo2nKGG/OdA=
github.com/common-fate/sdk v1.68.0/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
Expand Down
31 changes: 29 additions & 2 deletions internal/proxy/resource_rds_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -40,6 +41,7 @@ type DatabaseUser struct {
UserName types.String `tfsdk:"username"`
PasswordSecretsManagerARN types.String `tfsdk:"password_secrets_manager_arn"`
Endpoint types.String `tfsdk:"endpoint"`
DefaultLocalPort types.Int64 `tfsdk:"default_local_port"`
}

// AccessRuleResource is the data source implementation.
Expand Down Expand Up @@ -148,6 +150,12 @@ func (r *RDSDatabaseResource) Schema(ctx context.Context, req resource.SchemaReq
MarkdownDescription: "Override default endpoint behaviour by specifying a endpoint on a per user basis.",
Optional: true,
},
"default_local_port": schema.Int64Attribute{
MarkdownDescription: "The default local port to use for the user when running `granted rds proxy`",
Optional: true,
Default: int64default.StaticInt64(0),
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -195,6 +203,7 @@ func (r *RDSDatabaseResource) Create(ctx context.Context, req resource.CreateReq
Name: user.Name.ValueString(),
Username: user.UserName.ValueString(),
PasswordSecretsManagerArn: user.PasswordSecretsManagerARN.ValueString(),
DefaultLocalPort: uint32(user.DefaultLocalPort.ValueInt64()),
}

if user.Endpoint.ValueString() != "" {
Expand Down Expand Up @@ -262,8 +271,25 @@ func (r *RDSDatabaseResource) Read(ctx context.Context, req resource.ReadRequest
}

// refresh state

state.ID = types.StringValue(res.Msg.Id)
state = RDSDatabaseModel{
ID: types.StringValue(res.Msg.Id),
InstanceID: types.StringValue(res.Msg.RdsDatabase.InstanceId),
Name: types.StringValue(res.Msg.RdsDatabase.Name),
Engine: types.StringValue(res.Msg.RdsDatabase.Engine),
Endpoint: types.StringValue(res.Msg.RdsDatabase.Endpoint),
Region: types.StringValue(res.Msg.RdsDatabase.Region),
AWSAccountID: types.StringValue(res.Msg.RdsDatabase.Account),
Database: types.StringValue(res.Msg.RdsDatabase.Database),
ProxyId: types.StringValue(res.Msg.ProxyId),
}
for _, user := range res.Msg.RdsDatabase.Users {
state.Users = append(state.Users, DatabaseUser{
Name: types.StringValue(user.Name),
UserName: types.StringValue(user.Username),
PasswordSecretsManagerARN: types.StringValue(user.PasswordSecretsManagerArn),
DefaultLocalPort: types.Int64Value(int64(user.DefaultLocalPort)),
})
}

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Expand Down Expand Up @@ -308,6 +334,7 @@ func (r *RDSDatabaseResource) Update(ctx context.Context, req resource.UpdateReq
Name: user.Name.ValueString(),
Username: user.UserName.ValueString(),
PasswordSecretsManagerArn: user.PasswordSecretsManagerARN.ValueString(),
DefaultLocalPort: uint32(user.DefaultLocalPort.ValueInt64()),
}

if user.Endpoint.ValueString() != "" {
Expand Down
Loading

0 comments on commit d25996a

Please sign in to comment.