-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from fortanix/aman/dsm_app_data_source
DEVOPS-2835 dsm_app data source
- Loading branch information
Showing
7 changed files
with
129 additions
and
16 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
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,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 | ||
|
||
|
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,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 | ||
} |
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