-
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 #47 from Infisical/feat/project-environment-resource
feat: project environment resource
- Loading branch information
Showing
6 changed files
with
465 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,54 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "infisical_project_environment Resource - terraform-provider-infisical" | ||
subcategory: "" | ||
description: |- | ||
Create project environment | ||
--- | ||
|
||
# infisical_project_environment (Resource) | ||
|
||
Create project environment | ||
|
||
## 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 = "<>" | ||
client_secret = "<>" | ||
} | ||
resource "infisical_project" "example" { | ||
name = "example" | ||
slug = "example" | ||
} | ||
resource "infisical_project_environment" "pre-prod" { | ||
name = "pre-prod" | ||
project_id = infisical_project.example.id | ||
slug = "preprod" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the environment | ||
- `project_id` (String) The Infisical project ID (Required for Machine Identity auth, and service tokens with multiple scopes) | ||
- `slug` (String) The slug of the environment | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the environment |
25 changes: 25 additions & 0 deletions
25
examples/resources/infisical_project_environment/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,25 @@ | ||
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 = "<>" | ||
client_secret = "<>" | ||
} | ||
|
||
resource "infisical_project" "example" { | ||
name = "example" | ||
slug = "example" | ||
} | ||
|
||
resource "infisical_project_environment" "pre-prod" { | ||
name = "pre-prod" | ||
project_id = infisical_project.example.id | ||
slug = "preprod" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package infisicalclient | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func (client Client) CreateProjectEnvironment(request CreateProjectEnvironmentRequest) (CreateProjectEnvironmentResponse, error) { | ||
var body CreateProjectEnvironmentResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Post(fmt.Sprintf("api/v1/workspace/%s/environments", request.ProjectID)) | ||
|
||
if err != nil { | ||
return CreateProjectEnvironmentResponse{}, fmt.Errorf("CallCreateProjectEnvironment: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return CreateProjectEnvironmentResponse{}, fmt.Errorf("CallCreateProjectEnvironment: Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func (client Client) DeleteProjectEnvironment(request DeleteProjectEnvironmentRequest) (DeleteProjectEnvironmentResponse, error) { | ||
var body DeleteProjectEnvironmentResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Delete(fmt.Sprintf("api/v1/workspace/%s/environments/%s", request.ProjectID, request.ID)) | ||
|
||
if err != nil { | ||
return DeleteProjectEnvironmentResponse{}, fmt.Errorf("CallDeleteProjectEnvironment: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return DeleteProjectEnvironmentResponse{}, fmt.Errorf("CallDeleteProjectEnvironment Unsuccessful response. [response=%s]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func (client Client) GetProjectEnvironmentByID(request GetProjectEnvironmentByIDRequest) (GetProjectEnvironmentByIDResponse, error) { | ||
var body GetProjectEnvironmentByIDResponse | ||
|
||
httpRequest := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT) | ||
|
||
response, err := httpRequest.Get(fmt.Sprintf("api/v1/workspace/%s/environments/%s", request.ProjectID, request.ID)) | ||
|
||
if response.StatusCode() == http.StatusNotFound { | ||
return GetProjectEnvironmentByIDResponse{}, ErrNotFound | ||
} | ||
|
||
if err != nil { | ||
return GetProjectEnvironmentByIDResponse{}, fmt.Errorf("GetProjectEnvironmentByID: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return GetProjectEnvironmentByIDResponse{}, fmt.Errorf("GetProjectEnvironmentByID: Unsuccessful response. [response=%v]", string(response.Body())) | ||
} | ||
|
||
return body, nil | ||
} | ||
|
||
func (client Client) UpdateProjectEnvironment(request UpdateProjectEnvironmentRequest) (UpdateProjectEnvironmentResponse, error) { | ||
var body UpdateProjectEnvironmentResponse | ||
response, err := client.Config.HttpClient. | ||
R(). | ||
SetResult(&body). | ||
SetHeader("User-Agent", USER_AGENT). | ||
SetBody(request). | ||
Patch(fmt.Sprintf("api/v1/workspace/%s/environments/%s", request.ProjectID, request.ID)) | ||
|
||
if err != nil { | ||
return UpdateProjectEnvironmentResponse{}, fmt.Errorf("CallUpdateProjectEnvironment: Unable to complete api request [err=%s]", err) | ||
} | ||
|
||
if response.IsError() { | ||
return UpdateProjectEnvironmentResponse{}, fmt.Errorf("CallUpdateProjectEnvironment: 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
Oops, something went wrong.