Skip to content

Commit 24b69c5

Browse files
committed
feat: add resources awx_job_template_notification_template_success awx_job_template_notification_template_error awx_job_template_notification_template_started
1 parent 2af9b32 commit 24b69c5

11 files changed

Lines changed: 334 additions & 35 deletions

.goreleaser.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ builds:
1717
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
1818
goos:
1919
- linux
20-
# - freebsd
21-
# - darwin
22-
# - windows
20+
# - freebsd # TODO add it after dev is done
21+
# - darwin # TODO add it after dev is done
22+
# - windows # TODO add it after dev is done
2323
goarch:
2424
- amd64
25-
# - '386'
26-
# - arm
27-
# - arm64
25+
# - '386' # TODO add it after dev is done
26+
# - arm # TODO add it after dev is done
27+
# - arm64 # TODO add it after dev is done
2828
ignore:
2929
- goos: darwin
3030
goarch: '386'

awx/provider.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,35 @@ func Provider() *schema.Provider {
3737
},
3838
},
3939
ResourcesMap: map[string]*schema.Resource{
40-
"awx_credential_azure_key_vault": resourceCredentialAzureKeyVault(),
41-
"awx_credential_google_compute_engine": resourceCredentialGoogleComputeEngine(),
42-
"awx_credential_input_source": resourceCredentialInputSource(),
43-
"awx_credential": resourceCredential(),
44-
"awx_credential_type": resourceCredentialType(),
45-
"awx_credential_machine": resourceCredentialMachine(),
46-
"awx_credential_scm": resourceCredentialSCM(),
47-
"awx_host": resourceHost(),
48-
"awx_inventory_group": resourceInventoryGroup(),
49-
"awx_inventory_source": resourceInventorySource(),
50-
"awx_inventory": resourceInventory(),
51-
"awx_job_template_credential": resourceJobTemplateCredentials(),
52-
"awx_job_template": resourceJobTemplate(),
53-
"awx_job_template_launch": resourceJobTemplateLaunch(),
54-
"awx_notification_template": resourceNotificationTemplate(),
55-
"awx_organization": resourceOrganization(),
56-
"awx_project": resourceProject(),
57-
"awx_schedule": resourceSchedule(),
58-
"awx_settings_ldap_team_map": resourceSettingsLDAPTeamMap(),
59-
"awx_team": resourceTeam(),
60-
"awx_workflow_job_template_node_always": resourceWorkflowJobTemplateNodeAlways(),
61-
"awx_workflow_job_template_node_failure": resourceWorkflowJobTemplateNodeFailure(),
62-
"awx_workflow_job_template_node_success": resourceWorkflowJobTemplateNodeSuccess(),
63-
"awx_workflow_job_template_node": resourceWorkflowJobTemplateNode(),
64-
"awx_workflow_job_template": resourceWorkflowJobTemplate(),
65-
"awx_workflow_job_template_schedule": resourceWorkflowJobTemplateSchedule(),
40+
"awx_credential_azure_key_vault": resourceCredentialAzureKeyVault(),
41+
"awx_credential_google_compute_engine": resourceCredentialGoogleComputeEngine(),
42+
"awx_credential_input_source": resourceCredentialInputSource(),
43+
"awx_credential": resourceCredential(),
44+
"awx_credential_type": resourceCredentialType(),
45+
"awx_credential_machine": resourceCredentialMachine(),
46+
"awx_credential_scm": resourceCredentialSCM(),
47+
"awx_host": resourceHost(),
48+
"awx_inventory_group": resourceInventoryGroup(),
49+
"awx_inventory_source": resourceInventorySource(),
50+
"awx_inventory": resourceInventory(),
51+
"awx_job_template_credential": resourceJobTemplateCredentials(),
52+
"awx_job_template": resourceJobTemplate(),
53+
"awx_job_template_launch": resourceJobTemplateLaunch(),
54+
"awx_job_template_notification_template_error": resourceJobTemplateNotificationTemplateError(),
55+
"awx_job_template_notification_template_started": resourceJobTemplateNotificationTemplateStarted(),
56+
"awx_job_template_notification_template_success": resourceJobTemplateNotificationTemplateSuccess(),
57+
"awx_notification_template": resourceNotificationTemplate(),
58+
"awx_organization": resourceOrganization(),
59+
"awx_project": resourceProject(),
60+
"awx_schedule": resourceSchedule(),
61+
"awx_settings_ldap_team_map": resourceSettingsLDAPTeamMap(),
62+
"awx_team": resourceTeam(),
63+
"awx_workflow_job_template_node_always": resourceWorkflowJobTemplateNodeAlways(),
64+
"awx_workflow_job_template_node_failure": resourceWorkflowJobTemplateNodeFailure(),
65+
"awx_workflow_job_template_node_success": resourceWorkflowJobTemplateNodeSuccess(),
66+
"awx_workflow_job_template_node": resourceWorkflowJobTemplateNode(),
67+
"awx_workflow_job_template": resourceWorkflowJobTemplate(),
68+
"awx_workflow_job_template_schedule": resourceWorkflowJobTemplateSchedule(),
6669
},
6770
DataSourcesMap: map[string]*schema.Resource{
6871
"awx_credential_azure_key_vault": dataSourceCredentialAzure(),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*TBD*
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "awx_job_template_notification_template_error" "baseconfig" {
8+
job_template_id = awx_job_template.baseconfig.id
9+
notification_template_id = awx_notification_template.default.id
10+
}
11+
```
12+
13+
*/
14+
package awx
15+
16+
import (
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
)
19+
20+
func resourceJobTemplateNotificationTemplateError() *schema.Resource {
21+
return &schema.Resource{
22+
CreateContext: resourceJobTemplateNotificationTemplateCreateForType("error"),
23+
DeleteContext: resourceJobTemplateNotificationTemplateDeleteForType("error"),
24+
ReadContext: resourceJobTemplateNotificationTemplateRead,
25+
26+
Schema: map[string]*schema.Schema{
27+
"job_template_id": {
28+
Type: schema.TypeInt,
29+
Required: true,
30+
ForceNew: true,
31+
},
32+
"notification_template_id": {
33+
Type: schema.TypeInt,
34+
Required: true,
35+
ForceNew: true,
36+
},
37+
},
38+
}
39+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package awx
2+
3+
import (
4+
"context"
5+
"strconv"
6+
7+
awx "github.com/denouche/goawx/client"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
func getResourceJobTemplateNotificationTemplateAssociateFuncForType(client *awx.JobTemplateNotificationTemplatesService, typ string) func(jobTemplateID int, notificationTemplateID int) (*awx.NotificationTemplate, error) {
13+
switch typ {
14+
case "error":
15+
return client.AssociateJobTemplateNotificationTemplatesError
16+
case "success":
17+
return client.AssociateJobTemplateNotificationTemplatesSuccess
18+
case "started":
19+
return client.AssociateJobTemplateNotificationTemplatesStarted
20+
}
21+
return nil
22+
}
23+
24+
func getResourceJobTemplateNotificationTemplateDisassociateFuncForType(client *awx.JobTemplateNotificationTemplatesService, typ string) func(jobTemplateID int, notificationTemplateID int) (*awx.NotificationTemplate, error) {
25+
switch typ {
26+
case "error":
27+
return client.DisassociateJobTemplateNotificationTemplatesError
28+
case "success":
29+
return client.DisassociateJobTemplateNotificationTemplatesSuccess
30+
case "started":
31+
return client.DisassociateJobTemplateNotificationTemplatesStarted
32+
}
33+
return nil
34+
}
35+
36+
func resourceJobTemplateNotificationTemplateCreateForType(typ string) func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
37+
return func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
38+
var diags diag.Diagnostics
39+
client := m.(*awx.AWX)
40+
awxJobTemplateService := client.JobTemplateService
41+
jobTemplateID := d.Get("job_template_id").(int)
42+
_, err := awxJobTemplateService.GetJobTemplateByID(jobTemplateID, make(map[string]string))
43+
if err != nil {
44+
return buildDiagNotFoundFail("job template", jobTemplateID, err)
45+
}
46+
47+
awxJobTemplateNotifService := client.JobTemplateNotificationTemplatesService
48+
notificationTemplateID := d.Get("notification_template_id").(int)
49+
associationFunc := getResourceJobTemplateNotificationTemplateAssociateFuncForType(awxJobTemplateNotifService, typ)
50+
if associationFunc == nil {
51+
return buildDiagnosticsMessage("Create: JobTemplate not AssociateJobTemplateNotificationTemplates", "Fail to find association function for notification_template type %s", typ)
52+
}
53+
54+
result, err := associationFunc(jobTemplateID, notificationTemplateID)
55+
if err != nil {
56+
return buildDiagnosticsMessage("Create: JobTemplate not AssociateJobTemplateNotificationTemplates", "Fail to associate notification_template credentials with ID %v, for job_template ID %v, got error: %s", notificationTemplateID, jobTemplateID, err.Error())
57+
}
58+
59+
d.SetId(strconv.Itoa(result.ID))
60+
return diags
61+
}
62+
}
63+
64+
func resourceJobTemplateNotificationTemplateRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
65+
var diags diag.Diagnostics
66+
return diags
67+
}
68+
69+
func resourceJobTemplateNotificationTemplateDeleteForType(typ string) func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
70+
return func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
71+
var diags diag.Diagnostics
72+
client := m.(*awx.AWX)
73+
awxJobTemplateService := client.JobTemplateService
74+
jobTemplateID := d.Get("job_template_id").(int)
75+
_, err := awxJobTemplateService.GetJobTemplateByID(jobTemplateID, make(map[string]string))
76+
if err != nil {
77+
return buildDiagNotFoundFail("job template", jobTemplateID, err)
78+
}
79+
80+
awxJobTemplateNotifService := client.JobTemplateNotificationTemplatesService
81+
notificationTemplateID := d.Get("notification_template_id").(int)
82+
disassociationFunc := getResourceJobTemplateNotificationTemplateDisassociateFuncForType(awxJobTemplateNotifService, typ)
83+
if disassociationFunc == nil {
84+
return buildDiagnosticsMessage("Create: JobTemplate not DisassociateJobTemplateNotificationTemplates", "Fail to find disassociation function for notification_template type %s", typ)
85+
}
86+
87+
_, err = disassociationFunc(jobTemplateID, notificationTemplateID)
88+
if err != nil {
89+
return buildDiagnosticsMessage("Create: JobTemplate not DisassociateJobTemplateNotificationTemplates", "Fail to associate notification_template credentials with ID %v, for job_template ID %v, got error: %s", notificationTemplateID, jobTemplateID, err.Error())
90+
}
91+
92+
d.SetId("")
93+
return diags
94+
}
95+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*TBD*
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "awx_job_template_notification_template_started" "baseconfig" {
8+
job_template_id = awx_job_template.baseconfig.id
9+
notification_template_id = awx_notification_template.default.id
10+
}
11+
```
12+
13+
*/
14+
package awx
15+
16+
import (
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
)
19+
20+
func resourceJobTemplateNotificationTemplateStarted() *schema.Resource {
21+
return &schema.Resource{
22+
CreateContext: resourceJobTemplateNotificationTemplateCreateForType("started"),
23+
DeleteContext: resourceJobTemplateNotificationTemplateDeleteForType("started"),
24+
ReadContext: resourceJobTemplateNotificationTemplateRead,
25+
26+
Schema: map[string]*schema.Schema{
27+
"job_template_id": {
28+
Type: schema.TypeInt,
29+
Required: true,
30+
ForceNew: true,
31+
},
32+
"notification_template_id": {
33+
Type: schema.TypeInt,
34+
Required: true,
35+
ForceNew: true,
36+
},
37+
},
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*TBD*
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "awx_job_template_notification_template_success" "baseconfig" {
8+
job_template_id = awx_job_template.baseconfig.id
9+
notification_template_id = awx_notification_template.default.id
10+
}
11+
```
12+
13+
*/
14+
package awx
15+
16+
import (
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
)
19+
20+
func resourceJobTemplateNotificationTemplateSuccess() *schema.Resource {
21+
return &schema.Resource{
22+
CreateContext: resourceJobTemplateNotificationTemplateCreateForType("success"),
23+
DeleteContext: resourceJobTemplateNotificationTemplateDeleteForType("success"),
24+
ReadContext: resourceJobTemplateNotificationTemplateRead,
25+
26+
Schema: map[string]*schema.Schema{
27+
"job_template_id": {
28+
Type: schema.TypeInt,
29+
Required: true,
30+
ForceNew: true,
31+
},
32+
"notification_template_id": {
33+
Type: schema.TypeInt,
34+
Required: true,
35+
ForceNew: true,
36+
},
37+
},
38+
}
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: "awx"
3+
page_title: "AWX: awx_job_template_notification_template_error"
4+
sidebar_current: "docs-awx-resource-job_template_notification_template_error"
5+
description: |-
6+
*TBD*
7+
---
8+
9+
# awx_job_template_notification_template_error
10+
11+
*TBD*
12+
13+
## Example Usage
14+
15+
```hcl
16+
resource "awx_job_template_notification_template_error" "baseconfig" {
17+
job_template_id = awx_job_template.baseconfig.id
18+
notification_template_id = awx_notification_template.default.id
19+
}
20+
```
21+
22+
## Argument Reference
23+
24+
The following arguments are supported:
25+
26+
* `notification_template_id` - (Required, ForceNew)
27+
* `job_template_id` - (Required, ForceNew)
28+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: "awx"
3+
page_title: "AWX: awx_job_template_notification_template_started"
4+
sidebar_current: "docs-awx-resource-job_template_notification_template_started"
5+
description: |-
6+
*TBD*
7+
---
8+
9+
# awx_job_template_notification_template_started
10+
11+
*TBD*
12+
13+
## Example Usage
14+
15+
```hcl
16+
resource "awx_job_template_notification_template_started" "baseconfig" {
17+
job_template_id = awx_job_template.baseconfig.id
18+
notification_template_id = awx_notification_template.default.id
19+
}
20+
```
21+
22+
## Argument Reference
23+
24+
The following arguments are supported:
25+
26+
* `notification_template_id` - (Required, ForceNew)
27+
* `job_template_id` - (Required, ForceNew)
28+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: "awx"
3+
page_title: "AWX: awx_job_template_notification_template_success"
4+
sidebar_current: "docs-awx-resource-job_template_notification_template_success"
5+
description: |-
6+
*TBD*
7+
---
8+
9+
# awx_job_template_notification_template_success
10+
11+
*TBD*
12+
13+
## Example Usage
14+
15+
```hcl
16+
resource "awx_job_template_notification_template_success" "baseconfig" {
17+
job_template_id = awx_job_template.baseconfig.id
18+
notification_template_id = awx_notification_template.default.id
19+
}
20+
```
21+
22+
## Argument Reference
23+
24+
The following arguments are supported:
25+
26+
* `notification_template_id` - (Required, ForceNew)
27+
* `job_template_id` - (Required, ForceNew)
28+

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.6.4-0.20211224145227-c9a3c4c0046d
6+
github.com/denouche/goawx v0.7.1-0.20220104163959-7c8ac398b1ae
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

0 commit comments

Comments
 (0)