Skip to content

Commit e32185f

Browse files
authored
Deployment engine resource (#113)
* deployment engine resource * finish implementation * test fix, use unique names per tf version * update generate test step * add generate to makefile
1 parent bf4f645 commit e32185f

File tree

9 files changed

+613
-6
lines changed

9 files changed

+613
-6
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ jobs:
3434
generate:
3535
runs-on: ubuntu-latest
3636
steps:
37-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
38-
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
3939
with:
40-
go-version-file: "go.mod"
40+
go-version-file: 'go.mod'
4141
cache: true
42-
- run: go generate ./...
42+
# We need the latest version of Terraform for our documentation generation to use
43+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
44+
with:
45+
terraform_wrapper: false
46+
- run: make generate
4347
- name: git diff
4448
run: |
4549
git diff --compact-summary --exit-code || \
46-
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
50+
(echo; echo "Unexpected difference in directories after code generation. Run 'make generate' command and commit."; exit 1)
4751
4852
# Run acceptance tests in a matrix with Terraform CLI versions
4953
test:

GNUmakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
default: testacc
2-
2+
generate:
3+
cd tools; go generate ./...
34
# Run acceptance tests
45
.PHONY: testacc
56
testacc:

client/deployment_engine.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package client
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"log"
8+
"net/http"
9+
)
10+
11+
func (c *Client) CreateDeploymentEngine(engine_type string, name string, description string, agent_name string, auth_token string, polling_interval_seconds int32, server_url string, allowed_spaces AllowedSpaces) error {
12+
data := DeploymentEngine{
13+
Name: name,
14+
Description: description,
15+
Type: engine_type,
16+
ServerUrl: server_url,
17+
AgentName: agent_name,
18+
AuthToken: auth_token,
19+
PollingIntervalSeconds: polling_interval_seconds,
20+
AllowedSpaces: allowed_spaces,
21+
}
22+
payload, err := json.Marshal(data)
23+
if err != nil {
24+
log.Fatalf("impossible to marshall deployment engine request: %s", err)
25+
}
26+
27+
req, err := http.NewRequest("POST", fmt.Sprintf("%sapi/deployment_engines", c.HostURL), bytes.NewReader(payload))
28+
if err != nil {
29+
return err
30+
}
31+
32+
req.Header.Add("Content-Type", "application/json")
33+
req.Header.Add("Accept", "application/json")
34+
35+
_, err = c.doRequest(req, &c.Token)
36+
if err != nil {
37+
return err
38+
}
39+
40+
return nil
41+
}
42+
43+
func (c *Client) GetDeploymentEngine(name string) (*DeploymentEngineRead, error) {
44+
req, err := http.NewRequest("GET", fmt.Sprintf("%sapi/deployment_engines/%s", c.HostURL, name), nil)
45+
if err != nil {
46+
return nil, err
47+
}
48+
req.Header.Add("Content-Type", "application/json")
49+
req.Header.Add("Accept", "application/json")
50+
51+
body, err := c.doRequest(req, &c.Token)
52+
if err != nil {
53+
return nil, err
54+
}
55+
56+
deployment_engine := DeploymentEngineRead{}
57+
58+
err = json.Unmarshal(body, &deployment_engine)
59+
if err != nil {
60+
return nil, err
61+
}
62+
return &deployment_engine, nil
63+
}
64+
65+
func (c *Client) UpdateDeploymentEngine(engine_type string, current_name string, name string, description string, agent_name string, auth_token string, polling_interval_seconds int32, server_url string, allowed_spaces AllowedSpaces) error {
66+
data := DeploymentEngine{
67+
Name: name,
68+
Description: description,
69+
Type: engine_type,
70+
ServerUrl: server_url,
71+
AgentName: agent_name,
72+
AuthToken: auth_token,
73+
PollingIntervalSeconds: polling_interval_seconds,
74+
AllowedSpaces: allowed_spaces,
75+
}
76+
payload, err := json.Marshal(data)
77+
if err != nil {
78+
log.Fatalf("impossible to marshall deployment engine request: %s", err)
79+
}
80+
81+
req, err := http.NewRequest("PUT", fmt.Sprintf("%sapi/deployment_engines/%s", c.HostURL, current_name), bytes.NewReader(payload))
82+
if err != nil {
83+
return err
84+
}
85+
86+
req.Header.Add("Content-Type", "application/json")
87+
req.Header.Add("Accept", "application/json")
88+
89+
_, err = c.doRequest(req, &c.Token)
90+
if err != nil {
91+
return err
92+
}
93+
94+
return nil
95+
}
96+
97+
func (c *Client) DeleteDeploymentEngine(name string) error {
98+
req, err := http.NewRequest("DELETE", fmt.Sprintf("%sapi/deployment_engines/%s", c.HostURL, name), nil)
99+
if err != nil {
100+
return err
101+
}
102+
103+
req.Header.Add("Content-Type", "application/json")
104+
req.Header.Add("Accept", "application/json")
105+
106+
_, err = c.doRequest(req, &c.Token)
107+
if err != nil {
108+
return err
109+
}
110+
111+
return nil
112+
}

client/models.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,35 @@ type ResourceInventoryDetails struct {
485485
Type string `json:"type"`
486486
ViewArn *string `json:"view_arn"`
487487
}
488+
489+
type DeploymentEngine struct {
490+
Name string `json:"name"`
491+
Description string `json:"description"`
492+
Type string `json:"type"`
493+
AuthToken string `json:"auth_token"`
494+
AgentName string `json:"agent_name"`
495+
ServerUrl string `json:"server_url"`
496+
PollingIntervalSeconds int32 `json:"polling_interval_seconds"`
497+
AllowedSpaces AllowedSpaces `json:"allowed_spaces"`
498+
}
499+
500+
type DeploymentEngineRead struct {
501+
Name string `json:"name"`
502+
Description string `json:"description"`
503+
Type string `json:"type"`
504+
AuthToken string `json:"auth_token"`
505+
Agent AgentDetails `json:"agent"`
506+
ServerUrl string `json:"server_url"`
507+
PollingIntervalSeconds PollingInterval `json:"polling_interval_seconds"`
508+
AllowedSpaces AllowedSpaces `json:"allowed_spaces"`
509+
}
510+
511+
type PollingInterval struct {
512+
Default float32 `json:"default"`
513+
Value float32 `json:"value"`
514+
}
515+
516+
type AgentDetails struct {
517+
Name string `json:"name"`
518+
Type string `json:"type"`
519+
}

docs/resources/deployment_engine.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "torque_deployment_engine Resource - terraform-provider-torque"
4+
subcategory: ""
5+
description: |-
6+
Creates a new deployment engine.
7+
---
8+
9+
# torque_deployment_engine (Resource)
10+
11+
Creates a new deployment engine.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "torque_deployment_engine" "engine" {
17+
name = "name"
18+
description = "description"
19+
agent_name = "agent"
20+
auth_token = "token"
21+
server_url = "https://argocd.com"
22+
polling_interval_seconds = 30
23+
all_spaces = true
24+
}
25+
```
26+
27+
<!-- schema generated by tfplugindocs -->
28+
## Schema
29+
30+
### Required
31+
32+
- `agent_name` (String) Type of the deployment engine.
33+
- `auth_token` (String, Sensitive) Token of the deployment engine.
34+
- `name` (String) Name of the deployment engine.
35+
- `server_url` (String) Server URL of the deployment engine
36+
37+
### Optional
38+
39+
- `all_spaces` (Boolean) Specify if the deployment engine can be used in all spaces. Defaults to true, use specific spaces attribute for allowing only specific spaces.
40+
- `description` (String) Description of the deployment engine
41+
- `polling_interval_seconds` (Number) Polling interval of the deployment engine in seconds.
42+
- `specific_spaces` (List of String) List of spaces that can use this deployment engine
43+
44+
### Read-Only
45+
46+
- `type` (String) Type of the deployment engine.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "torque_deployment_engine" "engine" {
2+
name = "name"
3+
description = "description"
4+
agent_name = "agent"
5+
auth_token = "token"
6+
server_url = "https://argocd.com"
7+
polling_interval_seconds = 30
8+
all_spaces = true
9+
}

internal/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (p *torqueProvider) Resources(ctx context.Context) []func() resource.Resour
236236
resources.NewTorqueAwsResourceInventoryResource,
237237
resources.NewTorqueAzureBlobObjectInputSourceResource,
238238
resources.NewTorqueAzureBlobObjectContentInputSourceResource,
239+
resources.NewTorqueDeploymentEngineResource,
239240
}
240241
}
241242

0 commit comments

Comments
 (0)