From e25b455f3d72bc6441ee97901c20639097410664 Mon Sep 17 00:00:00 2001 From: Domenic Simone Date: Mon, 9 Oct 2023 12:48:38 +1100 Subject: [PATCH] feat: default space; force new on space ID change; SpaceID on accounts --- main.go | 3 ++- octopusdeploy/data_source_accounts.go | 3 ++- octopusdeploy/provider.go | 6 ++++-- octopusdeploy/schema_account_resource.go | 1 + octopusdeploy/schema_queries.go | 8 ++++++++ octopusdeploy/schema_utilities.go | 1 + 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 31b6fc294..63a681dc9 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,8 @@ func main() { flag.Parse() opts := &plugin.ServeOpts{ - ProviderFunc: octopusdeploy.Provider} + ProviderFunc: octopusdeploy.Provider, + } if debugMode { opts.Debug = true diff --git a/octopusdeploy/data_source_accounts.go b/octopusdeploy/data_source_accounts.go index 778a42efc..52acb1abb 100644 --- a/octopusdeploy/data_source_accounts.go +++ b/octopusdeploy/data_source_accounts.go @@ -27,9 +27,10 @@ func dataSourceAccountsRead(ctx context.Context, d *schema.ResourceData, m inter Skip: d.Get("skip").(int), Take: d.Get("take").(int), } + spaceID := d.Get("space_id").(string) client := m.(*client.Client) - existingAccounts, err := client.Accounts.Get(query) + existingAccounts, err := accounts.Get(client, spaceID, &query) if err != nil { return diag.FromErr(err) } diff --git a/octopusdeploy/provider.go b/octopusdeploy/provider.go index fcf2b2ae9..4299ce5ea 100644 --- a/octopusdeploy/provider.go +++ b/octopusdeploy/provider.go @@ -110,7 +110,7 @@ func Provider() *schema.Provider { }, "space_id": { Description: "The space ID to target", - Required: true, + Optional: true, Type: schema.TypeString, }, }, @@ -123,7 +123,9 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{} config := Config{ Address: d.Get("address").(string), APIKey: d.Get("api_key").(string), - SpaceID: d.Get("space_id").(string), + } + if spaceID, ok := d.GetOk("space_id"); ok { + config.SpaceID = spaceID.(string) } return config.Client() diff --git a/octopusdeploy/schema_account_resource.go b/octopusdeploy/schema_account_resource.go index 44e5432ec..5dbee9361 100644 --- a/octopusdeploy/schema_account_resource.go +++ b/octopusdeploy/schema_account_resource.go @@ -52,6 +52,7 @@ func getAccountResourceDataSchema() map[string]*schema.Schema { Type: schema.TypeList, }, "id": getDataSchemaID(), + "space_id": getQuerySpaceID(), "ids": getQueryIDs(), "partial_name": getQueryPartialName(), "skip": getQuerySkip(), diff --git a/octopusdeploy/schema_queries.go b/octopusdeploy/schema_queries.go index 8fe0a21ad..66ac87de4 100644 --- a/octopusdeploy/schema_queries.go +++ b/octopusdeploy/schema_queries.go @@ -147,6 +147,14 @@ func getQueryHealthStatuses() *schema.Schema { } } +func getQuerySpaceID() *schema.Schema { + return &schema.Schema{ + Description: "A Space ID to filter by. Will revert what is specified on the provider if not set.", + Optional: true, + Type: schema.TypeString, + } +} + func getDataSchemaID() *schema.Schema { return &schema.Schema{ Computed: true, diff --git a/octopusdeploy/schema_utilities.go b/octopusdeploy/schema_utilities.go index e37469dea..69b47ce30 100644 --- a/octopusdeploy/schema_utilities.go +++ b/octopusdeploy/schema_utilities.go @@ -289,6 +289,7 @@ func getSpaceIDSchema() *schema.Schema { Description: "The space ID associated with this resource.", Optional: true, Type: schema.TypeString, + ForceNew: true, } }