Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump go-backstage to v2 #26

Merged
merged 7 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion backstage/data_source_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
25 changes: 10 additions & 15 deletions backstage/data_source_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand All @@ -28,9 +28,9 @@ type entityDataSource struct {
}

type entityDataSourceModel struct {
ID types.String `tfsdk:"id"`
Filters map[string]string `tfsdk:"filters"`
Entities []entityModel `tfsdk:"entities"`
ID types.String `tfsdk:"id"`
Filters []string `tfsdk:"filters"`
Entities []entityModel `tfsdk:"entities"`
}

type entityModel struct {
Expand Down Expand Up @@ -120,7 +120,7 @@ func (d *entityDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
"[Backstage documentation](https://backstage.io/docs/features/software-catalog/software-catalog-api#filtering).",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Computed: true, Description: descriptionEntityMetadataUID},
"filters": schema.MapAttribute{Required: true, Description: descriptionEntityFilters, ElementType: types.StringType},
"filters": schema.ListAttribute{Required: true, Description: descriptionEntityFilters, ElementType: types.StringType},
"entities": schema.ListNestedAttribute{Computed: true, Description: descriptionEntitySpec, NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"api_version": schema.StringAttribute{Computed: true, Description: descriptionEntityApiVersion},
Expand Down Expand Up @@ -180,30 +180,25 @@ func (d *entityDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

var filters = make(map[string]string)
for k, v := range state.Filters {
filters[k] = v
}

tflog.Debug(ctx, fmt.Sprintf("Getting entities %v from Backstage API", filters))
entities, response, err := d.client.Catalog.Entities.List(ctx, &backstage.ListEntityOptions{Filters: filters})
tflog.Debug(ctx, fmt.Sprintf("Getting entities %v from Backstage API", state.Filters))
entities, response, err := d.client.Catalog.Entities.List(ctx, &backstage.ListEntityOptions{Filters: state.Filters})
if err != nil {
resp.Diagnostics.AddError(
"Error reading Backstage entities",
fmt.Sprintf("Could not read Backstage entities %v: %s", filters, err.Error()),
fmt.Sprintf("Could not read Backstage entities %v: %s", state.Filters, err.Error()),
)
return
}

if response.StatusCode != http.StatusOK {
resp.Diagnostics.AddError(
"Error reading Backstage entities",
fmt.Sprintf("Could not read Backstage entities %v: %s", filters, response.Status),
fmt.Sprintf("Could not read Backstage entities %v: %s", state.Filters, response.Status),
)
return
}

state.ID = types.StringValue(fmt.Sprint(filters))
state.ID = types.StringValue(fmt.Sprint(state.Filters))

for _, e := range entities {
entity := entityModel{
Expand Down
19 changes: 10 additions & 9 deletions backstage/data_source_entities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/tdabasinskas/go-backstage/backstage"
)

func TestAccDataSourceEntities(t *testing.T) {
Expand All @@ -15,16 +14,18 @@ func TestAccDataSourceEntities(t *testing.T) {
{
Config: testAccProviderConfig + testAccDataSourceEntitiesConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.backstage_entities.test", "id", fmt.Sprint(backstage.ListEntityFilter{
"kind": "user",
"metadata.name": "janelle.dawe",
resource.TestCheckResourceAttr("data.backstage_entities.test", "id", fmt.Sprint([]string{
"kind=user,metadata.name=janelle.dawe",
"metadata.uid=b70bed0a-e955-4f93-b03f-e03f7954da99",
})),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.#", "1"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.#", "2"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.0.kind", "User"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.0.metadata.annotations.backstage.io/managed-by-location",
"url:https://github.com/backstage/backstage/tree/master/packages/catalog-model/examples/acme/team-a-group.yaml"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.0.metadata.name", "janelle.dawe"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.1.metadata.uid", "b70bed0a-e955-4f93-b03f-e03f7954da99"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.0.relations.0.target_ref", "group:default/team-a"),
resource.TestCheckResourceAttr("data.backstage_entities.test", "entities.1.relations.0.target_ref", "group:default/team-a"),
),
},
},
Expand All @@ -33,9 +34,9 @@ func TestAccDataSourceEntities(t *testing.T) {

const testAccDataSourceEntitiesConfig = `
data "backstage_entities" "test" {
filters = {
"kind" = "user",
"metadata.name" = "janelle.dawe",
}
filters = [
"kind=user,metadata.name=janelle.dawe",
"metadata.uid=b70bed0a-e955-4f93-b03f-e03f7954da99",
]
}
`
2 changes: 1 addition & 1 deletion backstage/data_source_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/data_source_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backstage/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var _ provider.Provider = &backstageProvider{}
Expand Down
2 changes: 1 addition & 1 deletion backstage/resource_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tdabasinskas/go-backstage/backstage"
"github.com/tdabasinskas/go-backstage/v2/backstage"
)

var (
Expand Down
10 changes: 5 additions & 5 deletions docs/data-sources/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Use this data source to get a filtered list of [entities](https://backstage.io/d
# Retrieves data about multiple entities that match the given filters:
data "backstage_entities" "example" {
// The filters to apply to the query:
filters = {
"kind" = "User",
"metadata.namespace" = "default",
}
filters = [
"kind=User,metadata.namespace=default",
"kind=Group,metadata.namespace=default",
]
}
```

Expand All @@ -28,7 +28,7 @@ data "backstage_entities" "example" {

### Required

- `filters` (Map of String) A set of conditions that can be used to filter entities.
- `filters` (List of String) A set of conditions that can be used to filter entities.

### Read-Only

Expand Down
8 changes: 4 additions & 4 deletions examples/data-sources/backstage_entities/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Retrieves data about multiple entities that match the given filters:
data "backstage_entities" "example" {
// The filters to apply to the query:
filters = {
"kind" = "User",
"metadata.namespace" = "default",
}
filters = [
"kind=User,metadata.namespace=default",
"kind=Group,metadata.namespace=default",
]
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.15.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/tdabasinskas/go-backstage v1.1.1
github.com/tdabasinskas/go-backstage/v2 v2.0.0
)

require (
Expand Down
Loading