Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/acceptance_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
- run: go mod download
- env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_MGMT_API_KEY: ${{ secrets.PINECONE_MGMT_API_KEY }}
TF_ACC: "1"
run: go test -race -covermode=atomic -coverprofile=coverage.out -v ./pinecone/provider/
timeout-minutes: 10
24 changes: 24 additions & 0 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_project Data Source - terraform-provider-pinecone"
subcategory: ""
description: |-
Project data source
---

# pinecone_project (Data Source)

Project data source



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

### Required

- `name` (String) Project Name

### Read-Only

- `id` (String) Project identifier
25 changes: 25 additions & 0 deletions docs/data-sources/project_api_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_project_api_key Data Source - terraform-provider-pinecone"
subcategory: ""
description: |-
Project ApiKey data source
---

# pinecone_project_api_key (Data Source)

Project ApiKey data source



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

### Required

- `name` (String) ApiKey Name
- `project_id` (String) Project identifier

### Read-Only

- `id` (String) ApiKey identifier
34 changes: 34 additions & 0 deletions docs/data-sources/project_api_keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_project_api_keys Data Source - terraform-provider-pinecone"
subcategory: ""
description: |-
Project ApiKeys data source
---

# pinecone_project_api_keys (Data Source)

Project ApiKeys data source



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

### Required

- `project_id` (String) Project identifier

### Read-Only

- `api_keys` (Attributes List) List of the api keys in your project (see [below for nested schema](#nestedatt--api_keys))
- `id` (String) ApiKeys identifier

<a id="nestedatt--api_keys"></a>
### Nested Schema for `api_keys`

Read-Only:

- `id` (String) Project ApiKey identifier
- `name` (String) Project ApiKey name
- `project_id` (String) Project identifier
29 changes: 29 additions & 0 deletions docs/data-sources/projects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_projects Data Source - terraform-provider-pinecone"
subcategory: ""
description: |-
Projects data source
---

# pinecone_projects (Data Source)

Projects data source



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

### Read-Only

- `id` (String) Projects identifier
- `projects` (Attributes List) List of the indexes in your project (see [below for nested schema](#nestedatt--projects))

<a id="nestedatt--projects"></a>
### Nested Schema for `projects`

Read-Only:

- `id` (String) Project identifier
- `name` (String) Index name
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ provider "pinecone" {}
### Optional

- `api_key` (String, Sensitive) Pinecone API Key. Can be configured by setting PINECONE_API_KEY environment variable.
- `mgmt_api_key` (String, Sensitive) Pinecone Management API Key. Can be configured by setting PINECONE_MGMT_API_KEY environment variable.
24 changes: 24 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_project Resource - terraform-provider-pinecone"
subcategory: ""
description: |-
Project resource
---

# pinecone_project (Resource)

Project resource



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

### Required

- `name` (String) The name of the project to be created.

### Read-Only

- `id` (String) Project identifier
26 changes: 26 additions & 0 deletions docs/resources/project_api_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pinecone_project_api_key Resource - terraform-provider-pinecone"
subcategory: ""
description: |-
Project ApiKey resource
---

# pinecone_project_api_key (Resource)

Project ApiKey resource



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

### Required

- `name` (String) The name of the api key to be created.
- `project_id` (String) The id of the project.

### Read-Only

- `id` (String) ApiKey identifier
- `secret` (String, Sensitive) The api key secret.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module github.com/pinecone-io/terraform-provider-pinecone
go 1.21.1

require (
github.com/google/uuid v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.18.0
github.com/hashicorp/terraform-plugin-framework v1.7.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.22.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hashicorp/terraform-plugin-testing v1.7.0
github.com/pinecone-io/go-pinecone v0.4.1
github.com/pinecone-io/go-pinecone v0.4.2-0.20240409191554-22cce8b07156
)

require (
Expand All @@ -29,7 +30,6 @@ require (
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmt
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/pinecone-io/go-pinecone v0.4.1 h1:hRJgtGUIHwvM1NvzKe+YXog4NxYi9x3NdfFhQ2QWBWk=
github.com/pinecone-io/go-pinecone v0.4.1/go.mod h1:KwWSueZFx9zccC+thBk13+LDiOgii8cff9bliUI4tQs=
github.com/pinecone-io/go-pinecone v0.4.2-0.20240409191554-22cce8b07156 h1:P2lW6WvEzpq6F1yBzWHSnsIup9SyTzUctbbBZr9b6F4=
github.com/pinecone-io/go-pinecone v0.4.2-0.20240409191554-22cce8b07156/go.mod h1:KwWSueZFx9zccC+thBk13+LDiOgii8cff9bliUI4tQs=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
46 changes: 46 additions & 0 deletions pinecone/models/project_api_keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package models

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/pinecone-io/go-pinecone/pinecone"
)

type ProjectApiKeysModel struct {
Id types.String `tfsdk:"id"`
ProjectId types.String `tfsdk:"project_id"`
ApiKeys []ProjectApiKeyModel `tfsdk:"api_keys"`
}

type ProjectApiKeyModel struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Secret types.String `tfsdk:"secret"`
ProjectId types.String `tfsdk:"project_id"`
}

func (model *ProjectApiKeyModel) Read(ctx context.Context, apiKey *pinecone.APIKeyWithSecret) diag.Diagnostics {
var diags diag.Diagnostics

model.Id = types.StringValue(apiKey.Id.String())
model.Name = types.StringValue(apiKey.Name)
model.Secret = types.StringValue(apiKey.Secret)
model.ProjectId = types.StringValue(apiKey.ProjectId.String())

return diags
}

func (model *ProjectApiKeyModel) ReadWithoutSecret(ctx context.Context, apiKey *pinecone.APIKeyWithoutSecret) diag.Diagnostics {
var diags diag.Diagnostics

model.Id = types.StringValue(apiKey.Id.String())
model.Name = types.StringValue(apiKey.Name)
model.ProjectId = types.StringValue(apiKey.ProjectId.String())

return diags
}
31 changes: 31 additions & 0 deletions pinecone/models/projects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package models

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/pinecone-io/go-pinecone/pinecone"
)

type ProjectsModel struct {
Id types.String `tfsdk:"id"`
Projects []ProjectModel `tfsdk:"projects"`
}

type ProjectModel struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

func (model *ProjectModel) Read(ctx context.Context, project *pinecone.Project) diag.Diagnostics {
var diags diag.Diagnostics

model.Id = types.StringValue(project.Id.String())
model.Name = types.StringValue(project.Name)

return diags
}
84 changes: 84 additions & 0 deletions pinecone/provider/api_key_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
"context"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/pinecone-io/terraform-provider-pinecone/pinecone/models"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &ProjectApiKeyDataSource{}

func NewProjectApiKeyDataSource() datasource.DataSource {
return &ProjectApiKeyDataSource{PineconeDatasource: &PineconeDatasource{}}
}

// ProjectApiKeyDataSource defines the data source implementation.
type ProjectApiKeyDataSource struct {
*PineconeDatasource
}

func (d *ProjectApiKeyDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_project_api_key"
}

func (d *ProjectApiKeyDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Project ApiKey data source",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "ApiKey identifier",
Computed: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "ApiKey Name",
Required: true,
},
"project_id": schema.StringAttribute{
MarkdownDescription: "Project identifier",
Required: true,
},
},
}
}

func (d *ProjectApiKeyDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data models.ProjectApiKeyModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}

projectId, _ := uuid.Parse(data.ProjectId.ValueString())
apiKeys, err := d.mgmtClient.ListApiKeys(ctx, projectId)
if err != nil {
resp.Diagnostics.AddError("Failed to list project api keys", err.Error())
return
}

for _, apiKey := range apiKeys {
if apiKey.Name == *data.Name.ValueStringPointer() {
data.ReadWithoutSecret(ctx, apiKey)
break
}
}

if data.Id.IsNull() {
resp.Diagnostics.AddError("Failed to find project api key with name: ", data.Name.String())
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading