Skip to content
Merged
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
12 changes: 6 additions & 6 deletions codefresh/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package codefresh

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var testAccProvider *schema.Provider
var testAccProviders map[string]terraform.ResourceProvider
var testAccProviders map[string]*schema.Provider

func init() {
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"codefresh": testAccProvider,
}
}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
Expand Down
16 changes: 14 additions & 2 deletions codefresh/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package codefresh

import (
"fmt"
"strings"

cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"strings"
)

func resourcePipeline() *schema.Resource {
Expand All @@ -28,7 +29,6 @@ func resourcePipeline() *schema.Resource {
"project_id": {
Type: schema.TypeString,
Computed: true,

},
"revision": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -158,6 +158,13 @@ func resourcePipeline() *schema.Resource {
},
},
},
"contexts": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"runtime_environment": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -316,6 +323,8 @@ func flattenSpec(spec cfClient.Spec) []interface{} {

m["priority"] = spec.Priority

m["contexts"] = spec.Contexts

res = append(res, m)
return res
}
Expand Down Expand Up @@ -407,6 +416,9 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
}
}

contexts := d.Get("spec.0.contexts").([]interface{})
pipeline.Spec.Contexts = contexts

variables := d.Get("spec.0.variables").(map[string]interface{})
pipeline.SetVariables(variables)

Expand Down
69 changes: 67 additions & 2 deletions codefresh/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package codefresh

import (
"fmt"
"regexp"
"testing"

cfClient "github.com/codefresh-io/terraform-provider-codefresh/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"regexp"
"testing"
)

var pipelineNamePrefix = "TerraformAccTest_"
Expand Down Expand Up @@ -382,6 +383,36 @@ resource "codefresh_pipeline" "test" {
`, rName, repo, path, revision, context, var1Name, var1Value, var2Name, var2Value)
}

func testAccCodefreshPipelineBasicConfigContexts(rName, repo, path, revision, context, sharedContext1, sharedContext2 string) string {
return fmt.Sprintf(`
resource "codefresh_pipeline" "test" {

lifecycle {
ignore_changes = [
revision
]
}

name = "%s"

spec {
spec_template {
repo = %q
path = %q
revision = %q
context = %q
}

contexts = [
%q,
%q
]

}
}
`, rName, repo, path, revision, context, sharedContext1, sharedContext2)
}

func testAccCodefreshPipelineBasicConfigTriggers(
rName,
repo,
Expand Down Expand Up @@ -517,3 +548,37 @@ resource "codefresh_pipeline" "test" {
}
`, rName, originalYamlString)
}

func TestAccCodefreshPipeline_Contexts(t *testing.T) {
name := pipelineNamePrefix + acctest.RandString(10)
resourceName := "codefresh_pipeline.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCodefreshPipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccCodefreshPipelineBasicConfigContexts(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", "context1", "context2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodefreshPipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "spec.0.contexts.0", "context1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.contexts.1", "context2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccCodefreshPipelineBasicConfigContexts(name, "codefresh-contrib/react-sample-app", "./codefresh.yml", "master", "git", "context1_updated", "context2_updated"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCodefreshPipelineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "spec.0.contexts.0", "context1_updated"),
resource.TestCheckResourceAttr(resourceName, "spec.0.contexts.1", "context2_updated"),
),
},
},
})
}
6 changes: 6 additions & 0 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ resource "codefresh_pipeline" "test" {
context = "git"
}

contexts = [
"context1-name",
"context2-name",
]

trigger {
branch_regex = "/.*/gi"
context = "git"
Expand Down Expand Up @@ -94,6 +99,7 @@ resource "codefresh_pipeline" "test" {
- `trigger` - (Optional) A collection of `trigger` blocks as documented below. Triggers [documentation](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/triggers/git-triggers/).
- `spec_template` - (Optional) A collection of `spec_template` blocks as documented below.
- `runtime_environment` - (Optional) A collection of `runtime_environment` blocks as documented below.
- `contexts` - (Optional) A list of strings representing the contexts ([shared_configuration](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/shared-configuration/)) to be configured for the pipeline

---

Expand Down
5 changes: 5 additions & 0 deletions examples/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ resource "codefresh_pipeline" "test" {
context = "git"
}

contexts = [
"context1-name",
"context2-name",
]

trigger {
branch_regex = "/.*/gi"
context = "git"
Expand Down