Skip to content

Commit 9043e3f

Browse files
authored
Merge pull request #1 from NikolayDupak/fix-credentials
Fix resource update for 'awx_credential'
2 parents 52076b4 + 417b3d4 commit 9043e3f

3 files changed

Lines changed: 19 additions & 28 deletions

File tree

docs/resources/credential.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ resource "awx_organization" "example" {
1717
name = "example"
1818
}
1919
20-
resource "awx_credential_machine" "example" {
21-
name = "example"
22-
description = "Example Machine Credential"
23-
organization_id = awx_organization.example.id
24-
credential_type = "Machine"
20+
resource "awx_credential" "example" {
21+
name = "example"
22+
description = "Example of ansible vault credential"
23+
organization_id = awx_organization.example.id
24+
credential_type_id = 3 # ansible vault
2525
inputs = {
26-
username = "admin"
27-
password = "password"
26+
vault_password = "admin"
27+
vault_id = "password"
2828
}
2929
}
3030
```
@@ -35,7 +35,7 @@ resource "awx_credential_machine" "example" {
3535
### Required
3636

3737
- `credential_type_id` (Number) Specify the type of credential you want to create. Refer to the Ansible Tower documentation for details on each type
38-
- `inputs` (String, Sensitive) The inputs to be created with the credential.
38+
- `inputs` (Map of String, Sensitive) The inputs to be created with the credential.
3939
- `name` (String) The name of the credential
4040
- `organization_id` (Number) The organization ID that the credential belongs to
4141

examples/resources/awx_credential/resource.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ resource "awx_organization" "example" {
22
name = "example"
33
}
44

5-
resource "awx_credential_machine" "example" {
6-
name = "example"
7-
description = "Example Machine Credential"
8-
organization_id = awx_organization.example.id
9-
credential_type = "Machine"
5+
resource "awx_credential" "example" {
6+
name = "example"
7+
description = "Example of ansible vault credential"
8+
organization_id = awx_organization.example.id
9+
credential_type_id = 3 # ansible vault
1010
inputs = {
11-
username = "admin"
12-
password = "password"
11+
vault_password = "admin"
12+
vault_id = "password"
1313
}
1414
}

internal/awx/resource_credential.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package awx
22

33
import (
44
"context"
5-
"encoding/json"
65
"strconv"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -42,7 +41,7 @@ func resourceCredential() *schema.Resource {
4241
Description: "Specify the type of credential you want to create. Refer to the Ansible Tower documentation for details on each type",
4342
},
4443
"inputs": {
45-
Type: schema.TypeString,
44+
Type: schema.TypeMap,
4645
Required: true,
4746
Sensitive: true,
4847
Description: "The inputs to be created with the credential.",
@@ -52,11 +51,7 @@ func resourceCredential() *schema.Resource {
5251
}
5352

5453
func resourceCredentialCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
55-
inputs := d.Get("inputs").(string)
56-
inputsMap := make(map[string]interface{})
57-
if err := json.Unmarshal([]byte(inputs), &inputsMap); err != nil {
58-
return utils.DiagCreate(diagCredentialTitle, err)
59-
}
54+
inputsMap := d.Get("inputs")
6055

6156
payload := map[string]interface{}{
6257
"name": d.Get("name").(string),
@@ -115,11 +110,7 @@ func resourceCredentialUpdate(ctx context.Context, d *schema.ResourceData, m int
115110
if d.HasChanges(keys...) {
116111
var err error
117112

118-
inputs := d.Get("inputs").(string)
119-
inputsMap := make(map[string]interface{})
120-
if err := json.Unmarshal([]byte(inputs), &inputsMap); err != nil {
121-
return utils.DiagUpdate(diagCredentialTitle, d.Id(), err)
122-
}
113+
inputsMap := d.Get("inputs")
123114

124115
id, err := strconv.Atoi(d.Id())
125116
if err != nil {
@@ -139,7 +130,7 @@ func resourceCredentialUpdate(ctx context.Context, d *schema.ResourceData, m int
139130
}
140131
}
141132

142-
return resourceCredentialSCMRead(ctx, d, m)
133+
return resourceCredentialRead(ctx, d, m)
143134
}
144135

145136
func resourceCredentialDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

0 commit comments

Comments
 (0)