You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dr...@apache.org on 2017/09/26 18:28:37 UTC

[incubator-openwhisk-devtools] branch master updated: Add teraform plugin for wskdeploy tool. (#53)

This is an automated email from the ASF dual-hosted git repository.

dragos pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git


The following commit(s) were added to refs/heads/master by this push:
     new 3cfe050  Add teraform plugin for wskdeploy tool. (#53)
3cfe050 is described below

commit 3cfe050fda55b246032e696905d9b669ef950775
Author: David Liu <no...@126.com>
AuthorDate: Wed Sep 27 02:28:35 2017 +0800

    Add teraform plugin for wskdeploy tool. (#53)
    
    * Add teraform plugin for wskdeploy tool.
    * Add one simple Makefile and change code to coherent with
    latest wskdeploy package so it could build succeed.
    * Added Experimental in README.
---
 terraform-wskdeploy-plugin/.gitignore         |  9 +++++
 terraform-wskdeploy-plugin/Makefile           | 20 ++++++++++
 terraform-wskdeploy-plugin/README.md          | 49 +++++++++++++++++++++++++
 terraform-wskdeploy-plugin/main.go            | 14 +++++++
 terraform-wskdeploy-plugin/main.tf            |  4 ++
 terraform-wskdeploy-plugin/provider.go        | 11 ++++++
 terraform-wskdeploy-plugin/resource_server.go | 53 +++++++++++++++++++++++++++
 7 files changed, 160 insertions(+)

diff --git a/terraform-wskdeploy-plugin/.gitignore b/terraform-wskdeploy-plugin/.gitignore
new file mode 100644
index 0000000..0889233
--- /dev/null
+++ b/terraform-wskdeploy-plugin/.gitignore
@@ -0,0 +1,9 @@
+local.env
+*.log
+/.c9
+/snippets
+backup.sh
+actions/mhpost/node_modules
+actions/mhpost/mhpost.zip
+VCAP_SERVICES.json
+.idea
diff --git a/terraform-wskdeploy-plugin/Makefile b/terraform-wskdeploy-plugin/Makefile
new file mode 100644
index 0000000..f04038e
--- /dev/null
+++ b/terraform-wskdeploy-plugin/Makefile
@@ -0,0 +1,20 @@
+SOURCEDIR=.
+
+SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
+BINARY=terraform-provider-example
+
+VERSION=1.0.0
+
+BUILD=`git rev-parse HEAD`
+
+# Build the project
+build:deps
+	go build ${LDFLAGS} -o ${BINARY}
+
+deps:
+	@echo "Installing dependencies"
+	go get -d -t ./...
+
+LDFLAGS=-ldflags "-X main.Version=`date -u '+%Y-%m-%dT%H:%M:%S'` -X main.Build=`git rev-parse HEAD` "
+
+
diff --git a/terraform-wskdeploy-plugin/README.md b/terraform-wskdeploy-plugin/README.md
new file mode 100644
index 0000000..654a98a
--- /dev/null
+++ b/terraform-wskdeploy-plugin/README.md
@@ -0,0 +1,49 @@
+# (Experimental)Terraform Wskdeploy Plugin
+A sample app to demo how to implement Terraform Plugin. The purpose
+is to try to integrate Terraform with [wskdeploy](https://github.com/apache/incubator-openwhisk-wskdeploy)
+so in the sample main.tf, we added a sample yaml path. Change the path to your
+local wskdeploy yaml file instead.
+
+
+# How to
+This section describe how to build and run this demo app.
+
+## wskdeploy
+wskdeploy is a tool to help deploy OpenWHisk packages in a batch, this guide assume you have
+a basic idea about [OpenWhisk](https://openwhisk.org) and how wskdeploy worked.
+
+## Install Go
+For how to install go, please refer [golang web site](https://golang.org)
+
+## Install terraform.
+For how to install terraform, please refer [terraform website](https://www.terraform.io)
+
+## Clone wskdeploy repo
+Clone wskdeploy repo under your $GOPATH
+
+`git clone https://github.com/apache/incubator-openwhisk-wskdeploy.git $GOPATH/src/github.com/apache/incubator-openwhisk-wskdeploy`
+
+The wskdeloy yaml file property is defined in sample main.tf, you can change $USER and $GOPATH in the file as your
+environments, so terraform could find your local wskdeploy yaml file.
+
+## Build and run
+Run the below command to get all the dependencies:
+`go get . `
+
+Then run:
+`go build -o terraform-provider-example` to generate a plugin which
+will be invoked by terraform.
+
+You can get it directly as the terraform-provider-example bin in this repo.
+
+Then run:
+`terraform plan` to see the config details.
+
+Run command:
+`terraform apply` to deploy the manifest yaml file.
+
+# Next Steps:
+We could add more config tags and implement the code logic to support such as update, delete etc, By
+defining new terraform style tags or we could use yaml instead.
+
+
diff --git a/terraform-wskdeploy-plugin/main.go b/terraform-wskdeploy-plugin/main.go
new file mode 100644
index 0000000..5ecf31e
--- /dev/null
+++ b/terraform-wskdeploy-plugin/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+	"github.com/hashicorp/terraform/plugin"
+	"github.com/hashicorp/terraform/terraform"
+)
+
+func main() {
+	plugin.Serve(&plugin.ServeOpts{
+		ProviderFunc: func() terraform.ResourceProvider {
+			return Provider()
+		},
+	})
+}
diff --git a/terraform-wskdeploy-plugin/main.tf b/terraform-wskdeploy-plugin/main.tf
new file mode 100644
index 0000000..9046c07
--- /dev/null
+++ b/terraform-wskdeploy-plugin/main.tf
@@ -0,0 +1,4 @@
+resource "example_server" "my-server" {
+  address = "1.2.3.4"
+  wskdeploy_yaml = "/Users/$USER/$GOPATH/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/triggerrule/manifest.yml"
+}
diff --git a/terraform-wskdeploy-plugin/provider.go b/terraform-wskdeploy-plugin/provider.go
new file mode 100644
index 0000000..39d7df4
--- /dev/null
+++ b/terraform-wskdeploy-plugin/provider.go
@@ -0,0 +1,11 @@
+package main
+
+import "github.com/hashicorp/terraform/helper/schema"
+
+func Provider() *schema.Provider {
+	return &schema.Provider{
+		ResourcesMap: map[string]*schema.Resource{
+			"example_server": resourceServer(),
+		},
+	}
+}
diff --git a/terraform-wskdeploy-plugin/resource_server.go b/terraform-wskdeploy-plugin/resource_server.go
new file mode 100644
index 0000000..6898a2a
--- /dev/null
+++ b/terraform-wskdeploy-plugin/resource_server.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+	"github.com/apache/incubator-openwhisk-wskdeploy/cmd"
+    "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+	"github.com/hashicorp/terraform/helper/schema"
+	"log"
+)
+
+func resourceServer() *schema.Resource {
+	return &schema.Resource{
+		Create: resourceServerCreate,
+		Read:   resourceServerRead,
+		Update: resourceServerUpdate,
+		Delete: resourceServerDelete,
+
+		Schema: map[string]*schema.Schema{
+			"address": &schema.Schema{
+				Type:     schema.TypeString,
+				Required: true,
+			},
+			"wskdeploy_yaml": &schema.Schema{
+				Type:     schema.TypeString,
+				Required: true,
+			},
+		},
+	}
+}
+
+func resourceServerCreate(d *schema.ResourceData, m interface{}) error {
+	_ = d.Get("address").(string)
+	yaml := d.Get("wskdeploy_yaml").(string)
+	log.Printf("%s", yaml)
+    utils.Flags.ManifestPath=yaml
+	return cmd.Deploy()
+}
+
+func resourceServerRead(d *schema.ResourceData, m interface{}) error {
+
+	_ = d.Get("address").(string)
+
+	return nil
+}
+
+func resourceServerUpdate(d *schema.ResourceData, m interface{}) error {
+
+	return nil
+}
+
+func resourceServerDelete(d *schema.ResourceData, m interface{}) error {
+	d.SetId("")
+	return nil
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].