Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform 0.12 compatibility #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
628 changes: 0 additions & 628 deletions Gopkg.lock

This file was deleted.

46 changes: 0 additions & 46 deletions Gopkg.toml

This file was deleted.

35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
[![CircleCI](https://circleci.com/gh/armory-io/terraform-provider-spinnaker/tree/master.svg?style=svg)](https://circleci.com/gh/armory-io/terraform-provider-spinnaker/tree/master)

# terraform-provider-spinnaker

Manage [Spinnaker](https://spinnaker.io) applications and pipelines with Terraform.

## Demo
## Credits

![demo](https://d2ddoduugvun08.cloudfront.net/items/1A0A1C2C1M243j0b2u16/Screen%20Recording%202018-11-23%20at%2012.18%20PM.gif)
Forked from https://github.com/armory-io/terraform-provider-spinnaker and https://github.com/yoo/terraform-provider-spinnaker

## Example

```
provider "spinnaker" {
server = "http://spinnaker-gate.myorg.io"
server = "https://spinnaker-api.finanzcheck.de"
config = pathexpand("~/.spin/config")
ignore_cert_errors = false
}

resource "spinnaker_application" "my_app" {
application = "terraformtest"
email = "ethan@armory.io"
resource "spinnaker_application" "my-application" {
application = "my-application"
email = "me@finanzcheck.de"
read_permissions = [ "team-phoenix", "team-prism" ]
write_permissions = [ "team-phoenix" ]
execute_permissions = [ "team-phoenix" ]
}

resource "spinnaker_pipeline" "terraform_example" {
application = "${spinnaker_application.my_app.application}"
name = "Example Pipeline"
pipeline = file("pipelines/example.json")
resource "spinnaker_pipeline" "deploy-shared" {
application = "${spinnaker_application.mcc.application}"
name = "Deploy shared"
pipeline = file("pipeline.json")
}
```

## Installation

#### Build from Source

_Requires Go and [Dep](https://github.com/golang/dep#installation) be installed on the system._
#### Build from Source and symlink into the terraform provider folder

```
$ go get github.com/armory-io/terraform-provider-spinnaker
$ go get github.com/finanzcheck/terraform-provider-spinnaker
$ cd $GOPATH/src/github.com/armory-io/terraform-provider-spinnaker
$ dep ensure
$ go build
```

#### Installing 3rd Party Plugins
Expand Down
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/finanzcheck/terraform-provider-spinnaker

require (
github.com/finanzcheck/terraform-provider-spinnaker v0.0.0-20190925101548-cbedc5fec311
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/terraform v0.12.0
github.com/mitchellh/mapstructure v1.1.2
github.com/spf13/pflag v1.0.3
github.com/spinnaker/spin v0.0.0-20181210191703-fe23fcc28d97
)

go 1.13
466 changes: 466 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/armory-io/terraform-provider-spinnaker/spinnaker"
"github.com/finanzcheck/terraform-provider-spinnaker/spinnaker"
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/terraform"
)
Expand Down
82 changes: 49 additions & 33 deletions spinnaker/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package spinnaker
import (
"strings"

"github.com/armory-io/terraform-provider-spinnaker/spinnaker/api"
"github.com/finanzcheck/terraform-provider-spinnaker/spinnaker/api"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)
Expand All @@ -27,13 +27,20 @@ func resourceApplication() *schema.Resource {
Default: 80,
ValidateFunc: validation.IntBetween(1, 65535),
},
"permissions": {
Type: schema.TypeMap,
"read_permissions": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"read", "write", "read_write"}, false),
},
Elem: &schema.Schema{Type: schema.TypeString},
},
"write_permissions": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"execute_permissions": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
Create: resourceApplicationCreate,
Expand Down Expand Up @@ -69,6 +76,7 @@ func resourceApplicationCreate(data *schema.ResourceData, meta interface{}) erro
client := clientConfig.client

app := applicationFromResource(data)

if err := api.CreateApplication(client, app.Name, app); err != nil {
return err
}
Expand Down Expand Up @@ -138,23 +146,26 @@ func applicationFromResource(data *schema.ResourceData) *application {
InstancePort: data.Get("instance_port").(int),
Permissions: make(map[string][]string),
}

readPermissions := make([]string, len(data.Get("read_permissions").([]interface {})))
for i, v := range data.Get("read_permissions").([]interface {}) {
readPermissions[i] = v.(string)
}

// convert {"team_name": "read_write"} to {"READ": ["team_name"], "WRITE": ["team_name"]}
// for the spinnaker API
readPerms := []string{}
writePerms := []string{}
for team, permI := range data.Get("permissions").(map[string]interface{}) {
perm := permI.(string)
if strings.HasPrefix(perm, "read") {
readPerms = append(readPerms, team)
}
if strings.HasSuffix(perm, "write") {
writePerms = append(writePerms, team)
}
writePermissions := make([]string, len(data.Get("write_permissions").([]interface {})))
for i, v := range data.Get("write_permissions").([]interface {}) {
writePermissions[i] = v.(string)
}

executePermissions := make([]string, len(data.Get("execute_permissions").([]interface {})))
for i, v := range data.Get("execute_permissions").([]interface {}) {
executePermissions[i] = v.(string)
}
app.Permissions["READ"] = readPerms
app.Permissions["WRITE"] = writePerms


app.Permissions["READ"] = readPermissions
app.Permissions["WRITE"] = writePermissions
app.Permissions["EXECUTE"] = executePermissions

return app
}
Expand All @@ -165,21 +176,26 @@ func readApplication(data *schema.ResourceData, application *applicationRead) er
data.Set("email", application.Attributes.Email)
data.Set("instance_port", application.Attributes.InstancePort)

// convert {"READ": ["team_name"], "WRITE": ["team_name"]} to {"team_name": "read_write"}
// for the spinnaker API
perms := make(map[string]string)
readPermissions := []string{}

for _, team := range application.Attributes.Permissions["READ"] {
perms[team] = "read"
readPermissions = append(readPermissions, team)
}

writePermissions := []string{}
for _, team := range application.Attributes.Permissions["WRITE"] {
perm, ok := perms[team]
if ok {
// perms contains "read", append undescore to create "read_write"
perm += "_"
}
perm += "write"
perms[team] = perm
writePermissions = append(writePermissions, team)
}
data.Set("permissions", perms)

executePermissions := []string{}

for _, team := range application.Attributes.Permissions["EXECUTE"] {
executePermissions = append(executePermissions, team)
}

data.Set("read_permissions", readPermissions)
data.Set("write_permissions", writePermissions)
data.Set("execute_permissions", executePermissions)

return nil
}
2 changes: 1 addition & 1 deletion spinnaker/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/armory-io/terraform-provider-spinnaker/spinnaker/api"
"github.com/finanzcheck/terraform-provider-spinnaker/spinnaker/api"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion spinnaker/resource_pipeline_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"reflect"

"github.com/armory-io/terraform-provider-spinnaker/spinnaker/api"
"github.com/finanzcheck/terraform-provider-spinnaker/spinnaker/api"
"github.com/ghodss/yaml"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down
2 changes: 1 addition & 1 deletion spinnaker/resource_pipeline_template_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"log"

"github.com/armory-io/terraform-provider-spinnaker/spinnaker/api"
"github.com/finanzcheck/terraform-provider-spinnaker/spinnaker/api"
"github.com/ghodss/yaml"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down