-
Notifications
You must be signed in to change notification settings - Fork 43
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
chore: [CHAOS-6992]: Added support of chaos infrastructure #1138
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "harness_chaos_infrastructure Data Source - terraform-provider-harness" | ||
subcategory: "" | ||
description: |- | ||
Data source for retrieving a chaos infrastructure. | ||
--- | ||
|
||
# harness_chaos_infrastructure (Data Source) | ||
|
||
Data source for retrieving a chaos infrastructure. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "harness_chaos_infrastructure" "example" { | ||
identifier = "identifier" | ||
org_id = "org_id" | ||
project_id = "project_id" | ||
environment_id= "env_id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to fix the indentation here |
||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
|
||
## Schema | ||
|
||
### Required | ||
|
||
- `environment_id` (String) Environment identifier of the chaos infrastructure. | ||
- `identifier` (String) Identifier of the chaos infrastructure. | ||
- `org_id` (String) Identifier of the organization in which the chaos infrastructure is configured. | ||
- `project_id` (String) Identifier of the project in which the chaos infrastructure is configured. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||
--- | ||||||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||||||
page_title: "harness_chaos_infrastructure Resource - terraform-provider-harness" | ||||||
subcategory: "" | ||||||
description: |- | ||||||
Resource for creating a Chaos Infrastructure. | ||||||
--- | ||||||
|
||||||
# harness_chaos_infrastructure (Resource) | ||||||
|
||||||
Resource for creating a Chaos Infrastructure. | ||||||
|
||||||
### References: | ||||||
- For details on how to onboard with Terraform, please see [Harness Terraform Provider Overview](https://developer.harness.io/docs/platform/automation/terraform/harness-terraform-provider-overview/) | ||||||
|
||||||
## Example to create Chaos Infrastructure | ||||||
|
||||||
```terraform | ||||||
resource "harness_chaos_infrastructure" "example" { | ||||||
identifier = "identifier" | ||||||
name = "name" | ||||||
org_id = "org_id" | ||||||
project_id = "project_id" | ||||||
environment_id= "env_id" | ||||||
namespace= "namespace" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation fix |
||||||
service_account= "service_acc_name" | ||||||
} | ||||||
``` | ||||||
|
||||||
<!-- schema generated by tfplugindocs --> | ||||||
## Schema | ||||||
|
||||||
### Required | ||||||
|
||||||
- `org_id` (String) Unique identifier of the organization. | ||||||
- `project_id` (String) Unique identifier of the project. | ||||||
- `environment_id` (String) Environment ID of the chaos infrastructure. | ||||||
- `identifier` (String) Unique identifier of the resource. | ||||||
- `name` (String) Name of the resource. | ||||||
- `namespace` (String) Namespace of the chaos infrastructure. | ||||||
- `service_account` (String) Service Account of the chaos infrastructure. | ||||||
|
||||||
### Optional | ||||||
|
||||||
- `description` (String) Description of the resource. | ||||||
- `tags` (Set of String) Tags to associate with the resource. | ||||||
|
||||||
### Read-Only | ||||||
|
||||||
- `id` (String) The ID of this resource. | ||||||
|
||||||
## Import | ||||||
|
||||||
Import is supported using the following syntax: | ||||||
|
||||||
```shell | ||||||
# Import using the Harness application id and environment id. | ||||||
terraform import harness_environment.dev <application_id>/<environment_id> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
data "harness_chaos_infrastructure" "example" { | ||
identifier = "identifier" | ||
org_id = "org_id" | ||
project_id = "project_id" | ||
environment_id= "env_id" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Import using the Harness chaos_infra_id. | ||
terraform import harness_chaos_infrastructure.example <chaos_infra_id> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
# Sample resource for chaos infrastructure | ||
resource "harness_chaos_infrastructure" "example" { | ||
identifier = "identifier" | ||
name = "name" | ||
org_id = "org_id" | ||
project_id = "project_id" | ||
environment_id= "env_id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation fixes at all places wherever required |
||
namespace= "namespace" | ||
service_account= "service_acc_name" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package infrastructure | ||
|
||
import ( | ||
"context" | ||
"github.com/harness/terraform-provider-harness/helpers" | ||
"github.com/harness/terraform-provider-harness/internal" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceChaosInfrastructureService() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Description: "Data source for retrieving a chaos infrastructure.", | ||
|
||
ReadContext: dataSourceInfrastructureRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"org_id": { | ||
Description: "Identifier of the organization in which the chaos infrastructure is configured.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"project_id": { | ||
Description: "Identifier of the project in which the chaos infrastructure is configured.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"identifier": { | ||
Description: "Identifier of the chaos infrastructure.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"environment_id": { | ||
Description: "Environment identifier of the chaos infrastructure.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
|
||
return resource | ||
} | ||
|
||
func dataSourceInfrastructureRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c, ctx := meta.(*internal.Session).GetChaosClientWithContext(ctx) | ||
var accountIdentifier, orgIdentifier, projectIdentifier, identifier, envIdentifier string | ||
accountIdentifier = c.AccountId | ||
if attr, ok := d.GetOk("org_id"); ok { | ||
orgIdentifier = attr.(string) | ||
} | ||
if attr, ok := d.GetOk("project_id"); ok { | ||
projectIdentifier = attr.(string) | ||
} | ||
if attr, ok := d.GetOk("identifier"); ok { | ||
identifier = attr.(string) | ||
} | ||
if attr, ok := d.GetOk("environment_id"); ok { | ||
envIdentifier = attr.(string) | ||
} | ||
resp, httpResp, err := c.ChaosSdkApi.GetInfraV2(ctx, identifier, accountIdentifier, orgIdentifier, projectIdentifier, envIdentifier) | ||
|
||
if err != nil { | ||
if err.Error() == "404 Not Found" { | ||
d.SetId("") | ||
d.MarkNewResource() | ||
return nil | ||
} | ||
return helpers.HandleReadApiError(err, d, httpResp) | ||
} | ||
readChaosInfrastructure(d, resp) | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to have
Next Gen
as subcategory