Skip to content

Commit

Permalink
fix(resources): shared_source description should be optional
Browse files Browse the repository at this point in the history
The `description` field for the shared_source resource should have been
optional, not required.

Ref: LOG-20092
  • Loading branch information
darinspivey committed Jun 11, 2024
1 parent dd84ff7 commit 3299842
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
5 changes: 4 additions & 1 deletion docs/resources/shared_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ resource "mezmo_shared_source" "http" {

### Required

- `description` (String) Details describing the shared source.
- `title` (String) A descriptive name for the shared source.
- `type` (String) The type of source that should be shared. This is typically the name of the source componenet, e.g. `kinesis-firehose`. The source must be a "push source", thus pull sources cannot be shared and will result in an error.

### Optional

- `description` (String) Details describing the shared source.

### Read-Only

- `id` (String) The id of the shared source.
2 changes: 1 addition & 1 deletion internal/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type AccessKey struct {
type SharedSource struct {
Id string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
}

Expand Down
14 changes: 9 additions & 5 deletions internal/provider/models/shared_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func SharedSourceResourceSchema() schema.Schema {
},
"description": schema.StringAttribute{
Description: "Details describing the shared source.",
Required: true,
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
Expand All @@ -73,20 +73,24 @@ func SharedSourceResourceSchema() schema.Schema {
// From terraform schema/model to a struct for sending to the API
func SharedSourceFromModel(plan *SharedSourceResourceModel) *SharedSource {
source := SharedSource{
Title: plan.Title.ValueString(),
Description: plan.Description.ValueString(),
Type: plan.Type.ValueString(),
Title: plan.Title.ValueString(),
Type: plan.Type.ValueString(),
}
if !plan.Id.IsUnknown() {
source.Id = plan.Id.ValueString()
}
if !plan.Description.IsNull() {
source.Description = plan.Description.ValueString()
}
return &source
}

// From an API response to a terraform model
func SharedSourceToModel(plan *SharedSourceResourceModel, source *SharedSource) {
plan.Id = NewStringValue(source.Id)
plan.Title = NewStringValue(source.Title)
plan.Description = NewStringValue(source.Description)
plan.Type = NewStringValue(source.Type)
if source.Description != "" {
plan.Description = NewStringValue(source.Description)
}
}
12 changes: 4 additions & 8 deletions internal/provider/shared_source_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ func TestSharedSourceResource(t *testing.T) {
}`) + `
resource "mezmo_shared_source" "my_source" {
title = "HTTP Shared"
description = "This source can be shared across pipelines"
type = "http"
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchOutput("shared_source_key", regexp.MustCompile(`\w+`)),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "id", IDRegex),
StateHasExpectedValues("mezmo_shared_source.my_source", map[string]any{
"title": "HTTP Shared",
"description": "This source can be shared across pipelines",
"type": "http",
"title": "HTTP Shared",
"type": "http",
}),
),
},
Expand All @@ -64,7 +62,6 @@ func TestSharedSourceResource(t *testing.T) {
Config: GetCachedConfig(cacheKey) + `
resource "mezmo_shared_source" "my_source" {
title = "updated title"
description = "updated description"
type = "kinesis-firehose"
}
`,
Expand All @@ -73,9 +70,8 @@ func TestSharedSourceResource(t *testing.T) {
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "id", IDRegex),
resource.TestCheckResourceAttrPair("mezmo_access_key.shared", "source_id", "mezmo_shared_source.my_source", "id"),
StateHasExpectedValues("mezmo_shared_source.my_source", map[string]any{
"title": "updated title",
"description": "updated description",
"type": "kinesis-firehose",
"title": "updated title",
"type": "kinesis-firehose",
}),
),
},
Expand Down

0 comments on commit 3299842

Please sign in to comment.