Skip to content

Commit

Permalink
Merge pull request #115 from joshbeard/changelog-type-optional
Browse files Browse the repository at this point in the history
fix: changelog 'type' is optional
  • Loading branch information
joshbeard committed Feb 14, 2024
2 parents c3dadf9 + 9f72b4c commit e5f9d4c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "readme_changelog" "example" {

- `hidden` (Boolean) Whether the changelog is hidden. This can alternatively be set using the `hidden` front matter key.
- `title` (String) __REQUIRED.__ The title of the changelog. This can alternatively be set using the `title` front matter key.
- `type` (String) __REQUIRED.__ The type of changelog. This can alternatively be set using the `type` front matter key. Valid values: added, fixed, improved, deprecated, removed
- `type` (String) The type of changelog. This can alternatively be set using the `type` front matter key. Valid values: added, fixed, improved, deprecated, removed

### Read-Only

Expand Down
27 changes: 1 addition & 26 deletions readme/changelog_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,6 @@ func (r changelogResource) ValidateConfig(
return
}
}

if data.Type.IsNull() {
// check front matter for 'type'.
typeMatter, diag := frontmatter.GetValue(ctx, data.Body.ValueString(), "Type")
if diag != "" {
resp.Diagnostics.AddAttributeError(
path.Root("type"),
"Error checking front matter during validation.",
diag,
)

return
}

// Fail if type is not set in front matter or the attribute.
if typeMatter == (reflect.Value{}) {
resp.Diagnostics.AddAttributeError(
path.Root("type"),
"Missing required attribute.",
"'type' must be set using the attribute or in the body front matter.",
)

return
}
}
}

// Create creates the changelog and sets the initial Terraform state.
Expand Down Expand Up @@ -417,7 +392,7 @@ func (r *changelogResource) Schema(_ context.Context, _ resource.SchemaRequest,
},
},
"type": schema.StringAttribute{
Description: "__REQUIRED.__ The type of changelog. This can alternatively be set using the `type` front matter key. " +
Description: "The type of changelog. This can alternatively be set using the `type` front matter key. " +
"Valid values: added, fixed, improved, deprecated, removed",
Computed: true,
Optional: true,
Expand Down

0 comments on commit e5f9d4c

Please sign in to comment.