-
-
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 resource and datasource gocd_artifact_store
- Loading branch information
1 parent
b5bc088
commit 1d72037
Showing
11 changed files
with
453 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gocd_artifact_store Data Source - terraform-provider-gocd" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# gocd_artifact_store (Data Source) | ||
Fetch the details of the specified artifact store by interacting with GET artifact store [api](https://api.gocd.org/current/#get-an-artifact-store). | ||
|
||
## Example Usage | ||
```terraform | ||
data "gocd_artifact_store" "docker" { | ||
store_id = gocd_artifact_store.docker.id | ||
} | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `store_id` (String) The identifier of the artifact store. | ||
|
||
### Optional | ||
|
||
- `etag` (String) Etag used to track an artifact store | ||
- `plugin_id` (String) The plugin identifier of the artifact plugin. | ||
- `properties` (Block List) The list of configuration properties that represent the configuration of this artifact store. (see [below for nested schema](#nestedblock--properties)) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedblock--properties"></a> | ||
### Nested Schema for `properties` | ||
|
||
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 | ||
|
||
|
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,56 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "gocd_artifact_store Resource - terraform-provider-gocd" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# gocd_artifact_store (Resource) | ||
Creates artifact store in GoCD with all below passed parameters by interacting with GoCD artifact store [api](https://api.gocd.org/current/#create-an-artifact-store). | ||
|
||
## Example Usage | ||
```terraform | ||
resource "gocd_artifact_store" "docker" { | ||
store_id = "docker" | ||
plugin_id = "cd.go.artifact.s3" | ||
properties { | ||
key = "S3Bucket" | ||
value = "sample" | ||
} | ||
properties { | ||
key = "Region" | ||
value = "ap-south-1" | ||
} | ||
} | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `plugin_id` (String) The plugin identifier of the artifact plugin. | ||
- `properties` (Block Set, Min: 1) The list of configuration properties that represent the configuration of the profile. (see [below for nested schema](#nestedblock--properties)) | ||
- `store_id` (String) The identifier of the artifact store. | ||
|
||
### Read-Only | ||
|
||
- `etag` (String) etag used to track the plugin settings | ||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedblock--properties"></a> | ||
### Nested Schema for `properties` | ||
|
||
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 | ||
|
||
|
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,16 @@ | ||
resource "gocd_artifact_store" "docker" { | ||
store_id = "docker" | ||
plugin_id = "cd.go.artifact.s3" | ||
properties { | ||
key = "S3Bucket" | ||
value = "sample" | ||
} | ||
properties { | ||
key = "Region" | ||
value = "ap-south-1" | ||
} | ||
} | ||
|
||
data "gocd_artifact_store" "docker" { | ||
store_id = gocd_artifact_store.docker.id | ||
} |
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,83 @@ | ||
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 dataSourceArtifactStore() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceArtifactStoreRead, | ||
Schema: map[string]*schema.Schema{ | ||
"store_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The identifier of the artifact store.", | ||
}, | ||
"plugin_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The plugin identifier of the artifact plugin.", | ||
}, | ||
"properties": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The list of configuration properties that represent the configuration of this artifact store.", | ||
Elem: propertiesSchemaData(), | ||
}, | ||
"etag": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Etag used to track an artifact store", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceArtifactStoreRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
id := d.Id() | ||
|
||
if len(id) == 0 { | ||
resourceID := utils.String(d.Get(utils.TerraformResourceStoreID)) | ||
id = resourceID | ||
} | ||
|
||
response, err := defaultConfig.GetArtifactStore(id) | ||
if err != nil { | ||
return diag.Errorf("getting artifact store '%s' errored with: %v", id, err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourcePluginID, response.PluginID); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, err, utils.TerraformResourcePluginID) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceEtag, response.ETAG); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, utils.TerraformResourceEtag, err) | ||
} | ||
|
||
flattenedProperties, err := utils.MapSlice(response.Properties) | ||
if err != nil { | ||
d.SetId("") | ||
|
||
return diag.Errorf("errored while flattening artifact store properties obtained: %v", err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceProperties, flattenedProperties); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, err, utils.TerraformResourceProperties) | ||
} | ||
|
||
d.SetId(id) | ||
|
||
return nil | ||
} |
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,134 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"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 resourceArtifactStore() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceArtifactStoreCreate, | ||
ReadContext: resourceArtifactStoreRead, | ||
DeleteContext: resourceArtifactStoreDelete, | ||
UpdateContext: resourceArtifactStoreUpdate, | ||
Schema: map[string]*schema.Schema{ | ||
"store_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The identifier of the artifact store.", | ||
}, | ||
"plugin_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Computed: false, | ||
ForceNew: true, | ||
Description: "The plugin identifier of the artifact plugin.", | ||
}, | ||
"properties": propertiesSchemaResource(), | ||
"etag": { | ||
Type: schema.TypeString, | ||
Required: false, | ||
Computed: true, | ||
ForceNew: false, | ||
Description: "etag used to track the plugin settings", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArtifactStoreCreate(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.TerraformResourceStoreID)) | ||
id = resourceID | ||
} | ||
|
||
cfg := gocd.CommonConfig{ | ||
ID: id, | ||
PluginID: utils.String(d.Get(utils.TerraformResourcePluginID)), | ||
Properties: getPluginConfiguration(d.Get(utils.TerraformResourceProperties)), | ||
} | ||
|
||
_, err := defaultConfig.CreateArtifactStore(cfg) | ||
if err != nil { | ||
return diag.Errorf("creating artifact store '%s' for plugin '%s' errored with %v", cfg.ID, cfg.PluginID, err) | ||
} | ||
|
||
d.SetId(id) | ||
|
||
return resourceArtifactStoreRead(ctx, d, meta) | ||
} | ||
|
||
func resourceArtifactStoreRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
storeID := utils.String(d.Get(utils.TerraformResourceStoreID)) | ||
response, err := defaultConfig.GetArtifactStore(storeID) | ||
if err != nil { | ||
return diag.Errorf("getting artifact store configuration '%s' errored with: %v", storeID, err) | ||
} | ||
|
||
if err = d.Set(utils.TerraformResourceEtag, response.ETAG); err != nil { | ||
return diag.Errorf(settingAttrErrorTmp, utils.TerraformResourceEtag, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceArtifactStoreUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
if !d.HasChange(utils.TerraformResourceProperties) { | ||
log.Printf("nothing to update so skipping") | ||
|
||
return nil | ||
} | ||
|
||
cfg := gocd.CommonConfig{ | ||
ID: utils.String(d.Get(utils.TerraformResourceStoreID)), | ||
PluginID: utils.String(d.Get(utils.TerraformResourcePluginID)), | ||
Properties: getPluginConfiguration(d.Get(utils.TerraformResourceProperties)), | ||
ETAG: utils.String(d.Get(utils.TerraformResourceEtag)), | ||
} | ||
|
||
_, err := defaultConfig.UpdateArtifactStore(cfg) | ||
if err != nil { | ||
return diag.Errorf("updating artifact store config '%s' errored with: %v", cfg.ID, err) | ||
} | ||
|
||
return resourceArtifactStoreRead(ctx, d, meta) | ||
} | ||
|
||
func resourceArtifactStoreDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
defaultConfig := meta.(gocd.GoCd) | ||
|
||
id := d.Id() | ||
if len(d.Id()) == 0 { | ||
return diag.Errorf("resource with the ID '%s' not found", id) | ||
} | ||
|
||
storeID := utils.String(d.Get(utils.TerraformResourceStoreID)) | ||
|
||
err := defaultConfig.DeleteArtifactStore(storeID) | ||
if err != nil { | ||
return diag.Errorf("deleting artifact store '%s' errored with: %v", storeID, err) | ||
} | ||
|
||
d.SetId("") | ||
|
||
return nil | ||
} |
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.