Skip to content

Commit

Permalink
feat: [PL-38510]: added resource for api tokens (#556)
Browse files Browse the repository at this point in the history
* [PL-38510]: added resource for api tokens
  • Loading branch information
bhavya181 committed May 31, 2023
1 parent ce04df3 commit 82ad12d
Show file tree
Hide file tree
Showing 13 changed files with 1,274 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .changelog/556.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
platform_token - Added apikey token in Harness terraform provider
```
56 changes: 56 additions & 0 deletions docs/data-sources/platform_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_token Data Source - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Data source for retrieving a Harness ApiKey Token.
---

# harness_platform_token (Data Source)

Data source for retrieving a Harness ApiKey Token.

## Example Usage

```terraform
data "harness_platform_token" "test" {
identifier = "test_token"
parent_id = "apikey_parent_id"
org_id = "org_id"
project_id = "project_id"
apikey_id = "apikey_id"
apikey_type = "USER"
}
```

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

### Required

- `account_id` (String) Account Identifier for the Entity
- `apikey_id` (String) Identifier of the API Key
- `apikey_type` (String) Type of the API Key
- `identifier` (String) Identifier of the Token
- `name` (String) Name of the Token
- `parent_id` (String) Parent Entity Identifier of the API Key

### Optional

- `description` (String) Description of the Token
- `email` (String) Email Id of the user who created the Token
- `encoded_password` (String) Encoded password of the Token
- `org_id` (String) Organization Identifier for the Entity
- `project_id` (String) Project Identifier for the Entity
- `scheduled_expire_time` (Number) Scheduled expiry time in milliseconds
- `tags` (Map of String) Tags for the Token
- `username` (String) Name of the user who created the Token
- `valid` (Boolean) Boolean value to indicate if Token is valid or not.
- `valid_from` (Number) This is the time from which the Token is valid. The time is in milliseconds
- `valid_to` (Number) This is the time till which the Token is valid. The time is in milliseconds

### Read-Only

- `id` (String) The ID of this resource.


93 changes: 93 additions & 0 deletions docs/resources/platform_token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_token Resource - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for creating tokens.
---

# harness_platform_token (Resource)

Resource for creating tokens.

## Example Usage

```terraform
# Create token for account level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}
# Create token for org level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
org_id = "org_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}
# Create token for project level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
org_id = "org_id"
project_id = "project_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}
```

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

### Required

- `account_id` (String) Account Identifier for the Entity
- `apikey_id` (String) Identifier of the API Key
- `apikey_type` (String) Type of the API Key
- `identifier` (String) Identifier of the Token
- `name` (String) Name of the Token
- `parent_id` (String) Parent Entity Identifier of the API Key

### Optional

- `description` (String) Description of the Token
- `email` (String) Email Id of the user who created the Token
- `encoded_password` (String) Encoded password of the Token
- `org_id` (String) Organization Identifier for the Entity
- `project_id` (String) Project Identifier for the Entity
- `scheduled_expire_time` (Number) Scheduled expiry time in milliseconds
- `tags` (Map of String) Tags for the Token
- `username` (String) Name of the user who created the Token
- `valid` (Boolean) Boolean value to indicate if Token is valid or not.
- `valid_from` (Number) This is the time from which the Token is valid. The time is in milliseconds
- `valid_to` (Number) This is the time till which the Token is valid. The time is in milliseconds

### Read-Only

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

```shell
# Import account level token
terraform import harness_platform_token <parent_id>/<apikey_id>/<apikey_type>/<token_id>

# Import org level token
terraform import harness_platform_token <org_id>/<parent_id>/<apikey_id>/<apikey_type>/<token_id>

# Import project level token
terraform import harness_platform_token <org_id>/<project_id>/<parent_id>/<apikey_id>/<apikey_type>/<token_id>
```
8 changes: 8 additions & 0 deletions examples/data-sources/harness_platform_token/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "harness_platform_token" "test" {
identifier = "test_token"
parent_id = "apikey_parent_id"
org_id = "org_id"
project_id = "project_id"
apikey_id = "apikey_id"
apikey_type = "USER"
}
8 changes: 8 additions & 0 deletions examples/resources/harness_platform_token/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Import account level token
terraform import harness_platform_token <parent_id>/<apikey_id>/<apikey_type>/<token_id>

# Import org level token
terraform import harness_platform_token <org_id>/<parent_id>/<apikey_id>/<apikey_type>/<token_id>

# Import project level token
terraform import harness_platform_token <org_id>/<project_id>/<parent_id>/<apikey_id>/<apikey_type>/<token_id>
32 changes: 32 additions & 0 deletions examples/resources/harness_platform_token/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Create token for account level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}

# Create token for org level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
org_id = "org_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}

# Create token for project level apikey
resource "harness_platform_token" "test" {
identifier = "test_token"
name = "test token"
parent_id = "apikey_parent_id"
account_id = "account_id"
org_id = "org_id"
project_id = "project_id"
apikey_type = "USER"
apikey_id = "apikey_id"
}
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ require (
require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.2
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand All @@ -39,7 +41,7 @@ require (
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.5.1 // indirect
github.com/hashicorp/hc-install v0.5.2 // indirect
github.com/hashicorp/hcl/v2 v2.16.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.18.1 // indirect
Expand All @@ -51,9 +53,9 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/jhump/protoreflect v1.6.1 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
Expand All @@ -63,21 +65,20 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.8.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/genproto v0.0.0-20230524185152-1884fd1fac28 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 82ad12d

Please sign in to comment.