-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Infisical/daniel/gcp-integration-support
feat: gcp integration support
- Loading branch information
Showing
7 changed files
with
761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "infisical_integration_gcp_secret_manager Resource - terraform-provider-infisical" | ||
subcategory: "" | ||
description: |- | ||
Create GCP Secret Manager integration & save to Infisical. Only Machine Identity authentication is supported for this data source | ||
--- | ||
|
||
# infisical_integration_gcp_secret_manager (Resource) | ||
|
||
Create GCP Secret Manager integration & save to Infisical. Only Machine Identity authentication is supported for this data source | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
terraform { | ||
required_providers { | ||
infisical = { | ||
# version = <latest version> | ||
source = "infisical/infisical" | ||
} | ||
} | ||
} | ||
provider "infisical" { | ||
host = "https://app.infisical.com" # Only required if using self hosted instance of Infisical, default is https://app.infisical.com | ||
client_id = "<machine-identity-client-id>" | ||
client_secret = "<machine-identity-client-secret>" | ||
} | ||
variable "service_account_json" { | ||
type = string | ||
description = "Google Cloud service account JSON key" | ||
} | ||
resource "infisical_integration_gcp_secret_manager" "gcp-integration" { | ||
project_id = "your-project-id" | ||
service_account_json = var.service_account_json | ||
environment = "dev" | ||
secret_path = "/" | ||
gcp_project_id = "gcp-project-id" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `environment` (String) The slug of the environment to sync to GCP Secret Manager (prod, dev, staging, etc). | ||
- `gcp_project_id` (String) The ID of the GCP project. | ||
- `project_id` (String) The ID of your Infisical project. | ||
- `secret_path` (String) The secret path in Infisical to sync secrets from. | ||
- `service_account_json` (String, Sensitive) Service account json for the GCP project. | ||
|
||
### Optional | ||
|
||
- `options` (Attributes) Integration options (see [below for nested schema](#nestedatt--options)) | ||
|
||
### Read-Only | ||
|
||
- `env_id` (String) The ID of the environment, used internally by Infisical. | ||
- `integration_auth_id` (String) The ID of the integration auth, used internally by Infisical. | ||
- `integration_id` (String) The ID of the integration, used internally by Infisical. | ||
|
||
<a id="nestedatt--options"></a> | ||
### Nested Schema for `options` | ||
|
||
Optional: | ||
|
||
- `secret_prefix` (String) The prefix to add to the secret name in GCP Secret Manager. | ||
- `secret_suffix` (String) The suffix to add to the secret name in GCP Secret Manager. |
30 changes: 30 additions & 0 deletions
30
examples/resources/infisical_integration_gcp_secret_manager/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
terraform { | ||
required_providers { | ||
infisical = { | ||
# version = <latest version> | ||
source = "infisical/infisical" | ||
} | ||
} | ||
} | ||
|
||
provider "infisical" { | ||
host = "https://app.infisical.com" # Only required if using self hosted instance of Infisical, default is https://app.infisical.com | ||
client_id = "<machine-identity-client-id>" | ||
client_secret = "<machine-identity-client-secret>" | ||
} | ||
|
||
variable "service_account_json" { | ||
type = string | ||
description = "Google Cloud service account JSON key" | ||
} | ||
|
||
|
||
|
||
resource "infisical_integration_gcp_secret_manager" "gcp-integration" { | ||
project_id = "your-project-id" | ||
service_account_json = var.service_account_json | ||
environment = "dev" | ||
secret_path = "/" | ||
gcp_project_id = "gcp-project-id" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package infisicalclient | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func (client Client) CreateIntegration(request CreateIntegrationRequest) (CreateIntegrationResponse, error) { | ||
var body CreateIntegrationResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Post("api/v1/integration") | ||
|
||
if err != nil { | ||
return CreateIntegrationResponse{}, fmt.Errorf("CreateIntegration: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return CreateIntegrationResponse{}, fmt.Errorf("CreateIntegration: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func (client Client) GetIntegration(request GetIntegrationRequest) (GetIntegrationResponse, error) { | ||
var body GetIntegrationResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
Get(fmt.Sprintf("api/v1/integration/%s", request.ID)) | ||
|
||
if err != nil { | ||
return GetIntegrationResponse{}, fmt.Errorf("CallGetIntegration: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
if response.StatusCode() == http.StatusNotFound { | ||
return GetIntegrationResponse{}, ErrNotFound | ||
} | ||
return GetIntegrationResponse{}, fmt.Errorf("CallGetIntegration: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func (client Client) UpdateIntegration(request UpdateIntegrationRequest) (UpdateIntegrationResponse, error) { | ||
var body UpdateIntegrationResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Patch(fmt.Sprintf("api/v1/integration/%s", request.ID)) | ||
|
||
if err != nil { | ||
return UpdateIntegrationResponse{}, fmt.Errorf("UpdateIntegration: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return UpdateIntegrationResponse{}, fmt.Errorf("UpdateIntegration: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package infisicalclient | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Enum containing the possible values for the `type` field in the CreateIntegrationAuthRequest. | ||
type IntegrationAuthType string | ||
|
||
const ( | ||
IntegrationAuthTypeGcpSecretManager IntegrationAuthType = "gcp-secret-manager" | ||
) | ||
|
||
func (client Client) CreateIntegrationAuth(request CreateIntegrationAuthRequest) (CreateIntegrationAuthResponse, error) { | ||
var body CreateIntegrationAuthResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Post("api/v1/integration-auth/access-token") | ||
|
||
if err != nil { | ||
return CreateIntegrationAuthResponse{}, fmt.Errorf("CreateIntegrationAuth: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return CreateIntegrationAuthResponse{}, fmt.Errorf("CreateIntegrationAuth: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
// Deleting integration auth triggers a cascade effect, that will also delete the associated integration. | ||
func (client Client) DeleteIntegrationAuth(request DeleteIntegrationAuthRequest) (DeleteIntegrationAuthResponse, error) { | ||
var body DeleteIntegrationAuthResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
Delete(fmt.Sprintf("api/v1/integration-auth/%s", request.ID)) | ||
|
||
if err != nil { | ||
return DeleteIntegrationAuthResponse{}, fmt.Errorf("DeleteIntegrationAuth: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return DeleteIntegrationAuthResponse{}, fmt.Errorf("DeleteIntegrationAuth: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.