From b511ec597cd25c8bd123ef773174bb2eaf69786f Mon Sep 17 00:00:00 2001 From: "maxim.manuylov" Date: Tue, 28 Jun 2016 02:11:50 +0300 Subject: [PATCH] add "content_var" resource --- README.md | 21 +++++++++++++++----- content/provider_content.go | 14 +++++++++++++ content/resource_content_var.go | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 content/resource_content_var.go diff --git a/README.md b/README.md index 836851c..0dfd5bb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Terraform Content Provider -This is a plugin for HashiCorp [Terraform](https://terraform.io), which helps fetching some content from a remote URL and save it (or another content) locally to a file. +This is a plugin for HashiCorp [Terraform](https://terraform.io), which helps fetching some content from a remote URL, saving it (or another content) locally to a file, reusing variables with interpolated values. ## Usage @@ -12,8 +12,12 @@ resource "content_by_url" "readme" { url = "https://raw.githubusercontent.com/maxmanuylov/terraform-provider-content/master/README.md" } +resource "content_var" "readme_storage_path" { + value = "${path.root}/readme_storage" +} + resource "content_dir" "readme_storage" { - path = "${path.root}/readme_storage" + path = "${content_var.readme_storage_path.value}" permissions = "777" } @@ -37,7 +41,7 @@ Fetches content from the specified URL and provides it as a computed attribute. ### Mandatory Parameters - `url` - content URL to fetch -## Computed Parameters +### Computed Parameters - `content` - fetched content ## The "content_dir" resource type @@ -50,7 +54,7 @@ Manages (creates/removes/recreates) the local directory by the specified path. A ### Optional Parameters - `permissions` - string with octal directory permissions (e.g. "644") -## Computed Parameters +### Computed Parameters - `dir` - equal to `path` but is set _after_ the directory is created (so you can depend on this resource and be sure the directory already exists by the time you use it) ## The "content_file" resource type @@ -64,5 +68,12 @@ Saves the specified content to the local file. ### Optional Parameters - `permissions` - string with octal file permissions (e.g. "644") -## Computed Parameters +### Computed Parameters - `file` - equal to `path` but is set _after_ the file is written (so you can depend on this resource and be sure the file already exists by the time you use it) + +## The "content_var" resource type + +Provides simple named variable. Unlike the built-in Terraform variables these variables can have interpolations in its values. + +### Mandatory Parameters +- `value` - variable value diff --git a/content/provider_content.go b/content/provider_content.go index ec983e6..4944875 100644 --- a/content/provider_content.go +++ b/content/provider_content.go @@ -78,6 +78,20 @@ func Provider() terraform.ResourceProvider { Exists: contentFileExists, }, + "content_var": { + Schema: map[string]*schema.Schema{ + "value": { + Type: schema.TypeString, + Required: true, + }, + }, + Create: createContentVar, + Read: readContentVar, + Update: updateContentVar, + Delete: deleteContentVar, + Exists: contentVarExists, + }, + }, } } diff --git a/content/resource_content_var.go b/content/resource_content_var.go new file mode 100644 index 0000000..e8b4cd7 --- /dev/null +++ b/content/resource_content_var.go @@ -0,0 +1,35 @@ +package content + +import ( + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/consul/vendor/github.com/hashicorp/go-uuid" +) + +func createContentVar(resourceData *schema.ResourceData, _ interface{}) error { + id, err := uuid.GenerateUUID() + if err != nil { + return err + } + + resourceData.SetId(id) + + return nil +} + +func readContentVar(_ *schema.ResourceData, _ interface{}) error { + return nil +} + +func updateContentVar(_ *schema.ResourceData, _ interface{}) error { + return nil +} + +func deleteContentVar(resourceData *schema.ResourceData, _ interface{}) error { + resourceData.SetId("") + + return nil +} + +func contentVarExists(resourceData *schema.ResourceData, _ interface{}) (bool, error) { + return resourceData.Id() != "", nil +}