-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: step template resource and datasource (#793)
- Loading branch information
1 parent
062ebe8
commit 337f569
Showing
10 changed files
with
1,199 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "octopusdeploy_step_template Data Source - terraform-provider-octopusdeploy" | ||
subcategory: "" | ||
description: |- | ||
Provides information about existing step_template. | ||
--- | ||
|
||
# octopusdeploy_step_template (Data Source) | ||
|
||
Provides information about existing step_template. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `id` (String) Unique identifier of the step template | ||
|
||
### Optional | ||
|
||
- `space_id` (String) SpaceID of the Step Template | ||
|
||
### Read-Only | ||
|
||
- `step_template` (Object) (see [below for nested schema](#nestedatt--step_template)) | ||
|
||
<a id="nestedatt--step_template"></a> | ||
### Nested Schema for `step_template` | ||
|
||
Read-Only: | ||
|
||
- `action_type` (String) | ||
- `community_action_template_id` (String) | ||
- `description` (String) | ||
- `id` (String) | ||
- `name` (String) | ||
- `packages` (List of Object) (see [below for nested schema](#nestedobjatt--step_template--packages)) | ||
- `parameters` (List of Object) (see [below for nested schema](#nestedobjatt--step_template--parameters)) | ||
- `properties` (Map of String) | ||
- `space_id` (String) | ||
- `step_package_id` (String) | ||
- `version` (Number) | ||
|
||
<a id="nestedobjatt--step_template--packages"></a> | ||
### Nested Schema for `step_template.packages` | ||
|
||
Read-Only: | ||
|
||
- `acquisition_location` (String) | ||
- `feed_id` (String) | ||
- `id` (String) | ||
- `name` (String) | ||
- `package_id` (String) | ||
- `properties` (Object) (see [below for nested schema](#nestedobjatt--step_template--packages--properties)) | ||
|
||
<a id="nestedobjatt--step_template--packages--properties"></a> | ||
### Nested Schema for `step_template.packages.properties` | ||
|
||
Read-Only: | ||
|
||
- `extract` (String) | ||
- `package_parameter_name` (String) | ||
- `purpose` (String) | ||
- `selection_mode` (String) | ||
|
||
|
||
|
||
<a id="nestedobjatt--step_template--parameters"></a> | ||
### Nested Schema for `step_template.parameters` | ||
|
||
Read-Only: | ||
|
||
- `default_value` (String) | ||
- `display_settings` (Map of String) | ||
- `help_text` (String) | ||
- `id` (String) | ||
- `label` (String) | ||
- `name` (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "octopusdeploy_step_template Resource - terraform-provider-octopusdeploy" | ||
subcategory: "" | ||
description: |- | ||
This resource manages step_templates in Octopus Deploy. | ||
--- | ||
|
||
# octopusdeploy_step_template (Resource) | ||
|
||
This resource manages step_templates in Octopus Deploy. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `action_type` (String) The action type of the step template | ||
- `name` (String) The name of this resource. | ||
- `packages` (Attributes List) Package information for the step template (see [below for nested schema](#nestedatt--packages)) | ||
- `parameters` (Attributes List) List of parameters that can be used in Step Template. (see [below for nested schema](#nestedatt--parameters)) | ||
- `properties` (Map of String) Properties for the step template | ||
- `step_package_id` (String) The ID of the step package | ||
|
||
### Optional | ||
|
||
- `community_action_template_id` (String) The ID of the community action template | ||
- `description` (String) The description of this step_template. | ||
- `space_id` (String) The space ID associated with this step_template. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The unique ID for this resource. | ||
- `version` (Number) The version of the step template | ||
|
||
<a id="nestedatt--packages"></a> | ||
### Nested Schema for `packages` | ||
|
||
Required: | ||
|
||
- `feed_id` (String) ID of the feed. | ||
- `name` (String) The name of this resource. | ||
- `properties` (Attributes) Properties for the package. (see [below for nested schema](#nestedatt--packages--properties)) | ||
|
||
Optional: | ||
|
||
- `acquisition_location` (String) Acquisition location for the package. | ||
- `package_id` (String) The ID of the package to use. | ||
|
||
Read-Only: | ||
|
||
- `id` (String) The unique ID for this resource. | ||
|
||
<a id="nestedatt--packages--properties"></a> | ||
### Nested Schema for `packages.properties` | ||
|
||
Required: | ||
|
||
- `selection_mode` (String) The selection mode. | ||
|
||
Optional: | ||
|
||
- `extract` (String) If the package should extract. | ||
- `package_parameter_name` (String) The name of the package parameter | ||
- `purpose` (String) The purpose of this property. | ||
|
||
|
||
|
||
<a id="nestedatt--parameters"></a> | ||
### Nested Schema for `parameters` | ||
|
||
Required: | ||
|
||
- `id` (String) The id for the property. | ||
- `name` (String) The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName` | ||
|
||
Optional: | ||
|
||
- `default_value` (String) A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference. | ||
- `display_settings` (Map of String) The display settings for the parameter. | ||
- `help_text` (String) The help presented alongside the parameter input. | ||
- `label` (String) The label shown beside the parameter when presented in the deployment process. Example: `Server name`. | ||
|
||
|
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,116 @@ | ||
package octopusdeploy_framework | ||
|
||
import ( | ||
"context" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/actiontemplates" | ||
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" | ||
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type stepTemplateDataSource struct { | ||
*Config | ||
} | ||
|
||
func NewStepTemplateDataSource() datasource.DataSource { | ||
return &stepTemplateDataSource{} | ||
} | ||
func (*stepTemplateDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = util.GetTypeName("step_template") | ||
} | ||
|
||
func (*stepTemplateDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schemas.StepTemplateSchema{}.GetDatasourceSchema() | ||
} | ||
|
||
func (d *stepTemplateDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
d.Config = DataSourceConfiguration(req, resp) | ||
} | ||
|
||
func (d *stepTemplateDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var err error | ||
var data schemas.StepTemplateTypeDataSourceModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
query := struct { | ||
ID string | ||
SpaceID string | ||
}{data.ID.ValueString(), data.SpaceID.ValueString()} | ||
|
||
util.DatasourceReading(ctx, "step_template", query) | ||
|
||
actionTemplate, err := actiontemplates.GetByID(d.Config.Client, query.SpaceID, query.ID) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Unable to load step template", err.Error()) | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(mapStepTemplateToDatasourceModel(&data, actionTemplate)...) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func mapStepTemplateToDatasourceModel(data *schemas.StepTemplateTypeDataSourceModel, at *actiontemplates.ActionTemplate) diag.Diagnostics { | ||
resp := diag.Diagnostics{} | ||
|
||
data.ID = types.StringValue(at.ID) | ||
data.SpaceID = types.StringValue(at.SpaceID) | ||
stepTemplate, dg := convertStepTemplateAttributes(at) | ||
resp.Append(dg...) | ||
data.StepTemplate = stepTemplate | ||
return resp | ||
} | ||
|
||
func convertStepTemplateAttributes(at *actiontemplates.ActionTemplate) (types.Object, diag.Diagnostics) { | ||
diags := diag.Diagnostics{} | ||
|
||
params := make([]attr.Value, len(at.Parameters)) | ||
for i, param := range at.Parameters { | ||
p, dg := convertStepTemplateParameterAttribute(param) | ||
diags.Append(dg...) | ||
params[i] = p | ||
} | ||
paramsListValue, dg := types.ListValue(types.ObjectType{AttrTypes: schemas.GetStepTemplateParameterTypeAttributes()}, params) | ||
diags.Append(dg...) | ||
|
||
pkgs := make([]attr.Value, len(at.Packages)) | ||
for i, pkg := range at.Packages { | ||
p, dg := convertStepTemplatePackageAttribute(pkg) | ||
diags.Append(dg...) | ||
pkgs[i] = p | ||
} | ||
packageListValue, dg := types.ListValue(types.ObjectType{AttrTypes: schemas.GetStepTemplatePackageTypeAttributes()}, pkgs) | ||
diags.Append(dg...) | ||
|
||
props := make(map[string]attr.Value, len(at.Properties)) | ||
for key, val := range at.Properties { | ||
props[key] = types.StringValue(val.Value) | ||
} | ||
propertiesMap, dg := types.MapValue(types.StringType, props) | ||
diags.Append(dg...) | ||
|
||
if diags.HasError() { | ||
return types.ObjectNull(schemas.GetStepTemplateParameterTypeAttributes()), diags | ||
} | ||
|
||
stepTemplate, dg := types.ObjectValue(schemas.GetStepTemplateAttributes(), map[string]attr.Value{ | ||
"id": types.StringValue(at.ID), | ||
"name": types.StringValue(at.Name), | ||
"description": types.StringValue(at.Description), | ||
"space_id": types.StringValue(at.SpaceID), | ||
"version": types.Int32Value(at.Version), | ||
"step_package_id": types.StringValue(at.ActionType), | ||
"action_type": types.StringValue(at.ActionType), | ||
"community_action_template_id": types.StringValue(at.CommunityActionTemplateID), | ||
"packages": packageListValue, | ||
"parameters": paramsListValue, | ||
"properties": propertiesMap, | ||
}) | ||
diags.Append(dg...) | ||
return stepTemplate, diags | ||
} |
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.