Skip to content

Commit

Permalink
cached variables
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmanuylov committed Aug 23, 2017
1 parent cfc850a commit cf905f5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="v1.4"
VERSION="v1.5"

govendor sync

Expand Down
44 changes: 44 additions & 0 deletions ext/provider_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,50 @@ func Provider() terraform.ResourceProvider {
Delete: deleteRemote,
},

"ext_cached_var": {
Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
Required: true,
},
"cached": {
Type: schema.TypeString,
Computed: true,
},
"trigger": {
Type: schema.TypeString,
Optional: true,
},
},
Create: createCachedVar,
Read: readCachedVar,
Update: updateCachedVar,
Delete: deleteCachedVar,
},

"ext_cached_svar": {
Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
"cached": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"trigger": {
Type: schema.TypeString,
Optional: true,
},
},
Create: createCachedVar,
Read: readCachedVar,
Update: updateCachedVar,
Delete: deleteCachedVar,
},

},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
42 changes: 42 additions & 0 deletions ext/resource_ext_cached_var.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ext

import (
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/helper/schema"
)

func createCachedVar(resourceData *schema.ResourceData, _ interface{}) error {
id, err := uuid.GenerateUUID()
if err != nil {
return err
}

cacheValue(resourceData)

resourceData.SetId(id)

return nil
}

func readCachedVar(_ *schema.ResourceData, _ interface{}) error {
return nil
}

func updateCachedVar(resourceData *schema.ResourceData, _ interface{}) error {
if resourceData.HasChange("trigger") {
cacheValue(resourceData)
}

return nil
}

func deleteCachedVar(resourceData *schema.ResourceData, _ interface{}) error {
resourceData.SetId("")
resourceData.Set("cached", "")

return nil
}

func cacheValue(resourceData *schema.ResourceData) {
resourceData.Set("cached", resourceData.Get("value"))
}

0 comments on commit cf905f5

Please sign in to comment.