This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
forked from r2ronoha/terraform-provider-cfssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from wandera/onepass_note_resources
Add onepass note resource and datasource
- Loading branch information
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cfssl | ||
|
||
import "github.com/hashicorp/terraform/helper/schema" | ||
|
||
func dataSourceItemSecureNote() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: resourceItemSecureNoteRead, | ||
Schema: resourceItemSecureNote().Schema, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cfssl | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceItemSecureNote() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: resourceItemSecureNoteRead, | ||
Create: resourceItemSecureNoteCreate, | ||
Delete: resourceItemDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
err := resourceItemSecureNoteRead(d, meta) | ||
return []*schema.ResourceData{d}, err | ||
}, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"tags": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"vault": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"notes": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceItemSecureNoteRead(d *schema.ResourceData, meta interface{}) error { | ||
m := meta.(*Meta) | ||
vaultID := d.Get("vault").(string) | ||
v, err := m.onePassClient.ReadItem(getID(d), vaultID) | ||
if err != nil { | ||
return err | ||
} | ||
if v.Template != Category2Template(SecureNoteCategory) { | ||
return errors.New("item is not from " + string(SecureNoteCategory)) | ||
} | ||
|
||
d.SetId(v.UUID) | ||
if err := d.Set("name", v.Overview.Title); err != nil { | ||
return err | ||
} | ||
if err := d.Set("tags", v.Overview.Tags); err != nil { | ||
return err | ||
} | ||
if err := d.Set("vault", v.Vault); err != nil { | ||
return err | ||
} | ||
return d.Set("notes", v.Details.Notes) | ||
} | ||
|
||
func resourceItemSecureNoteCreate(d *schema.ResourceData, meta interface{}) error { | ||
item := &Item{ | ||
Vault: d.Get("vault").(string), | ||
Template: Category2Template(SecureNoteCategory), | ||
Details: Details{ | ||
Notes: d.Get("notes").(string), | ||
}, | ||
Overview: Overview{ | ||
Title: d.Get("name").(string), | ||
}, | ||
} | ||
m := meta.(*Meta) | ||
err := m.onePassClient.CreateItem(item) | ||
if err != nil { | ||
return err | ||
} | ||
d.SetId(item.UUID) | ||
return nil | ||
} |