generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [CHAOS-6992]: Added support of chaos infrastructure (#1138)
* chore: [CHAOS-6992]: Added support of chaos infrastructure Signed-off-by: Saranya-jena <[email protected]> * chore: [CHAOS-6992]: resolved comments Signed-off-by: Saranya-jena <[email protected]> * chore: [CHAOS-6992]: fixed imports Signed-off-by: Saranya-jena <[email protected]> --------- Signed-off-by: Saranya-jena <[email protected]>
- Loading branch information
1 parent
437a79a
commit 43d3f98
Showing
9 changed files
with
488 additions
and
1 deletion.
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,37 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "harness_chaos_infrastructure Data Source - terraform-provider-harness" | ||
subcategory: "Next Gen" | ||
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" | ||
} | ||
``` | ||
|
||
<!-- 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. |
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,61 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "harness_chaos_infrastructure Resource - terraform-provider-harness" | ||
subcategory: "Next Gen" | ||
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" | ||
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 Chaos Infra ID. | ||
terraform import harness_chaos_infrastructure.example <chaos_infra_id> | ||
``` |
6 changes: 6 additions & 0 deletions
6
examples/data-sources/harness_chaos_infrastructure/data-source.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,6 @@ | ||
data "harness_chaos_infrastructure" "example" { | ||
identifier = "identifier" | ||
org_id = "org_id" | ||
project_id = "project_id" | ||
environment_id= "env_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,2 @@ | ||
# Import using the Harness chaos_infra_id. | ||
terraform import harness_chaos_infrastructure.example <chaos_infra_id> |
11 changes: 11 additions & 0 deletions
11
examples/resources/harness_chaos_infrastructure/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,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" | ||
namespace = "namespace" | ||
service_account = "service_acc_name" | ||
} |
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
74 changes: 74 additions & 0 deletions
74
internal/service/chaos/infrastructure/data_source_infrastructure.go
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,74 @@ | ||
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: dataSourceChaosInfrastructureRead, | ||
|
||
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 dataSourceChaosInfrastructureRead(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 | ||
} |
Oops, something went wrong.