Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/resources/channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resource "octopusdeploy_channel" "example" {

### Optional

- `custom_field_definitions` (Attributes List) A list of custom field definitions for this channel. Maximum of 10. (see [below for nested schema](#nestedatt--custom_field_definitions))
- `description` (String) The description of this channel.
- `ephemeral_environment_name_template` (String) The name template for ephemeral environments created from this channel.
- `is_default` (Boolean) Indicates whether this is the default channel for the associated project.
Expand All @@ -43,6 +44,15 @@ resource "octopusdeploy_channel" "example" {

- `id` (String) The unique ID for this resource.

<a id="nestedatt--custom_field_definitions"></a>
### Nested Schema for `custom_field_definitions`

Required:

- `description` (String) The description of the custom field.
- `field_name` (String) The name of the custom field.


<a id="nestedblock--rule"></a>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated docs changes.

### Nested Schema for `rule`

Expand Down
46 changes: 46 additions & 0 deletions octopusdeploy_framework/resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func expandChannel(ctx context.Context, model schemas.ChannelModel) *channels.Ch
channel.Description = model.Description.ValueString()
channel.IsDefault = model.IsDefault.ValueBool()
channel.LifecycleID = model.LifecycleId.ValueString()
channel.CustomFieldDefinitions = expandChannelCustomFieldDefinitions(model.CustomFieldDefinitions)
channel.Rules = expandChannelRules(model.Rule)
channel.SpaceID = model.SpaceId.ValueString()
channel.TenantTags = util.ExpandStringSet(model.TenantTags)
Expand Down Expand Up @@ -252,6 +253,7 @@ func flattenChannel(ctx context.Context, channel *channels.Channel, model schema
model.Name = types.StringValue(channel.Name)
model.ProjectId = types.StringValue(channel.ProjectID)

model.CustomFieldDefinitions = flattenChannelCustomFieldDefinitions(channel.CustomFieldDefinitions)
model.Rule = flattenChannelRules(channel.Rules, model.Rule)

if channel.SpaceID == "" && model.SpaceId.IsNull() {
Expand Down Expand Up @@ -333,3 +335,47 @@ func getChannelRuleDeploymentActionPackageAttrTypes() map[string]attr.Type {
"package_reference": types.StringType,
}
}

func expandChannelCustomFieldDefinitions(defs types.List) []channels.ChannelCustomFieldDefinition {
if defs.IsNull() || defs.IsUnknown() || len(defs.Elements()) == 0 {
return []channels.ChannelCustomFieldDefinition{}
}

result := make([]channels.ChannelCustomFieldDefinition, 0, len(defs.Elements()))
for _, elem := range defs.Elements() {
obj := elem.(types.Object)
attrs := obj.Attributes()

var def channels.ChannelCustomFieldDefinition
if v, ok := attrs["field_name"].(types.String); ok && !v.IsNull() {
def.FieldName = v.ValueString()
}
if v, ok := attrs["description"].(types.String); ok && !v.IsNull() {
def.Description = v.ValueString()
}
result = append(result, def)
}
return result
}

func flattenChannelCustomFieldDefinitions(defs []channels.ChannelCustomFieldDefinition) types.List {
if len(defs) == 0 {
return types.ListNull(types.ObjectType{AttrTypes: getChannelCustomFieldDefinitionAttrTypes()})
}

elems := make([]attr.Value, 0, len(defs))
for _, def := range defs {
elems = append(elems, types.ObjectValueMust(getChannelCustomFieldDefinitionAttrTypes(), map[string]attr.Value{
"field_name": types.StringValue(def.FieldName),
"description": types.StringValue(def.Description),
}))
}
return types.ListValueMust(types.ObjectType{AttrTypes: getChannelCustomFieldDefinitionAttrTypes()}, elems)
}

func getChannelCustomFieldDefinitionAttrTypes() map[string]attr.Type {
return map[string]attr.Type{
"field_name": types.StringType,
"description": types.StringType,
}
}
17 changes: 17 additions & 0 deletions octopusdeploy_framework/schemas/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ChannelModel struct {
Name types.String `tfsdk:"name"`
ParentEnvironmentID types.String `tfsdk:"parent_environment_id"`
ProjectId types.String `tfsdk:"project_id"`
CustomFieldDefinitions types.List `tfsdk:"custom_field_definitions"`
Rule types.List `tfsdk:"rule"`
SpaceId types.String `tfsdk:"space_id"`
TenantTags types.Set `tfsdk:"tenant_tags"`
Expand Down Expand Up @@ -55,6 +56,22 @@ func (c ChannelSchema) GetResourceSchema() resourceSchema.Schema {
Description: "The project ID associated with this channel.",
Required: true,
},
"custom_field_definitions": resourceSchema.ListNestedAttribute{
Description: "A list of custom field definitions for this channel. Maximum of 10.",
Optional: true,
NestedObject: resourceSchema.NestedAttributeObject{
Attributes: map[string]resourceSchema.Attribute{
"field_name": resourceSchema.StringAttribute{
Required: true,
Description: "The name of the custom field.",
},
"description": resourceSchema.StringAttribute{
Required: true,
Description: "The description of the custom field.",
},
},
},
},
"space_id": GetSpaceIdResourceSchema(ChannelResourceDescription),
"tenant_tags": resourceSchema.SetAttribute{
Description: "A set of tenant tags associated with this channel.",
Expand Down
Loading