-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
46 lines (39 loc) · 1011 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"os"
"github.com/DelineaXPM/terraform-provider-tss/v2/delinea"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
)
func main() {
if len(os.Args) >= 2 {
action := os.Args[1]
stateFile := os.Args[2]
passphrase := os.Getenv("TFSTATE_PASSPHRASE")
if passphrase == "" {
log.Println("Passphrase not set in TFSTATE_PASSPHRASE environment variable")
return
}
switch action {
case "encrypt":
err := delinea.EncryptFile(passphrase, stateFile)
if err != nil {
log.Printf("[DEBUG] Error encrypting file: %v\n", err)
}
case "decrypt":
err := delinea.DecryptFile(passphrase, stateFile)
if err != nil {
log.Printf("[DEBUG] Error decrypting file: %v\n", err)
}
default:
log.Println("[DEBUG] Invalid action. Use 'encrypt' or 'decrypt'.")
}
return
}
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() *schema.Provider {
return delinea.Provider()
},
})
}