Skip to content

Commit

Permalink
feat: migrate user resource to tf framework (#796)
Browse files Browse the repository at this point in the history
* wip user resource

* User resource with create

* wip read

* wip test

* Update test to use new get function

* Fixes and remove old test

* Working user resource in framework, remove SDK version

* Docs updates

* Remove old schema and update docs again

* Docs again

* fix test

* is_active doesn't actually do anything

* Update docs

* Revert is_active since it does do something on update

* Docs

* Update the user if they're expected to be inactive

* Try this

* Fill email address if there's a value

---------

Co-authored-by: domenicsim1 <[email protected]>
  • Loading branch information
N-lson and domenicsim1 authored Oct 13, 2024
1 parent 6c31839 commit 062ebe8
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 267 deletions.
20 changes: 10 additions & 10 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ resource "octopusdeploy_user" "example" {
### Optional

- `email_address` (String) The email address of this resource.
- `id` (String) The unique ID for this resource.
- `identity` (Block Set) (see [below for nested schema](#nestedblock--identity))
- `is_active` (Boolean)
- `is_service` (Boolean)
- `identity` (Block Set) The identities associated with the user. (see [below for nested schema](#nestedblock--identity))
- `is_active` (Boolean) Specifies whether or not the user is active.
- `is_service` (Boolean) Specifies whether or not the user is a service account.
- `password` (String, Sensitive) The password associated with this resource.

### Read-Only

- `can_password_be_edited` (Boolean)
- `is_requestor` (Boolean)
- `can_password_be_edited` (Boolean) Specifies whether or not the password can be edited.
- `id` (String) The unique ID for this resource.
- `is_requestor` (Boolean) Specifies whether or not the user is the requestor.

<a id="nestedblock--identity"></a>
### Nested Schema for `identity`

Optional:

- `claim` (Block Set) (see [below for nested schema](#nestedblock--identity--claim))
- `provider` (String)
- `claim` (Block Set) The claim associated with the identity. (see [below for nested schema](#nestedblock--identity--claim))
- `provider` (String) The identity provider.

<a id="nestedblock--identity--claim"></a>
### Nested Schema for `identity.claim`

Required:

- `is_identifying_claim` (Boolean)
- `is_identifying_claim` (Boolean) Specifies whether or not the claim is an identifying claim.
- `name` (String) The name of this resource.
- `value` (String)
- `value` (String) The value of this resource.

## Import

Expand Down
1 change: 0 additions & 1 deletion octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func Provider() *schema.Provider {
"octopusdeploy_static_worker_pool": resourceStaticWorkerPool(),
"octopusdeploy_team": resourceTeam(),
"octopusdeploy_token_account": resourceTokenAccount(),
"octopusdeploy_user": resourceUser(),
"octopusdeploy_user_role": resourceUserRole(),
},
Schema: map[string]*schema.Schema{
Expand Down
25 changes: 25 additions & 0 deletions octopusdeploy/resource_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ func testSpaceDataSource(localName string, name string, slug string) string {
}`, localName, name)
}

func testAccUserBasic(localName string, displayName string, isActive bool, isService bool, password string, username string, emailAddress string) string {
return fmt.Sprintf(`resource "octopusdeploy_user" "%s" {
display_name = "%s"
email_address = "%s"
is_active = %v
is_service = %v
password = "%s"
username = "%s"
identity {
provider = "Octopus ID"
claim {
name = "email"
is_identifying_claim = true
value = "%s"
}
claim {
name = "dn"
is_identifying_claim = false
value = "%s"
}
}
}`, localName, displayName, emailAddress, isActive, isService, password, username, emailAddress, displayName)
}

func testSpaceBasic(localName string, name string, slug string) string {
userLocalName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
userDisplayName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
Expand Down
94 changes: 0 additions & 94 deletions octopusdeploy/resource_user.go

This file was deleted.

132 changes: 0 additions & 132 deletions octopusdeploy/schema_user.go

This file was deleted.

4 changes: 2 additions & 2 deletions octopusdeploy_framework/datasource_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func (u *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
return
}

mappedUsers := []schemas.UserTypeResourceModel{}
mappedUsers := []schemas.UserTypeDatasourceModel{}
tflog.Debug(ctx, fmt.Sprintf("users returned from API: %#v", existingUsers))
for _, user := range existingUsers.Items {
mappedUsers = append(mappedUsers, schemas.MapFromUser(user))
mappedUsers = append(mappedUsers, schemas.MapToUserDatasourceModel(user))
}

util.DatasourceResultCount(ctx, "users", len(mappedUsers))
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func()
NewTenantResource,
NewTentacleCertificateResource,
NewScriptModuleResource,
NewUserResource,
}
}

Expand Down
Loading

0 comments on commit 062ebe8

Please sign in to comment.