-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-source): new lacework_agent_access_token
To have parity with our resource `lacework_agent_access_token` we are adding a new data source to retrieve Agent access tokens by looking up for the Token Alias. (a.k.a Token Name) Contributes #41 Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
6 changed files
with
109 additions
and
3 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,9 @@ | ||
provider "lacework" {} | ||
|
||
data "lacework_agent_access_token" "k8s" { | ||
name = "k8s-deployments" | ||
} | ||
|
||
output "lacework_agent_access_token" { | ||
value = data.lacework_agent_access_token.k8s.token | ||
} |
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,52 @@ | ||
package lacework | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
"github.com/lacework/go-sdk/api" | ||
) | ||
|
||
func dataSourceLaceworkAgentAccessToken() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceLaceworkAgentAccessTokenRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceLaceworkAgentAccessTokenRead(d *schema.ResourceData, meta interface{}) error { | ||
lacework := meta.(*api.Client) | ||
|
||
log.Printf("[INFO] Lookup agent access token.") | ||
response, err := lacework.Agents.ListTokens() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
lookupName := d.Get("name").(string) | ||
for _, token := range response.Data { | ||
if token.TokenAlias == lookupName { | ||
log.Printf("[INFO] agent access token found. name=%s, description=%s, enabled=%t", | ||
token.TokenAlias, token.Props.Description, token.Status()) | ||
|
||
d.Set("token", token.AccessToken) | ||
d.SetId(token.TokenAlias) | ||
|
||
return nil | ||
} | ||
} | ||
|
||
return fmt.Errorf("Agent access token with name '%s' was not found.", lookupName) | ||
} |
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
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,33 @@ | ||
--- | ||
subcategory: "Agents" | ||
layout: "lacework" | ||
page_title: "Lacework: lacework_agent_access_token" | ||
description: |- | ||
Lookup agent access token. | ||
--- | ||
|
||
# lacework\_agent\_access\_token | ||
|
||
Retrieve Lacework agent access tokens. | ||
|
||
-> **Note:** To list all agent access tokens in your Lacework account, use the | ||
Lacework CLI command `lacework agent token list`. To install this tool follow | ||
[this documentation](https://github.com/lacework/go-sdk/wiki/CLI-Documentation#installation). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "lacework_agent_access_token" "k8s" { | ||
name = "k8s-deployments" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The agent access token name. | ||
|
||
## Attribute Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `token` - The agent access token. |
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