Skip to content

Commit

Permalink
fix(shared-source): missing consumer_id
Browse files Browse the repository at this point in the history
Add consumer_id to the shared source model, this ID is what can be used
to derive the endpoint for the shared source.

Ref: LOG-20980 #213

commit-id:55406d17
  • Loading branch information
martinohansen committed Nov 13, 2024
1 parent 22ee459 commit 50afe3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/resources/shared_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ resource "mezmo_shared_source" "http" {

### Read-Only

- `consumer_id` (String) Consumer ID of the shared source.
- `id` (String) The id of the shared source.
1 change: 1 addition & 0 deletions internal/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type AccessKey struct {

type SharedSource struct {
Id string `json:"id"`
ConsumerId string `json:"consumer_id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/models/shared_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var PUSH_SOURCE_TYPES = []string{

type SharedSourceResourceModel struct {
Id StringValue `tfsdk:"id"`
ConsumerId StringValue `tfsdk:"consumer_id"`
Title StringValue `tfsdk:"title" user_config:"true"`
Description StringValue `tfsdk:"description" user_config:"true"`
Type StringValue `tfsdk:"type" user_config:"true"`
Expand All @@ -39,6 +40,10 @@ func SharedSourceResourceSchema() schema.Schema {
Description: "The id of the shared source.",
Computed: true,
},
"consumer_id": schema.StringAttribute{
Description: "Consumer ID of the shared source.",
Computed: true,
},
"title": schema.StringAttribute{
Description: "A descriptive name for the shared source.",
Required: true,
Expand Down Expand Up @@ -88,6 +93,7 @@ func SharedSourceFromModel(plan *SharedSourceResourceModel) *SharedSource {
// From an API response to a terraform model
func SharedSourceToModel(plan *SharedSourceResourceModel, source *SharedSource) {
plan.Id = NewStringValue(source.Id)
plan.ConsumerId = NewStringValue(source.ConsumerId)
plan.Title = NewStringValue(source.Title)
plan.Type = NewStringValue(source.Type)
if source.Description != "" {
Expand Down
19 changes: 11 additions & 8 deletions internal/provider/shared_source_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ func TestSharedSourceResource(t *testing.T) {
}`) + `
resource "mezmo_shared_source" "my_source" {
title = "HTTP Shared"
type = "http"
}
type = "http"
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchOutput("shared_source_key", regexp.MustCompile(`\w+`)),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "id", IDRegex),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "consumer_id", IDRegex),
StateHasExpectedValues("mezmo_shared_source.my_source", map[string]any{
"title": "HTTP Shared",
"type": "http",
Expand All @@ -44,13 +45,14 @@ func TestSharedSourceResource(t *testing.T) {
Config: GetCachedConfig(cacheKey) + `
resource "mezmo_shared_source" "my_source" {
title = "updated title"
description = "updated description"
description = "updated description"
type = "http"
}
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchOutput("shared_source_key", regexp.MustCompile(`\w+`)),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "id", IDRegex),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "consumer_id", IDRegex),
StateHasExpectedValues("mezmo_shared_source.my_source", map[string]any{
"title": "updated title",
"description": "updated description",
Expand All @@ -63,11 +65,12 @@ func TestSharedSourceResource(t *testing.T) {
resource "mezmo_shared_source" "my_source" {
title = "updated title"
type = "kinesis-firehose"
}
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchOutput("shared_source_key", regexp.MustCompile(`\w+`)),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "id", IDRegex),
resource.TestMatchResourceAttr("mezmo_shared_source.my_source", "consumer_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",
Expand Down Expand Up @@ -95,9 +98,9 @@ func TestSharedSourceResourceErrors(t *testing.T) {
Config: `
resource "mezmo_shared_source" "my_source" {
title = ""
description = ""
type = ""
}
description = ""
type = ""
}
`,
},
},
Expand Down

0 comments on commit 50afe3f

Please sign in to comment.