Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove FF for api keys and create docs #149

Merged
merged 1 commit into from
Jan 27, 2025
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
27 changes: 26 additions & 1 deletion docs/resources/api_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ resource "ybm_api_key" "example_custom_role_api_key" {
}
```

To issue an API key with allow lists associated for IP based restrictions on the key

```terraform
resource "ybm_allow_list" "external_network_range" {
allow_list_name = "external-range"
allow_list_description = "allow a range of external IP addresses"
cidr_list = ["192.168.1.0/24"]
}
resource "ybm_allow_list" "external_single_ip" {
allow_list_name = "external-single"
allow_list_description = "allow a single external IP address"
cidr_list = ["203.0.113.1/32"]
}

resource "ybm_api_key" "developer_api_key" {
name = "developer-key"
description = "IP restricted API key for developer access"
duration = 1
unit = "Hours"
role_name = "Developer"
allow_list_ids = [ybm_allow_list.external_network_range.allow_list_id, ybm_allow_list.external_single_ip.allow_list_id]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

Expand All @@ -47,6 +71,7 @@ resource "ybm_api_key" "example_custom_role_api_key" {

### Optional

- `allow_list_ids` (Set of String) List of IDs of the allow lists assigned to the API Key.
- `api_key_id` (String) The ID of the API Key. Created automatically when an API Key is created. Use this ID to get a specific API Key.
- `description` (String) The description of the API Key.

Expand All @@ -59,4 +84,4 @@ resource "ybm_api_key" "example_custom_role_api_key" {
- `issuer` (String) The issuer of the API Key.
- `last_used` (String) The last used time of the API Key.
- `project_id` (String) The ID of the project this user belongs to.
- `status` (String) The status of the API Key.
- `status` (String) The status of the API Key.
19 changes: 19 additions & 0 deletions examples/resources/ybm_api_key/allow-list-api-key.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "ybm_allow_list" "external_network_range" {
allow_list_name = "external-range"
allow_list_description = "allow a range of external IP addresses"
cidr_list = ["192.168.1.0/24"]
}
resource "ybm_allow_list" "external_single_ip" {
allow_list_name = "external-single"
allow_list_description = "allow a single external IP address"
cidr_list = ["203.0.113.1/32"]
}

resource "ybm_api_key" "developer_api_key" {
name = "developer-key"
description = "IP restricted API key for developer access"
duration = 1
unit = "Hours"
role_name = "Developer"
allow_list_ids = [ybm_allow_list.external_network_range.allow_list_id, ybm_allow_list.external_single_ip.allow_list_id]
}
10 changes: 4 additions & 6 deletions managed/fflags/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (
type FeatureFlag string

const (
CONNECTION_POOLING FeatureFlag = "CONNECTION_POOLING"
DR FeatureFlag = "DR"
API_KEYS_ALLOW_LIST FeatureFlag = "API_KEYS_ALLOW_LIST"
CONNECTION_POOLING FeatureFlag = "CONNECTION_POOLING"
DR FeatureFlag = "DR"
)

var flagEnabled = map[FeatureFlag]bool{
CONNECTION_POOLING: false,
DR: false,
API_KEYS_ALLOW_LIST: false,
CONNECTION_POOLING: false,
DR: false,
}

func (f FeatureFlag) String() string {
Expand Down
23 changes: 9 additions & 14 deletions managed/resource_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/yugabyte/terraform-provider-ybm/managed/fflags"
openapiclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
)

type resourceApiKeyType struct{}

func (r resourceApiKeyType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
schema := tfsdk.Schema{
return tfsdk.Schema{
Description: `The resource to issue an API Key in YugabyteDB Aeon.`,
Attributes: map[string]tfsdk.Attribute{
"account_id": {
Expand Down Expand Up @@ -58,6 +57,13 @@ func (r resourceApiKeyType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
Type: types.StringType,
Required: true,
},
"allow_list_ids": {
Description: "List of IDs of the allow lists assigned to the API Key.",
Type: types.SetType{
ElemType: types.StringType,
},
Optional: true,
},
"description": {
Description: "The description of the API Key.",
Type: types.StringType,
Expand Down Expand Up @@ -96,18 +102,7 @@ func (r resourceApiKeyType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
Computed: true,
},
},
}
// Add allow lists if the feature flag is enabled
if fflags.IsFeatureFlagEnabled(fflags.API_KEYS_ALLOW_LIST) {
schema.Attributes["allow_list_ids"] = tfsdk.Attribute{
Description: "List of IDs of the allow lists assigned to the API Key.",
Type: types.SetType{
ElemType: types.StringType,
},
Optional: true,
}
}
return schema, nil
}, nil
}

func (r resourceApiKeyType) NewResource(_ context.Context, p tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) {
Expand Down
6 changes: 5 additions & 1 deletion templates/resources/api_key.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ To issue an API Key with custom user defined roles

{{ tffile "examples/resources/ybm_api_key/custom-role-api-key.tf" }}

{{ .SchemaMarkdown | trimspace }}
To issue an API key with allow lists associated for IP based restrictions on the key

{{ tffile "examples/resources/ybm_api_key/allow-list-api-key.tf" }}

{{ .SchemaMarkdown | trimspace }}
Loading