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

Add OIDC auth method and account resource #105

Merged
merged 57 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
37d8f12
build: update provider to build against Boundary 0.1.3
malnick Dec 18, 2020
28dbfc1
update deps
malnick Jan 26, 2021
6081846
Merge branch 'main' of github.com:hashicorp/terraform-provider-bounda…
malnick Mar 18, 2021
a2e1b79
add oidc configuration to authmethod resource
malnick Mar 30, 2021
283c619
break into multiple auth method resources
malnick Mar 30, 2021
99c714c
point to jimlambrt-oidc
malnick Mar 30, 2021
47963ca
update data munging functions
malnick Mar 30, 2021
d1d9cc3
update go mod
malnick Mar 30, 2021
363e82d
fix tests and start on update method
malnick Mar 31, 2021
446f1f4
rework update to include oidc type
malnick Apr 1, 2021
6630a19
make things optional
malnick Apr 6, 2021
8fa30cc
updates
malnick Apr 6, 2021
384a8d6
updates
malnick Apr 6, 2021
b89459f
fix basic validation of lists
malnick Apr 6, 2021
80695ce
update provider auth
malnick Apr 6, 2021
a101e81
fix basic create params
malnick Apr 6, 2021
16683d3
trying to fix empty secret in response
malnick Apr 7, 2021
cd07ce4
secret state
malnick Apr 7, 2021
a23a24a
ignore client_secret when verifying state
malnick Apr 8, 2021
5b0a722
use response map on update
malnick Apr 8, 2021
159a452
refresh oidc tests with complete set of attrs
malnick Apr 8, 2021
e2e8d65
not sure what is breaking with the returned ca certs and allowed aud …
malnick Apr 8, 2021
fd129ae
update to latest test branch
malnick Apr 8, 2021
dd1addb
ca certs still come back as diff
malnick Apr 9, 2021
7d6109a
point to main
malnick Apr 9, 2021
02c6e26
Merge branch 'main' into malnick-oidc
jefferai Apr 9, 2021
8253fa1
Flesh out descriptions and other cleanup
jefferai Apr 9, 2021
e8d8bec
Move oidc bits into oidc file
jefferai Apr 9, 2021
a00a5e7
Move password logic into auth method password resource
jefferai Apr 9, 2021
c04aed8
wip
jefferai Apr 9, 2021
750bdec
Fix oidc tests
jefferai Apr 9, 2021
99e5336
revert to old auth method resource
malnick Apr 10, 2021
92f63ad
update auth method base resource with attrs logic; simplify parameter…
malnick Apr 10, 2021
4126f8e
remove duplicate const
malnick Apr 10, 2021
2d45fca
add base auth method test
malnick Apr 10, 2021
9d62a8c
need to convert on response mapping
malnick Apr 10, 2021
1f97708
update tests for attr mapping
malnick Apr 11, 2021
0206cf6
issues with update
malnick Apr 11, 2021
22d3495
fix tests for auth method with attrs, add account base type
malnick Apr 11, 2021
5a48c8b
rework accounts test method signatures for password type
malnick Apr 11, 2021
00c426c
add tests for base account with attrs
malnick Apr 12, 2021
714ed2a
tests still need work
malnick Apr 12, 2021
d3923d5
add resource_account_oidc
malnick Apr 12, 2021
4e8222e
add primary auth method id to scope
malnick Apr 13, 2021
808e569
add primary for scope attr
malnick Apr 13, 2021
2ae4b57
add tests for is primary attr
malnick Apr 14, 2021
f506d14
finished tests
malnick Apr 14, 2021
7af1596
update deps
malnick Apr 14, 2021
fa3e5ec
update to main
malnick Apr 14, 2021
9a5298c
fix more deps
malnick Apr 14, 2021
0fea981
update dep
malnick Apr 14, 2021
068e42c
update status on create
malnick Apr 27, 2021
ff04f98
see if we can get the oidc "change state" to work... (#97)
jimlambrt Apr 28, 2021
97ff742
merge from main
jimlambrt Apr 29, 2021
6246357
update state before calling change state to avoid loosing state if pr…
malnick Apr 29, 2021
fdf545f
merge main
malnick May 4, 2021
5ec5f03
PR feedback
malnick May 5, 2021
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/hashicorp/boundary v0.2.0
github.com/hashicorp/boundary/api v0.0.9
github.com/hashicorp/boundary/sdk v0.0.4
github.com/hashicorp/cap v0.0.0-20210408110729-0dd65efe5473
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-kms-wrapping v0.6.1
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand Down
24 changes: 14 additions & 10 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,20 @@ func New() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"boundary_account": resourceAccount(),
"boundary_auth_method": resourceAuthMethod(),
"boundary_group": resourceGroup(),
"boundary_host": resourceHost(),
"boundary_host_catalog": resourceHostCatalog(),
"boundary_host_set": resourceHostset(),
"boundary_role": resourceRole(),
"boundary_scope": resourceScope(),
"boundary_target": resourceTarget(),
"boundary_user": resourceUser(),
"boundary_account": resourceAccount(),
"boundary_account_password": resourceAccountPassword(),
"boundary_account_oidc": resourceAccountOidc(),
"boundary_auth_method": resourceAuthMethod(),
"boundary_auth_method_password": resourceAuthMethodPassword(),
"boundary_auth_method_oidc": resourceAuthMethodOidc(),
"boundary_group": resourceGroup(),
"boundary_host": resourceHost(),
"boundary_host_catalog": resourceHostCatalog(),
"boundary_host_set": resourceHostset(),
"boundary_role": resourceRole(),
"boundary_scope": resourceScope(),
"boundary_target": resourceTarget(),
"boundary_user": resourceUser(),
},
}

Expand Down
103 changes: 23 additions & 80 deletions internal/provider/resource_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
accountTypePassword = "password"
accountLoginNameKey = "login_name"
accountPasswordKey = "password"
)

func resourceAccount() *schema.Resource {
return &schema.Resource{
Description: "The account resource allows you to configure a Boundary account.",
Expand Down Expand Up @@ -60,11 +54,14 @@ func resourceAccount() *schema.Resource {
Description: "The login name for this account.",
Type: schema.TypeString,
Optional: true,
Deprecated: "Will be removed in favor of using attributes parameter",
},
accountPasswordKey: {
Description: "The account password. Only set on create, changes will not be reflected when updating account.",
Type: schema.TypeString,
Optional: true,
Deprecated: "Will be removed in favor of using attributes parameter",

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Id() == "" {
// This is a new resource do not suppress password diff
Expand All @@ -91,6 +88,7 @@ func setFromAccountResponseMap(d *schema.ResourceData, raw map[string]interface{
return err
}

// TODO(malnick) - remove after deprecation cycle in favor of attributes
switch raw["type"].(string) {
case accountTypePassword:
jefferai marked this conversation as resolved.
Show resolved Hide resolved
if attrsVal, ok := raw["attributes"]; ok {
Expand All @@ -115,51 +113,24 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, meta int
return diag.Errorf("no auth method ID provided")
}

var loginName *string
if keyVal, ok := d.GetOk(accountLoginNameKey); ok {
key := keyVal.(string)
loginName = &key
}

var password *string
if keyVal, ok := d.GetOk(accountPasswordKey); ok {
key := keyVal.(string)
password = &key
}

opts := []accounts.Option{}

var typeStr string
if typeVal, ok := d.GetOk(TypeKey); ok {
typeStr = typeVal.(string)
} else {
return diag.Errorf("no type provided")
if nameVal, ok := d.GetOk(NameKey); ok {
opts = append(opts, accounts.WithName(nameVal.(string)))
}
switch typeStr {
case accountTypePassword:
if loginName != nil {
opts = append(opts, accounts.WithPasswordAccountLoginName(*loginName))
}
if password != nil {
opts = append(opts, accounts.WithPasswordAccountPassword(*password))
if err := d.Set(accountPasswordKey, *password); err != nil {
return diag.FromErr(err)
}
}
default:
return diag.Errorf("invalid type provided")

if descVal, ok := d.GetOk(DescriptionKey); ok {
opts = append(opts, accounts.WithDescription(descVal.(string)))
}

nameVal, ok := d.GetOk(NameKey)
if ok {
nameStr := nameVal.(string)
opts = append(opts, accounts.WithName(nameStr))
// TODO(malnick) - remove after deprecation cycle
if name, ok := d.GetOk(accountLoginNameKey); ok {
opts = append(opts, accounts.WithPasswordAccountLoginName(name.(string)))
}

descVal, ok := d.GetOk(DescriptionKey)
if ok {
descStr := descVal.(string)
opts = append(opts, accounts.WithDescription(descStr))
// TODO(malnick) - remove after deprecation cycle
if pass, ok := d.GetOk(accountPasswordKey); ok {
opts = append(opts, accounts.WithPasswordAccountPassword(pass.(string)))
}

aClient := accounts.NewClient(md.client)
Expand Down Expand Up @@ -208,66 +179,38 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, meta int

opts := []accounts.Option{}

var name *string
if d.HasChange(NameKey) {
opts = append(opts, accounts.DefaultName())
nameVal, ok := d.GetOk(NameKey)
if ok {
nameStr := nameVal.(string)
name = &nameStr
opts = append(opts, accounts.WithName(nameStr))
opts = append(opts, accounts.WithName(nameVal.(string)))
}
}

var desc *string
if d.HasChange(DescriptionKey) {
opts = append(opts, accounts.DefaultDescription())
descVal, ok := d.GetOk(DescriptionKey)
if ok {
descStr := descVal.(string)
desc = &descStr
opts = append(opts, accounts.WithDescription(descStr))
opts = append(opts, accounts.WithDescription(descVal.(string)))
}
}

var loginName *string
// TODO(malnick) - remove after deprecation cycle
if d.HasChange(accountLoginNameKey) {
switch d.Get(TypeKey).(string) {
case accountTypePassword:
opts = append(opts, accounts.DefaultPasswordAccountLoginName())
keyVal, ok := d.GetOk(accountLoginNameKey)
if ok {
keyStr := keyVal.(string)
loginName = &keyStr
opts = append(opts, accounts.WithPasswordAccountLoginName(keyStr))
}
default:
return diag.Errorf(`"login_name" cannot be used with this type of account`)
opts = append(opts, accounts.DefaultPasswordAccountLoginName())
if keyVal, ok := d.GetOk(accountLoginNameKey); ok {
opts = append(opts, accounts.WithPasswordAccountLoginName(keyVal.(string)))
}
}

if len(opts) > 0 {
opts = append(opts, accounts.WithAutomaticVersioning(true))
_, err := aClient.Update(ctx, d.Id(), 0, opts...)
aur, err := aClient.Update(ctx, d.Id(), 0, opts...)
if err != nil {
return diag.Errorf("error updating account: %v", err)
}
}

if d.HasChange(NameKey) {
if err := d.Set(NameKey, name); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange(DescriptionKey) {
if err := d.Set(DescriptionKey, desc); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange(accountLoginNameKey) {
if err := d.Set(accountLoginNameKey, loginName); err != nil {
return diag.FromErr(err)
}
setFromAccountResponseMap(d, aur.GetResponse().Map)
}

return nil
Expand Down
Loading