Skip to content

Commit 55b7d41

Browse files
authored
feat: add AWX token authentication (#15)
Co-authored-by: jnahelou
1 parent 653f346 commit 55b7d41

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

awx/provider.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func Provider() *schema.Provider {
3535
Sensitive: true,
3636
DefaultFunc: schema.EnvDefaultFunc("AWX_PASSWORD", "password"),
3737
},
38+
"token": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Sensitive: true,
42+
DefaultFunc: schema.EnvDefaultFunc("AWX_TOKEN", ""),
43+
},
3844
},
3945
ResourcesMap: map[string]*schema.Resource{
4046
"awx_credential_azure_key_vault": resourceCredentialAzureKeyVault(),
@@ -98,6 +104,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
98104
hostname := d.Get("hostname").(string)
99105
username := d.Get("username").(string)
100106
password := d.Get("password").(string)
107+
token := d.Get("token").(string)
101108

102109
// Warning or errors can be collected in a slice type
103110
var diags diag.Diagnostics
@@ -109,7 +116,13 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
109116
client.Transport = customTransport
110117
}
111118

112-
c, err := awx.NewAWX(hostname, username, password, client)
119+
var c *awx.AWX
120+
var err error
121+
if token != "" {
122+
c, err = awx.NewAWXToken(hostname, token, client)
123+
} else {
124+
c, err = awx.NewAWX(hostname, username, password, client)
125+
}
113126
if err != nil {
114127
diags = append(diags, diag.Diagnostic{
115128
Severity: diag.Error,

docs/index.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@ Ansible Tower Provider for handle Tower Projects with [rest](https://docs.ansibl
55

66
## Example Usage
77

8+
Using username and password:
9+
```hcl
10+
provider "awx" {
11+
hostname = "http://localhost:8078"
12+
username = "test"
13+
password = "changeme"
14+
}
15+
```
16+
17+
Using token:
818
```hcl
919
provider "awx" {
1020
hostname = "http://localhost:8078"
11-
username = "test"
12-
password = "changeme"
21+
token = "awxtoken"
1322
}
1423
```
1524

25+
> ⚠️ Be careful, if you set both token and username/password the token will have the precedence.
26+
1627
## Argument Reference
1728

1829
The following arguments are supported:
1930

2031
* `hostname` - (Optional) The API endpoint for AWX. Defaults to `"http://localhost"`.
2132
* `username` - (Optional) The username for API access. Defaults to `"admin"`.
2233
* `password` - (Optional) The password for API access. Defaults to `"password"`.
34+
* `token` - (Optional) The AWX token for API access. Defaults to empty.
2335
* `insecure` - (Optional) Whether to check the TLS certificate. Defaults to `false`.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/denouche/terraform-provider-awx
33
go 1.14
44

55
require (
6-
github.com/denouche/goawx v0.14.1
6+
github.com/denouche/goawx v0.17.0
77
github.com/gruntwork-io/terratest v0.31.2
88
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
99
github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2
137137
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
138138
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
139139
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
140-
github.com/denouche/goawx v0.14.1 h1:YyH5v9Ex8iqvLvWH58G+QA0AEi5vDgaBRe1H4HbdjwA=
141-
github.com/denouche/goawx v0.14.1/go.mod h1:MppzSteoj2xgfiqiRWW/Bf1a8z2FrRyvah1z0J2vJTY=
140+
github.com/denouche/goawx v0.17.0 h1:mtCfsYdKBSTO/3BGFPU7q13shAneLSlaJYEmqgLVwC0=
141+
github.com/denouche/goawx v0.17.0/go.mod h1:MppzSteoj2xgfiqiRWW/Bf1a8z2FrRyvah1z0J2vJTY=
142142
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
143143
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
144144
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=

0 commit comments

Comments
 (0)