Skip to content

Commit

Permalink
Merge pull request #2 from guido9j/feat/upsert-strategy
Browse files Browse the repository at this point in the history
Upsert Strategy
  • Loading branch information
guido9j authored Sep 11, 2022
2 parents 2616ca6 + cf1ff3e commit 2eb4d25
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ https://spinnaker.io/concepts/
## Requirements

- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
- [Go](https://golang.org/doc/install) 1.11 (to build the provider plugin)
- [Go](https://golang.org/doc/install) 1.14 (to build the provider plugin)

## Building and Developing The Provider

```sh
$ git clone [email protected]:tidal-engineering/terraform-provider-spinnaker.git
$ git clone [email protected]:guido9j/terraform-provider-spinnaker.git
$ cd terraform-provider-spinnaker/
$ go build
$ go test./...
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/tidal-engineering/terraform-provider-spinnaker
module github.com/guido9j/terraform-provider-spinnaker

go 1.14

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/tidal-engineering/terraform-provider-spinnaker/spinnaker"
"github.com/guido9j/terraform-provider-spinnaker/spinnaker"
)

func main() {
Expand Down
9 changes: 9 additions & 0 deletions spinnaker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func Provider() terraform.ResourceProvider {
Description: "Path to Gate config file",
DefaultFunc: schema.EnvDefaultFunc("SPINNAKER_CONFIG_PATH", nil),
},
"upsert_strategy": {
Type: schema.TypeBool,
Optional: true,
Description: "When creating pipelines, update pipeline if it already exists.",
Default: true,
},
"https_proxy": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -60,11 +66,13 @@ func Provider() terraform.ResourceProvider {
type gateConfig struct {
server string
client *gate.GatewayClient
upSertStrategy bool
}

func providerConfigureFunc(data *schema.ResourceData) (interface{}, error) {
server := data.Get("server").(string)
config := data.Get("config").(string)
upSertStrategy := data.Get("upsert_strategy").(bool)
httpsProxy := data.Get("https_proxy").(string)
ignoreCertErrors := data.Get("ignore_cert_errors").(bool)
defaultHeaders := data.Get("default_headers").(string)
Expand All @@ -88,5 +96,6 @@ func providerConfigureFunc(data *schema.ResourceData) (interface{}, error) {
return gateConfig{
server: data.Get("server").(string),
client: client,
upSertStrategy: upSertStrategy,
}, nil
}
2 changes: 1 addition & 1 deletion 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/tidal-engineering/terraform-provider-spinnaker/spinnaker/api"
"github.com/guido9j/terraform-provider-spinnaker/spinnaker/api"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down
14 changes: 13 additions & 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/tidal-engineering/terraform-provider-spinnaker/spinnaker/api"
"github.com/guido9j/terraform-provider-spinnaker/spinnaker/api"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -54,6 +54,18 @@ func resourcePipelineCreate(data *schema.ResourceData, meta interface{}) error {
pipelineName := data.Get("name").(string)
pipeline := data.Get("pipeline").(string)

if clientConfig.upSertStrategy == true {
var p pipelineRead
jsonMap, err := api.GetPipeline(client, applicationName, pipelineName, &p)
//return fmt.Errorf("jsonMap: %v, err: %s", jsonMap, err)
if err == nil {
err = data.Set("pipeline_id", jsonMap["id"])
if err == nil {
return resourcePipelineUpdate (data, meta);
}
}
}

var tmp map[string]interface{}
if err := json.NewDecoder(strings.NewReader(pipeline)).Decode(&tmp); err != nil {
return err
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/tidal-engineering/terraform-provider-spinnaker/spinnaker/api"
"github.com/guido9j/terraform-provider-spinnaker/spinnaker/api"
"github.com/ghodss/yaml"
"github.com/hashicorp/terraform-plugin-sdk/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/tidal-engineering/terraform-provider-spinnaker/spinnaker/api"
"github.com/guido9j/terraform-provider-spinnaker/spinnaker/api"
"github.com/ghodss/yaml"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
Expand Down

0 comments on commit 2eb4d25

Please sign in to comment.