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

feat: add creating folders feature in terraform provider #90

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
)

require (
github.com/BeyondTrust/go-client-library-passwordsafe v0.10.0
github.com/BeyondTrust/go-client-library-passwordsafe v0.11.0
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/fatih/color v1.13.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/BeyondTrust/go-client-library-passwordsafe v0.10.0 h1:dtjvXamv1KjC9NZGLWTT7Avddpj6x8DQ7lZs19CVwQk=
github.com/BeyondTrust/go-client-library-passwordsafe v0.10.0/go.mod h1:72FMrpiz1fUSiIIIAXiCzQ55Y83spsu2jl5n/Stzfks=
github.com/BeyondTrust/go-client-library-passwordsafe v0.11.0 h1:5DbzqNxfAgnp61xiwoD2+bkv0BTFI8LSiZls2sCDUoM=
github.com/BeyondTrust/go-client-library-passwordsafe v0.11.0/go.mod h1:72FMrpiz1fUSiIIIAXiCzQ55Y83spsu2jl5n/Stzfks=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
Expand Down
93 changes: 93 additions & 0 deletions provider/folders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2023 BeyondTrust. All rights reserved.
// Package Provider implements a terraform provider that can talk with Beyondtrust Secret Safe API.
package provider

import (
auth "github.com/BeyondTrust/go-client-library-passwordsafe/api/authentication"
"github.com/BeyondTrust/go-client-library-passwordsafe/api/entities"
"github.com/BeyondTrust/go-client-library-passwordsafe/api/secrets"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// resourceFolder Resource.
func resourceFolder() *schema.Resource {
return &schema.Resource{
Create: resourceFolderCreate,
Read: resourceFolderRead,
Update: resourceFolderUpdate,
Delete: resourceFolderDelete,

Schema: map[string]*schema.Schema{
"parent_folder_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"user_group_id": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
},
}

}

// Create context for resourceFolder Resource.
func resourceFolderCreate(d *schema.ResourceData, m interface{}) error {
authenticationObj := m.(*auth.AuthenticationObj)
parent_folder_name := d.Get("parent_folder_name").(string)

_, err := autenticate(d, m)
if err != nil {
return err
}

secretObj, _ := secrets.NewSecretObj(*authenticationObj, zapLogger, 5000000)

name := d.Get("name").(string)
description := d.Get("description").(string)
userGroupId := d.Get("user_group_id").(int)

folder := entities.FolderDetails{
Name: name,
Description: description,
UserGroupId: userGroupId,
}

createdFolder, err := secretObj.CreateFolderFlow(parent_folder_name, folder)

if err != nil {
return err
}

err = signOut(d, m)
if err != nil {
return err
}

d.SetId(createdFolder.Id.String())
return nil
}

// Read context for resourceFolder Resource.
func resourceFolderRead(d *schema.ResourceData, m interface{}) error {
return nil
}

// Update context for resourceFolder Resource.
func resourceFolderUpdate(d *schema.ResourceData, m interface{}) error {
return nil
}

// Delete context for resourceFolder Resource.
func resourceFolderDelete(d *schema.ResourceData, m interface{}) error {
return nil
}
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func Provider() *schema.Provider {
"passwordsafe_credential_secret": resourceCredentialSecret(),
"passwordsafe_text_secret": resourceTextSecret(),
"passwordsafe_file_secret": resourceFileSecret(),
"passwordsafe_folder": resourceFolder(),
},
DataSourcesMap: map[string]*schema.Resource{
"passwordsafe_secret": getSecretByPath(),
Expand Down
5 changes: 5 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ resource "passwordsafe_file_secret" "my_file_secret" {
file_content = file("test_secret.txt")
file_name = "my_secret.txt"
notes= "My notes"
}

resource "passwordsafe_folder" "my_folder" {
parent_folder_name = "folder1"
name= "my_new_folder_mame"
}
Loading