Skip to content

Commit

Permalink
Fix schema for resource and datasource so it matches the current docs (
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn authored Aug 1, 2024
1 parent 77de86c commit 7fca508
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 64 deletions.
22 changes: 11 additions & 11 deletions docs/data-sources/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ data "octopusdeploy_variables" "example" {

- `name` (String) The name of variable to find.
- `owner_id` (String) Owner ID for the variable to find.
- `scope` (Block List, Min: 1, Max: 1) As variable names can appear more than once under different scopes, a VariableScope must also be provided (see [below for nested schema](#nestedblock--scope))

### Optional

- `scope` (Block List) As variable names can appear more than once under different scopes, a VariableScope must also be provided (see [below for nested schema](#nestedblock--scope))
- `space_id` (String) A Space ID to filter by. Will revert what is specified on the provider if not set.

### Read-Only
Expand All @@ -36,9 +36,9 @@ data "octopusdeploy_variables" "example" {
- `id` (String) The identifier of the variable to find.
- `is_editable` (Boolean) Indicates whether or not this variable is considered editable.
- `is_sensitive` (Boolean) Indicates whether or not this resource is considered sensitive and should be kept secret.
- `prompt` (List of Object) (see [below for nested schema](#nestedatt--prompt))
- `prompt` (Attributes List) (see [below for nested schema](#nestedatt--prompt))
- `sensitive_value` (String, Sensitive)
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `Certificate`, `Sensitive`, `String`, or `WorkerPool`.
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `UsernamePasswordAccount`, `Certificate`, `Sensitive`, `String`, `WorkerPool`.
- `value` (String)

<a id="nestedblock--scope"></a>
Expand All @@ -60,25 +60,25 @@ Optional:

Read-Only:

- `description` (String)
- `display_settings` (List of Object) (see [below for nested schema](#nestedobjatt--prompt--display_settings))
- `description` (String) The description of this variable prompt option.
- `display_settings` (Attributes List) (see [below for nested schema](#nestedatt--prompt--display_settings))
- `is_required` (Boolean)
- `label` (String)

<a id="nestedobjatt--prompt--display_settings"></a>
<a id="nestedatt--prompt--display_settings"></a>
### Nested Schema for `prompt.display_settings`

Read-Only:

- `control_type` (String)
- `select_option` (List of Object) (see [below for nested schema](#nestedobjatt--prompt--display_settings--select_option))
- `control_type` (String) The type of control for rendering this prompted variable. Valid types are `SingleLineText`, `MultiLineText`, `Checkbox`, `Select`.
- `select_option` (Attributes List) If the `control_type` is `Select`, then this value defines an option. (see [below for nested schema](#nestedatt--prompt--display_settings--select_option))

<a id="nestedobjatt--prompt--display_settings--select_option"></a>
<a id="nestedatt--prompt--display_settings--select_option"></a>
### Nested Schema for `prompt.display_settings.select_option`

Read-Only:

- `display_name` (String)
- `value` (String)
- `display_name` (String) The display name for the select value
- `value` (String) The select value


10 changes: 5 additions & 5 deletions docs/resources/variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ resource "octopusdeploy_variable" "prompted_variable" {
### Required

- `name` (String) The name of this resource.
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `UsernamePasswordAccount`, `Certificate`, `Sensitive`, `String`, or `WorkerPool`.
- `type` (String) The type of variable represented by this resource. Valid types are `AmazonWebServicesAccount`, `AzureAccount`, `GoogleCloudAccount`, `UsernamePasswordAccount`, `Certificate`, `Sensitive`, `String`, `WorkerPool`.

### Optional

Expand All @@ -106,10 +106,10 @@ resource "octopusdeploy_variable" "prompted_variable" {
- `owner_id` (String)
- `pgp_key` (String, Sensitive)
- `project_id` (String, Deprecated)
- `prompt` (Block List, Max: 1) (see [below for nested schema](#nestedblock--prompt))
- `scope` (Block List, Max: 1) (see [below for nested schema](#nestedblock--scope))
- `prompt` (Block List) (see [below for nested schema](#nestedblock--prompt))
- `scope` (Block List) (see [below for nested schema](#nestedblock--scope))
- `sensitive_value` (String, Sensitive)
- `space_id` (String) The space ID associated with this resource.
- `space_id` (String) The space ID associated with this variable.
- `value` (String)

### Read-Only
Expand All @@ -124,7 +124,7 @@ resource "octopusdeploy_variable" "prompted_variable" {
Optional:

- `description` (String) The description of this variable prompt option.
- `display_settings` (Block List, Max: 1) (see [below for nested schema](#nestedblock--prompt--display_settings))
- `display_settings` (Block List) (see [below for nested schema](#nestedblock--prompt--display_settings))
- `is_required` (Boolean)
- `label` (String)

Expand Down
40 changes: 21 additions & 19 deletions octopusdeploy_framework/schemas/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ var VariableTypeNames = struct {
AmazonWebServicesAccount string
AzureAccount string
GoogleCloudAccount string
UsernamePasswordAccount string
Certificate string
Sensitive string
String string
WorkerPool string
UsernamePasswordAccount string
}{
AmazonWebServicesAccount: "AmazonWebServicesAccount",
AzureAccount: "AzureAccount",
GoogleCloudAccount: "GoogleCloudAccount",
UsernamePasswordAccount: "UsernamePasswordAccount",
Certificate: "Certificate",
Sensitive: "Sensitive",
String: "String",
WorkerPool: "WorkerPool",
UsernamePasswordAccount: "UsernamePasswordAccount",
}

var VariableTypes = []string{
VariableTypeNames.AmazonWebServicesAccount,
VariableTypeNames.AzureAccount,
VariableTypeNames.GoogleCloudAccount,
VariableTypeNames.UsernamePasswordAccount,
VariableTypeNames.Certificate,
VariableTypeNames.Sensitive,
VariableTypeNames.String,
VariableTypeNames.WorkerPool,
VariableTypeNames.UsernamePasswordAccount,
}

func GetVariableDatasourceSchema() datasourceSchema.Schema {
Expand All @@ -113,19 +113,19 @@ func GetVariableDatasourceSchema() datasourceSchema.Schema {
},
SchemaAttributeNames.Description: datasourceSchema.StringAttribute{
Computed: true,
Description: "The description of this variable",
Description: "The description of this variable.",
},
VariableSchemaAttributeNames.IsEditable: datasourceSchema.BoolAttribute{
Description: "Indicates whether or not this variable is considered editable.",
Computed: true,
},
VariableSchemaAttributeNames.IsSensitive: datasourceSchema.BoolAttribute{
Description: "Indicates whether or not this resource is considered sensitive and should be kept secret.",
Computed: true,
},
VariableSchemaAttributeNames.IsEditable: GetBooleanDatasourceAttribute(
"Indicates whether or not this variable is considered editable.",
true,
),
VariableSchemaAttributeNames.IsSensitive: GetBooleanDatasourceAttribute(
"Indicates whether or not this resource is considered sensitive and should be kept secret.",
true,
),
VariableSchemaAttributeNames.Type: datasourceSchema.StringAttribute{
Computed: true,
Description: fmt.Sprintf("The type of variable represented by this resource. Valid types are %s", strings.Join(VariableTypes, ", ")),
Description: fmt.Sprintf("The type of variable represented by this resource. Valid types are %s.", strings.Join(util.Map(VariableTypes, func(item string) string { return fmt.Sprintf("`%s`", item) }), ", ")),
},
VariableSchemaAttributeNames.SensitiveValue: datasourceSchema.StringAttribute{
Computed: true,
Expand All @@ -134,18 +134,22 @@ func GetVariableDatasourceSchema() datasourceSchema.Schema {
VariableSchemaAttributeNames.Value: datasourceSchema.StringAttribute{
Computed: true,
},
VariableSchemaAttributeNames.Prompt: getVariablePromptDatasourceSchema(),
},
Blocks: map[string]datasourceSchema.Block{
VariableSchemaAttributeNames.Scope: getVariableScopeDatasourceSchema(),
VariableSchemaAttributeNames.Prompt: getVariablePromptDatasourceSchema(),
VariableSchemaAttributeNames.Scope: getVariableScopeDatasourceSchema(),
},
}
}

func GetVariableResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Description: util.GetResourceSchemaDescription(VariableResourceDescription),
Attributes: map[string]resourceSchema.Attribute{
SchemaAttributeNames.ID: GetIdResourceSchema(),
SchemaAttributeNames.ID: resourceSchema.StringAttribute{
Description: "The ID of this resource.",
Computed: true,
},
SchemaAttributeNames.Name: GetNameResourceSchema(true),
SchemaAttributeNames.Description: GetDescriptionResourceSchema(VariableResourceDescription),
SchemaAttributeNames.SpaceID: GetSpaceIdResourceSchema(VariableResourceDescription),
Expand All @@ -171,7 +175,6 @@ func GetVariableResourceSchema() resourceSchema.Schema {
false,
true),
VariableSchemaAttributeNames.KeyFingerprint: resourceSchema.StringAttribute{
Optional: true,
Computed: true,
},
VariableSchemaAttributeNames.PgpKey: resourceSchema.StringAttribute{
Expand All @@ -182,7 +185,6 @@ func GetVariableResourceSchema() resourceSchema.Schema {
},
},
VariableSchemaAttributeNames.EncryptedValue: resourceSchema.StringAttribute{
Optional: true,
Computed: true,
},
VariableSchemaAttributeNames.SensitiveValue: resourceSchema.StringAttribute{
Expand All @@ -194,7 +196,7 @@ func GetVariableResourceSchema() resourceSchema.Schema {
},
VariableSchemaAttributeNames.Type: resourceSchema.StringAttribute{
Required: true,
Description: fmt.Sprintf("The type of variable represented by this resource. Valid types are %s", strings.Join(VariableTypes, ", ")),
Description: fmt.Sprintf("The type of variable represented by this resource. Valid types are %s.", strings.Join(util.Map(VariableTypes, func(item string) string { return fmt.Sprintf("`%s`", item) }), ", ")),
Validators: []validator.String{
stringvalidator.OneOf(
VariableTypes...,
Expand Down
53 changes: 28 additions & 25 deletions octopusdeploy_framework/schemas/variable_prompt_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ var displaySettingsControlTypeNames = struct {
Select string
SingleLineText string
}{
"CheckBox",
"Checkbox",
"MultiLineText",
"Select",
"SingeLineText",
"SingleLineText",
}

var displaySettingsControlTypes = []string{
displaySettingsControlTypeNames.CheckBox,
displaySettingsControlTypeNames.SingleLineText,
displaySettingsControlTypeNames.MultiLineText,
displaySettingsControlTypeNames.CheckBox,
displaySettingsControlTypeNames.Select,
displaySettingsControlTypeNames.SingleLineText,
}

func VariablePromptOptionsObjectType() map[string]attr.Type {
Expand Down Expand Up @@ -192,17 +192,18 @@ func MapToSelectOptions(selectOptions types.List) []*resources.SelectOption {
return options
}

func getVariablePromptDatasourceSchema() datasourceSchema.ListNestedBlock {
return datasourceSchema.ListNestedBlock{
NestedObject: datasourceSchema.NestedBlockObject{
func getVariablePromptDatasourceSchema() datasourceSchema.ListNestedAttribute {
return datasourceSchema.ListNestedAttribute{
Computed: true,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
SchemaAttributeNames.Description: util.GetDescriptionDatasourceSchema("variable prompt option"),
VariableSchemaAttributeNames.DisplaySettings: getDisplaySettingsDatasourceSchema(),
VariableSchemaAttributeNames.IsRequired: datasourceSchema.BoolAttribute{
Optional: true,
Computed: true,
},
VariableSchemaAttributeNames.Label: datasourceSchema.StringAttribute{
Optional: true,
Computed: true,
},
},
},
Expand All @@ -214,12 +215,12 @@ func getVariablePromptDatasourceSchema() datasourceSchema.ListNestedBlock {

func getDisplaySettingsDatasourceSchema() datasourceSchema.ListNestedAttribute {
return datasourceSchema.ListNestedAttribute{
Optional: true,
Computed: true,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
VariableSchemaAttributeNames.ControlType: datasourceSchema.StringAttribute{
Description: fmt.Sprintf("The type of control for rendering this prompted variable. Valid types are %s", strings.Join(displaySettingsControlTypes, ", ")),
Required: true,
Description: fmt.Sprintf("The type of control for rendering this prompted variable. Valid types are %s.", strings.Join(util.Map(displaySettingsControlTypes, func(item string) string { return fmt.Sprintf("`%s`", item) }), ", ")),
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf(
displaySettingsControlTypes...,
Expand All @@ -228,16 +229,16 @@ func getDisplaySettingsDatasourceSchema() datasourceSchema.ListNestedAttribute {
},
VariableSchemaAttributeNames.SelectOption: datasourceSchema.ListNestedAttribute{
Description: fmt.Sprintf("If the `%s` is `%s`, then this value defines an option.", VariableSchemaAttributeNames.ControlType, displaySettingsControlTypeNames.Select),
Optional: true,
Computed: true,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
VariableSchemaAttributeNames.Value: datasourceSchema.StringAttribute{
Description: "The select value",
Required: true,
Computed: true,
},
VariableSchemaAttributeNames.DisplayName: datasourceSchema.StringAttribute{
Description: "The display name for the select value",
Required: true,
Computed: true,
},
},
},
Expand All @@ -254,40 +255,42 @@ func getVariablePromptResourceSchema() resourceSchema.ListNestedBlock {
return resourceSchema.ListNestedBlock{
NestedObject: resourceSchema.NestedBlockObject{
Attributes: map[string]resourceSchema.Attribute{
SchemaAttributeNames.Description: util.GetDescriptionResourceSchema("variable prompt option"),
VariableSchemaAttributeNames.DisplaySettings: getDisplaySettingsResourceSchema(),
SchemaAttributeNames.Description: util.GetDescriptionResourceSchema("variable prompt option"),
VariableSchemaAttributeNames.IsRequired: resourceSchema.BoolAttribute{
Optional: true,
},
VariableSchemaAttributeNames.Label: resourceSchema.StringAttribute{
Optional: true,
},
},
Blocks: map[string]resourceSchema.Block{
VariableSchemaAttributeNames.DisplaySettings: getDisplaySettingsResourceSchema(),
},
},
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
}
}

func getDisplaySettingsResourceSchema() resourceSchema.ListNestedAttribute {
return resourceSchema.ListNestedAttribute{
Optional: true,
NestedObject: resourceSchema.NestedAttributeObject{
func getDisplaySettingsResourceSchema() resourceSchema.ListNestedBlock {
return resourceSchema.ListNestedBlock{
NestedObject: resourceSchema.NestedBlockObject{
Attributes: map[string]resourceSchema.Attribute{
VariableSchemaAttributeNames.ControlType: resourceSchema.StringAttribute{
Description: fmt.Sprintf("The type of control for rendering this prompted variable. Valid types are %s", strings.Join(displaySettingsControlTypes, ", ")),
Description: fmt.Sprintf("The type of control for rendering this prompted variable. Valid types are %s.", strings.Join(util.Map(displaySettingsControlTypes, func(item string) string { return fmt.Sprintf("`%s`", item) }), ", ")),
Required: true,
Validators: []validator.String{
stringvalidator.OneOf(
displaySettingsControlTypes...,
),
},
},
VariableSchemaAttributeNames.SelectOption: resourceSchema.ListNestedAttribute{
},
Blocks: map[string]resourceSchema.Block{
VariableSchemaAttributeNames.SelectOption: resourceSchema.ListNestedBlock{
Description: fmt.Sprintf("If the `%s` is `%s`, then this value defines an option.", VariableSchemaAttributeNames.ControlType, displaySettingsControlTypeNames.Select),
Optional: true,
NestedObject: resourceSchema.NestedAttributeObject{
NestedObject: resourceSchema.NestedBlockObject{
Attributes: map[string]resourceSchema.Attribute{
VariableSchemaAttributeNames.Value: resourceSchema.StringAttribute{
Description: "The select value",
Expand Down
7 changes: 5 additions & 2 deletions octopusdeploy_framework/schemas/variable_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"fmt"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
Expand Down Expand Up @@ -121,14 +122,15 @@ func getVariableScopeResourceSchema() resourceSchema.ListNestedBlock {

func getVariableScopeFieldResourceSchema(scopeDescription string) resourceSchema.ListAttribute {
return resourceSchema.ListAttribute{
Description: fmt.Sprintf("A list of %s that are scoped to this variable value.", scopeDescription),
Description: fmt.Sprintf("A list of %s that are scoped to this variable value.", strings.ReplaceAll(scopeDescription, "_", " ")),
Optional: true,
ElementType: basetypes.StringType{},
}
}

func getVariableScopeDatasourceSchema() datasourceSchema.ListNestedBlock {
return datasourceSchema.ListNestedBlock{
Description: "As variable names can appear more than once under different scopes, a VariableScope must also be provided",
NestedObject: datasourceSchema.NestedBlockObject{
Attributes: map[string]datasourceSchema.Attribute{
variableScopeFieldNames.Actions: getVariableScopeFieldDatasourceSchema(variableScopeFieldNames.Actions),
Expand All @@ -141,14 +143,15 @@ func getVariableScopeDatasourceSchema() datasourceSchema.ListNestedBlock {
},
},
Validators: []validator.List{
listvalidator.IsRequired(),
listvalidator.SizeAtMost(1),
},
}
}

func getVariableScopeFieldDatasourceSchema(scopeDescription string) datasourceSchema.ListAttribute {
return datasourceSchema.ListAttribute{
Description: fmt.Sprintf("A list of %s that are scoped to this variable value.", scopeDescription),
Description: fmt.Sprintf("A list of %s that are scoped to this variable value.", strings.ReplaceAll(scopeDescription, "_", " ")),
Optional: true,
ElementType: basetypes.StringType{},
}
Expand Down
1 change: 0 additions & 1 deletion octopusdeploy_framework/util/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func GetNameDatasourceSchema(isRequired bool) datasourceSchema.Attribute {
func GetDescriptionDatasourceSchema(resourceDescription string) datasourceSchema.Attribute {
return datasourceSchema.StringAttribute{
Description: "The description of this " + resourceDescription + ".",
Optional: true,
Computed: true,
}
}
Expand Down
Loading

0 comments on commit 7fca508

Please sign in to comment.