Merge pull request #18604 from hashicorp/svh/f-remote-backend

backend/remote: use schema max/min items options
This commit is contained in:
Sander van Harmelen 2018-08-06 21:02:07 +02:00 committed by GitHub
commit c0793c84fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 23 deletions

View File

@ -98,6 +98,8 @@ func New(services *disco.Disco) *Remote {
Type: schema.TypeSet, Type: schema.TypeSet,
Required: true, Required: true,
Description: schemaDescriptions["workspaces"], Description: schemaDescriptions["workspaces"],
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
@ -129,15 +131,8 @@ func (b *Remote) configure(ctx context.Context) error {
b.hostname = d.Get("hostname").(string) b.hostname = d.Get("hostname").(string)
b.organization = d.Get("organization").(string) b.organization = d.Get("organization").(string)
// Get the workspaces configuration. // Get and assert the workspaces configuration block.
workspaces := d.Get("workspaces").(*schema.Set) workspace := d.Get("workspaces").(*schema.Set).List()[0].(map[string]interface{})
if workspaces.Len() != 1 {
return fmt.Errorf("only one 'workspaces' block allowed")
}
// After checking that we have exactly one workspace block, we can now get
// and assert that one workspace from the set.
workspace := workspaces.List()[0].(map[string]interface{})
// Get the default workspace name and prefix. // Get the default workspace name and prefix.
b.workspace = workspace["name"].(string) b.workspace = workspace["name"].(string)

View File

@ -43,20 +43,6 @@ func TestRemote_config(t *testing.T) {
}, },
err: nil, err: nil,
}, },
"with_two_workspace_entries": {
config: map[string]interface{}{
"organization": "hashicorp",
"workspaces": []interface{}{
map[string]interface{}{
"name": "prod",
},
map[string]interface{}{
"prefix": "my-app-",
},
},
},
err: errors.New("only one 'workspaces' block allowed"),
},
"without_either_a_name_and_a_prefix": { "without_either_a_name_and_a_prefix": {
config: map[string]interface{}{ config: map[string]interface{}{
"organization": "hashicorp", "organization": "hashicorp",