Skip to content

Commit

Permalink
Add datasource plugin_setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Jan 28, 2023
1 parent f10e589 commit c4fc230
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 6 deletions.
41 changes: 41 additions & 0 deletions docs/data-sources/plugin_setting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd_plugin_setting Data Source - terraform-provider-gocd"
subcategory: ""
description: |-
---

# gocd_plugin_setting (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `configuration` (Block List) List of configuration required to configure the plugin settings. (see [below for nested schema](#nestedblock--configuration))
- `etag` (String) Etag used to track the cluster profile
- `plugin_id` (String) The plugin identifier of the cluster profile.

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--configuration"></a>
### Nested Schema for `configuration`

Required:

- `key` (String) the name of the property key.

Optional:

- `encrypted_value` (String) The encrypted value of the property
- `is_secure` (Boolean) Specify whether the given property is secure or not. If true and encrypted_value is not specified, GoCD will store the value in encrypted format.
- `value` (String) The value of the property


4 changes: 4 additions & 0 deletions examples/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ output "sample_environment" {

output "sample_ec2" {
value = data.gocd_elastic_agent_profile.sample_ec2.properties
}

output "yaml_plugin_settings" {
value = data.gocd_plugin_setting.yaml_plugin_settings.configuration
}
10 changes: 7 additions & 3 deletions examples/yaml_plugins_setttings.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//resource "gocd_plugin_setting" "yaml_plugin_settings" {
// plugin_id = "yaml.config.plugin"
// plugin_configurations {
// key = "file_pattern"
// key = "file_pattern"
// value = "*.gocd.yaml"
// }
// plugin_configurations {
// key = "file_pattern"
// key = "file_pattern"
// value = "*.gocd.yam"
// }
//}
//}

data "gocd_plugin_setting" "yaml_plugin_settings" {
plugin_id = "yaml.config.plugin"
}
76 changes: 76 additions & 0 deletions internal/provider/data_plugin_setting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package provider

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"
)

func dataSourcePluginsSetting() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePluginsSettingRead,
Schema: map[string]*schema.Schema{
"plugin_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Required: false,
Description: "The plugin identifier of the cluster profile.",
},
"configuration": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "List of configuration required to configure the plugin settings.",
Elem: propertiesSchemaData(),
},
"etag": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Etag used to track the cluster profile",
},
},
}
}

func dataSourcePluginsSettingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
defaultConfig := meta.(gocd.GoCd)

id := d.Id()

if len(id) == 0 {
newID, err := utils.GetRandomID()
if err != nil {
d.SetId("")

return diag.Errorf("errored while fetching randomID %v", err)
}
id = newID
}

pluginID := utils.String(d.Get(utils.TerraformPluginID))

response, err := defaultConfig.GetPluginSettings(pluginID)
if err != nil {
return diag.Errorf("getting cluster profile %s errored with: %v", pluginID, err)
}

flattenedConfiguration, err := utils.MapSlice(response.Configuration)
if err != nil {
d.SetId("")

return diag.Errorf("errored while flattening Configuration obtained: %v", err)
}

if err = d.Set(utils.TerraformResourceConfiguration, flattenedConfiguration); err != nil {
return diag.Errorf("setting '%s' errored with %v", err, utils.TerraformResourceConfiguration)
}

d.SetId(id)

return nil
}
7 changes: 4 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ func Provider() *schema.Provider {
"gocd_cluster_profile": resourceClusterProfile(),
"gocd_elastic_agent_profile": resourceElasticAgentProfile(),
"gocd_config_repository": resourceConfigRepository(),
"gocd_encrypt_value": resourceEncryptValue(),
"gocd_environment": resourceEnvironment(),
"gocd_encrypt_value": resourceEncryptValue(),
},

DataSourcesMap: map[string]*schema.Resource{
"gocd_config_repository": dataSourceConfigRepository(),
"gocd_plugin_setting": dataSourcePluginsSetting(),
"gocd_auth_config": datasourceAuthConfig(),
"gocd_cluster_profile": datasourceClusterProfile(),
"gocd_elastic_agent_profile": datasourceElasticAgentProfile(),
"gocd_auth_config": datasourceAuthConfig(),
"gocd_config_repository": dataSourceConfigRepository(),
"gocd_environment": datasourceEnvironment(),
},

Expand Down

0 comments on commit c4fc230

Please sign in to comment.