Skip to content

Commit

Permalink
Merge pull request #24 from fortanix/aman/dsm_app_data_source
Browse files Browse the repository at this point in the history
DEVOPS-2835 dsm_app data source
  • Loading branch information
aman-ahuja-fortanix authored Jul 28, 2022
2 parents 14f1699 + 6d1848d commit c0beb22
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ HOSTNAME=fortanix.com
NAMESPACE=fortanix
NAME=dsm
BINARY=terraform-provider-${NAME}
VERSION=0.5.15
VERSION=0.5.16
OS=linux
ARCH=amd64
OS_ARCH=${OS}_${ARCH}
Expand Down
29 changes: 29 additions & 0 deletions docs/data-sources/dsm_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# dsm\_app

## dsm\_app

Returns the Fortanix DSM app object from the cluster as a Data Source.

## Usage Reference

```
data "dsm_app" "app" {
app_id = <app_id>
}
```

## Argument Reference

The following arguments are supported in the `dsm_app` data block:

* **app_id**: App id value

## Attribute Reference

The following attributes are stored in the `dsm_app` data source block:

* **id**: The unique ID of object from Terraform
* **credential**: The Fortanix DSM App API key
* _**new\_credential**_: Set to false by default


2 changes: 1 addition & 1 deletion docs/data-sources/dsm_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data "dsm_group" "group" {

## Argument Reference

The following arguments are supported in the `dsm_group` resource block:
The following arguments are supported in the `dsm_group` data block:

* **name**: Group object name

Expand Down
67 changes: 67 additions & 0 deletions dsm/data_source_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// **********
// Terraform Provider - DSM: data source: app
// **********
// - Author: [email protected]
// - Version: 0.5.16
// - Date: 28/07/2022
// **********

package dsm

import (
"context"
"encoding/base64"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceApp() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAppRead,
Schema: map[string]*schema.Schema{
"app_id": {
Type: schema.TypeString,
Required: true,
},
"credential": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"new_credential": {
Type: schema.TypeBool,
Optional: true,
},
},
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
}
}

func dataSourceAppRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics

d.SetId(d.Get("app_id").(string))

req, _, err := m.(*api_client).APICall("GET", fmt.Sprintf("sys/v1/apps/%s/credential", d.Id()))
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "[DSM SDK] Unable to call DSM provider API client",
Detail: fmt.Sprintf("[E]: API: GET sys/v1/apps/-/credential: %v", err),
})
return diags
}

if err := d.Set("credential", base64.StdEncoding.EncodeToString([]byte(d.Id()+":"+req["credential"].(map[string]interface{})["secret"].(string)))); err != nil {
return diag.FromErr(err)
}

if err := d.Set("new_credential", false); err != nil {
return diag.FromErr(err)
}
return nil
}
1 change: 1 addition & 0 deletions dsm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func Provider() *schema.Provider {
"dsm_secret": dataSourceSecret(),
"dsm_group": dataSourceGroup(),
"dsm_version": dataSourceVersion(),
"dsm_app": dataSourceApp(),
},
ConfigureContextFunc: configureProvider,
}
Expand Down
40 changes: 28 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,38 @@ module terraform-provider-dsm
go 1.15

require (
cloud.google.com/go v0.103.0 // indirect
cloud.google.com/go/storage v1.24.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 // indirect
github.com/aws/aws-sdk-go v1.38.22
github.com/google/go-cmp v0.5.6 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f // indirect
github.com/aws/aws-sdk-go v1.44.64
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-getter v1.6.2 // indirect
github.com/hashicorp/go-hclog v1.2.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/jstemmer/go-junit-report v1.0.0 // indirect
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/mitchellh/cli v1.1.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/net v0.0.0-20220728030405-41545e8bf201 // indirect
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
golang.org/x/tools v0.1.12 // indirect
google.golang.org/api v0.89.0 // indirect
google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
4 changes: 2 additions & 2 deletions template/main.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
terraform {
required_providers {
dsm = {
version = "0.2.1"
source = "fortanix.com/fyoo/dsm"
version = "0.5.16"
source = "fortanix.com/dsm"
}
}
}
Expand Down

0 comments on commit c0beb22

Please sign in to comment.