Skip to content

Commit

Permalink
feat: default space; force new on space ID change; SpaceID on accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 9, 2023
1 parent c3470b5 commit e25b455
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func main() {
flag.Parse()

opts := &plugin.ServeOpts{
ProviderFunc: octopusdeploy.Provider}
ProviderFunc: octopusdeploy.Provider,
}

if debugMode {
opts.Debug = true
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Provider() *schema.Provider {
},
"space_id": {
Description: "The space ID to target",
Required: true,
Optional: true,
Type: schema.TypeString,
},
},
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy/schema_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions octopusdeploy/schema_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy/schema_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func getSpaceIDSchema() *schema.Schema {
Description: "The space ID associated with this resource.",
Optional: true,
Type: schema.TypeString,
ForceNew: true,
}
}

Expand Down

0 comments on commit e25b455

Please sign in to comment.