-
-
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.
Add support for datasource gocd_config_repository
- Loading branch information
1 parent
f2e5f6c
commit e921ef4
Showing
13 changed files
with
373 additions
and
15 deletions.
There are no files selected for viewing
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,78 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gocd_config_repository Data Source - terraform-provider-gocd" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# gocd_config_repository (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `profile_id` (String) The identifier of the elastic agent profile. | ||
|
||
### Optional | ||
|
||
- `configuration` (Block List) the list of configuration properties that represent the configuration of this profile. (see [below for nested schema](#nestedblock--configuration)) | ||
- `etag` (String) Etag used to track the plugin settings | ||
- `plugin_id` (String) The plugin identifier of the cluster profile. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `material` (Set of Object) The material to be used by the config repo. (see [below for nested schema](#nestedatt--material)) | ||
- `rules` (List of Object) The list of rules, which allows restricting the entities that the config repo can refer to. (see [below for nested schema](#nestedatt--rules)) | ||
|
||
<a id="nestedblock--configuration"></a> | ||
### Nested Schema for `configuration` | ||
|
||
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. | ||
- `key` (String) the name of the property key. | ||
- `value` (String) The value of the property | ||
|
||
|
||
<a id="nestedatt--material"></a> | ||
### Nested Schema for `material` | ||
|
||
Read-Only: | ||
|
||
- `attributes` (Set of Object) (see [below for nested schema](#nestedobjatt--material--attributes)) | ||
- `fingerprint` (String) | ||
- `type` (String) | ||
|
||
<a id="nestedobjatt--material--attributes"></a> | ||
### Nested Schema for `material.attributes` | ||
|
||
Read-Only: | ||
|
||
- `auto_update` (Boolean) | ||
- `branch` (String) | ||
- `encrypted_password` (String) | ||
- `password` (String) | ||
- `url` (String) | ||
- `username` (String) | ||
|
||
|
||
|
||
<a id="nestedatt--rules"></a> | ||
### Nested Schema for `rules` | ||
|
||
Read-Only: | ||
|
||
- `action` (String) | ||
- `directive` (String) | ||
- `resource` (String) | ||
- `type` (String) | ||
|
||
|
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,4 +1,8 @@ | ||
output "encrypted_value" { | ||
value = gocd_encrypt_value.new_value.encrypted_value | ||
sensitive = true | ||
} | ||
|
||
output "sample_config_repo" { | ||
value = data.gocd_config_repository.sample_config_repo.material | ||
} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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 dataSourceConfigRepository() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceConfigRepositoryRead, | ||
Schema: configRepoSchema(), | ||
} | ||
} | ||
|
||
func dataSourceConfigRepositoryRead(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 | ||
} | ||
|
||
profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) | ||
response, err := defaultConfig.GetConfigRepo(profileID) | ||
if err != nil { | ||
return diag.Errorf("getting config repo %s errored with: %v", profileID, err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformPluginID, response.PluginID); err != nil { | ||
return diag.Errorf("setting pluginID errored with %v", err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceMaterial, flattenMaterial(response.Material)); err != nil { | ||
return diag.Errorf("setting material errored with %v", 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 plugin configurations errored with %v", err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceRules, response.Rules); err != nil { | ||
return diag.Errorf("setting rules errored with %v", err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceEtag, response.ETAG); err != nil { | ||
return diag.Errorf("setting etag errored with %v", err) | ||
} | ||
|
||
d.SetId(id) | ||
|
||
return nil | ||
} | ||
|
||
func flattenMaterial(material gocd.Material) []map[string]interface{} { | ||
return []map[string]interface{}{ | ||
{ | ||
"type": material.Type, | ||
"fingerprint": material.Fingerprint, | ||
"attributes": flattenAttributes(material.Attributes), | ||
}, | ||
} | ||
} | ||
|
||
func flattenAttributes(attribute gocd.Attribute) []map[string]interface{} { | ||
return []map[string]interface{}{ | ||
{ | ||
"url": attribute.URL, | ||
"username": attribute.Username, | ||
"password": attribute.Password, | ||
"encrypted_password": attribute.EncryptedPassword, | ||
"branch": attribute.Branch, | ||
"auto_update": attribute.AutoUpdate, | ||
}, | ||
} | ||
} |
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
Oops, something went wrong.