Skip to content

Commit

Permalink
add "content_var" resource
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmanuylov committed Jun 27, 2016
1 parent 7a8c8b6 commit b511ec5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
14 changes: 14 additions & 0 deletions content/provider_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

},
}
}
35 changes: 35 additions & 0 deletions content/resource_content_var.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b511ec5

Please sign in to comment.