-
-
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.
Rename the datasource gocd_agent_config to gocd_agent to keep it in sync with resource
- Loading branch information
1 parent
10f8000
commit 4d67fd1
Showing
14 changed files
with
241 additions
and
23 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
docs/data-sources/agent_config.md → docs/data-sources/agent.md
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,44 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gocd_agent Resource - terraform-provider-gocd" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# gocd_agent (Resource) | ||
Update configuration of a specified agent by interacting with GoCD [api](https://api.gocd.org/current/#update-an-agent). | ||
|
||
## Example Usage | ||
```terraform | ||
resource "gocd_agent" "sample_agent" { | ||
uuid = "bbfe3a75-7fd8-48db-af32-0a91b9efd0ab" | ||
agent_config_state = "ENABLED" | ||
environments = ["sample_environment_3"] | ||
resources = ["linux"] | ||
hostname = "sample.agent001.com" | ||
} | ||
``` | ||
**NOTE:** Since this resource updates the agent config, `terraform destroy` of this would just remove its reference from state and does not delete the agent itself. | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `uuid` (String) The identifier of this agent. | ||
|
||
### Optional | ||
|
||
- `agent_config_state` (String) Whether an agent is enabled or not. Can be one of `Enabled`, `Disabled`. | ||
- `environments` (List of String) The set of environments that this agent belongs to. | ||
- `hostname` (String) The hostname of the agent. | ||
- `ip_address` (String) The IP address of the agent. | ||
- `operating_system` (String) The operating system as reported by the agent. | ||
- `resources` (List of String) The set of resources that this agent is tagged with (if agent is not an elastic agent). | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
data "gocd_agent_config" "sample_agent" { | ||
uuid = "3bc47e62-eb8f-4c37-b082-1517f10ef7aa" | ||
resource "gocd_agent" "sample_agent" { | ||
uuid = "bbfe3a75-7fd8-48db-af32-0a91b9efd0ab" | ||
environments = ["sample_environment_3"] | ||
} | ||
|
||
data "gocd_agent" "sample_agent" { | ||
uuid = "bbfe3a75-7fd8-48db-af32-0a91b9efd0ab" | ||
} |
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,3 @@ | ||
//resource "gocd_backup_schedule" "now" { | ||
// schedule = true | ||
//} |
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
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
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 |
---|---|---|
@@ -1,8 +1,132 @@ | ||
package provider | ||
|
||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/nikhilsbhat/gocd-sdk-go" | ||
"github.com/nikhilsbhat/terraform-provider-gocd/pkg/utils" | ||
) | ||
|
||
//nolint:deadcode,unused | ||
func resourceAgentConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceAgentConfigCreate, | ||
ReadContext: resourceAgentConfigRead, | ||
DeleteContext: resourceAgentConfigDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"uuid": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The identifier of this agent.", | ||
}, | ||
"hostname": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The hostname of the agent.", | ||
}, | ||
"agent_config_state": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "Whether an agent is enabled or not. Can be one of `Enabled`, `Disabled`.", | ||
}, | ||
"resources": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The set of resources that this agent is tagged with (if agent is not an elastic agent).", | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"environments": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The set of environments that this agent belongs to.", | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: false, | ||
Description: "The IP address of the agent.", | ||
}, | ||
"operating_system": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: false, | ||
Description: "The operating system as reported by the agent.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAgentConfigCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
if !d.IsNewResource() { | ||
return nil | ||
} | ||
|
||
id := d.Id() | ||
|
||
if len(id) == 0 { | ||
resourceID := utils.String(d.Get(utils.TerraformResourceUUID)) | ||
id = resourceID | ||
} | ||
|
||
cfg := gocd.Agent{ | ||
ID: id, | ||
Name: utils.String(d.Get(utils.TerraformResourceHostname)), | ||
Environments: utils.GetSlice(d.Get(utils.TerraformResourceEnvironments).([]interface{})), | ||
Resources: utils.GetSlice(d.Get(utils.TerraformResourceResources).([]interface{})), | ||
ConfigState: utils.String(d.Get(utils.TerraformResourceAgentConfigState)), | ||
} | ||
|
||
if err := defaultConfig.UpdateAgent(cfg); err != nil { | ||
return diag.Errorf("updating agent '%s' errored with %v", id, err) | ||
} | ||
|
||
d.SetId(id) | ||
|
||
return resourceAgentConfigRead(ctx, d, meta) | ||
} | ||
|
||
func resourceAgentConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
response, err := defaultConfig.GetAgent(d.Id()) | ||
if err != nil { | ||
return diag.Errorf("fetching information of agent '%s' errored with %v", d.Id(), err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceIPAddress, response.IPAddress); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, utils.TerraformResourceIPAddress, err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceOperatingSystem, response.OS); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, utils.TerraformResourceOperatingSystem, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAgentConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
id := d.Id() | ||
if len(d.Id()) == 0 { | ||
return diag.Errorf("resource with the ID '%s' not found", id) | ||
} | ||
|
||
d.SetId("") | ||
|
||
return nil | ||
} |
6 changes: 3 additions & 3 deletions
6
templates/data-sources/agent_config.md.tmpl → templates/data-sources/agent.md.tmpl
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,44 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gocd_agent Resource - terraform-provider-gocd" | ||
subcategory: "" | ||
description: |- | ||
|
||
--- | ||
|
||
# gocd_agent (Resource) | ||
Update configuration of a specified agent by interacting with GoCD [api](https://api.gocd.org/current/#update-an-agent). | ||
|
||
## Example Usage | ||
```terraform | ||
resource "gocd_agent" "sample_agent" { | ||
uuid = "bbfe3a75-7fd8-48db-af32-0a91b9efd0ab" | ||
agent_config_state = "ENABLED" | ||
environments = ["sample_environment_3"] | ||
resources = ["linux"] | ||
hostname = "sample.agent001.com" | ||
} | ||
``` | ||
**NOTE:** Since this resource updates the agent config, `terraform destroy` of this would just remove its reference from state and does not delete the agent itself. | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `uuid` (String) The identifier of this agent. | ||
|
||
### Optional | ||
|
||
- `agent_config_state` (String) Whether an agent is enabled or not. Can be one of `Enabled`, `Disabled`. | ||
- `environments` (List of String) The set of environments that this agent belongs to. | ||
- `hostname` (String) The hostname of the agent. | ||
- `ip_address` (String) The IP address of the agent. | ||
- `operating_system` (String) The operating system as reported by the agent. | ||
- `resources` (List of String) The set of resources that this agent is tagged with (if agent is not an elastic agent). | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
|