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

Release pipeline #178

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c035c14
adding tags to build pipeline
Sep 1, 2020
9676a77
adding in release pipelines
Sep 1, 2020
e315f33
fix tests & lint
Sep 1, 2020
c044181
update build docs
Sep 2, 2020
6187002
added acc test
Sep 3, 2020
1076a3a
Merge branch 'build-pipeline-tags' into release-pipeline
Sep 3, 2020
ccc3a75
fix tags syntax
Sep 3, 2020
199745e
adding acc test
Sep 4, 2020
710019b
adding group for ownership of the release pipeline, escape path
Sep 4, 2020
b88d971
adding data for agent queue & adding origin id to group data
Sep 8, 2020
f179fba
update to test, got it running, not passing
Sep 8, 2020
4d103f3
Merge branch 'master' into build-pipeline-tags
Sep 8, 2020
c6a895d
Merge branch 'data-agent-queue' into release-pipeline
Sep 9, 2020
5bdd03c
fix import name
Sep 9, 2020
d077d64
Merge remote-tracking branch 'origin/master' into build-pipeline-tags
Sep 9, 2020
558049c
Merge remote-tracking branch 'origin/master' into release-pipeline
Sep 9, 2020
1b63d79
Merge branch 'data_group-add-origin-id' into release-pipeline
Sep 9, 2020
76a0a34
Merge branch 'build-pipeline-tags' into release-pipeline
Sep 9, 2020
b875ccb
move tasks to taskagent
Sep 9, 2020
51a31fa
added support for approval options
Sep 9, 2020
1cf865b
update notes
Sep 9, 2020
c012ef5
remove todo notes
Sep 9, 2020
53c2c89
fix applying options for "pre" & "post" with unique execution_order
Sep 9, 2020
a3e224a
Merge branch 'master' into release-pipeline
Sep 10, 2020
dce72a3
custom timeout for pre and post
Sep 10, 2020
89b0bef
add note for required with, remove debug log
Sep 10, 2020
f392168
Merge branch 'master' into release-pipeline
Sep 11, 2020
4c4c7a6
Merge remote-tracking branch 'origin/master' into release-pipeline
Nov 3, 2020
f785f1d
add new os versions to agent_specification validation (#1)
marekaf Feb 8, 2021
cbe1a98
Merge branch 'main' into release-pipeline
exocom Jun 2, 2022
d0fdccb
go fmt
exocom Jun 2, 2022
cefc7d2
update to latest versions
exocom Jun 2, 2022
6eb8ba2
update to latest versions with deps
exocom Jun 2, 2022
71cb222
add generic function
exocom Jun 2, 2022
6863fd9
add generic function for interface
exocom Jun 2, 2022
1be91cc
use generic func
exocom Jun 2, 2022
1113a42
use generic func
exocom Jun 2, 2022
87d46f6
use generic func
exocom Jun 2, 2022
637aa4b
use generic func
exocom Jun 2, 2022
830de16
use generic func
exocom Jun 2, 2022
3c39896
use generic func
exocom Jun 4, 2022
5d5593f
use generic func
exocom Jun 4, 2022
c6e226b
use generic func
exocom Jun 4, 2022
5e120f7
use generic func
exocom Jun 4, 2022
855a05a
use generic func
exocom Jun 4, 2022
f6c2e5e
use generic func
exocom Jun 4, 2022
7b1c765
use generic func
exocom Jun 4, 2022
391c5d2
use generic func
exocom Jun 4, 2022
685bbae
lint
exocom Jun 4, 2022
056f53c
lint again
exocom Jun 4, 2022
e2c3e57
fix imports for test
exocom Jun 4, 2022
847eaf7
using v6 not standalone
exocom Jun 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ func TestAccBuildDefinitionBitbucket_Create(t *testing.T) {
})
}

// Verifies a build for with tags can create and update
func TestAccBuildDefinition_WithTags_CreateAndUpdate(t *testing.T) {
name := testutils.GenerateResourceName()
tfNode := "azuredevops_build_definition.build"

resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: checkBuildDefinitionDestroyed,
Steps: []resource.TestStep{
{
Config: testutils.HclBuildDefinitionWithTags([]string{"one", "two"}, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "tags.#", "2"),
),
}, {
Config: testutils.HclBuildDefinitionWithTags([]string{"one", "two", "three"}, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "tags.#", "3"),
),
},
},
})
}

// Verifies a build for with variables can create and update, including secret variables
func TestAccBuildDefinition_WithVariables_CreateAndUpdate(t *testing.T) {
name := testutils.GenerateResourceName()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
//go:build (all || resource_release_definition) && !exclude_resource_release_definition
// +build all resource_release_definition
// +build !exclude_resource_release_definition

package acceptancetests

import (
"fmt"
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/microsoft/azure-devops-go-api/azuredevops/v6/release"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/client"
)

// validates that an apply followed by another apply (i.e., resource update) will be reflected in AzDO and the
// underlying terraform state.
func TestAccReleaseDefinition_Create_Update_Import(t *testing.T) {
projectName := testutils.GenerateResourceName()
releaseDefinitionPathEmpty := `\`
releaseDefinitionNameFirst := testutils.GenerateResourceName()
//releaseDefinitionNameSecond := testutils.GenerateResourceName()
//releaseDefinitionNameThird := testutils.GenerateResourceName()

//releaseDefinitionPathFirst := `\` + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
//releaseDefinitionPathSecond := `\` + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

//releaseDefinitionPathThird := `\` + releaseDefinitionNameFirst + `\` + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
//releaseDefinitionPathFourth := `\` + releaseDefinitionNameSecond + `\` + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

c1 := testutils.HclReleaseDefinitionAgent(projectName, releaseDefinitionNameFirst, releaseDefinitionPathEmpty)
tfReleaseDefNode := "azuredevops_release_definition.release"
resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: checkReleaseDefinitionDestroyed,
Steps: []resource.TestStep{
{
Config: c1,
Check: resource.ComposeTestCheckFunc(
checkReleaseDefinitionExists(releaseDefinitionNameFirst),
resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameFirst),
resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathEmpty),
),
},
//{
// Config: testutils.HclReleaseDefinitionAgentless(projectName, releaseDefinitionNameSecond, releaseDefinitionPathEmpty),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameSecond),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameSecond),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathEmpty),
// ),
//}, {
// Config: testutils.HclReleaseDefinitionAgentless(projectName, releaseDefinitionNameFirst, releaseDefinitionPathFirst),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameFirst),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameFirst),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathFirst),
// ),
//}, {
// Config: testutils.HclReleaseDefinitionAgentless(projectName, releaseDefinitionNameFirst,
// releaseDefinitionPathSecond),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameFirst),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameFirst),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathSecond),
// ),
//}, {
// Config: testutils.HclReleaseDefinitionAgentless(projectName, releaseDefinitionNameFirst, releaseDefinitionPathThird),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameFirst),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameFirst),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathThird),
// ),
//}, {
// Config: testutils.HclReleaseDefinitionAgentless(projectName, releaseDefinitionNameFirst, releaseDefinitionPathFourth),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameFirst),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameFirst),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathFourth),
// ),
//}, {
// Config: testutils.HclReleaseDefinitionAgentless(projectName, gitRepoName, releaseDefinitionNameThird, releaseDefinitionPathEmpty),
// Check: resource.ComposeTestCheckFunc(
// checkReleaseDefinitionExists(releaseDefinitionNameThird),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "project_id"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "revision"),
// resource.TestCheckResourceAttrSet(tfReleaseDefNode, "repository.0.repo_id"),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "name", releaseDefinitionNameThird),
// resource.TestCheckResourceAttr(tfReleaseDefNode, "path", releaseDefinitionPathEmpty),
// ),
//}, {
// // Resource Acceptance Testing https://www.terraform.io/docs/extend/resources/import.html#resource-acceptance-testing-implementation
// ResourceName: tfReleaseDefNode,
// ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(tfReleaseDefNode),
// ImportState: true,
// ImportStateVerify: true,
//},
},
})
}

// Given the name of an AzDO release definition, this will return a function that will check whether
// or not the definition (1) exists in the state and (2) exist in AzDO and (3) has the correct name
func checkReleaseDefinitionExists(expectedName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
releaseDef, ok := s.RootModule().Resources["azuredevops_release_definition.release"]
if !ok {
return fmt.Errorf("Did not find a release definition in the TF state")
}

releaseDefinition, err := getReleaseDefinitionFromResource(releaseDef)
if err != nil {
return err
}

if *releaseDefinition.Name != expectedName {
return fmt.Errorf("Release Definition has Name=%s, but expected Name=%s", *releaseDefinition.Name, expectedName)
}

return nil
}
}

// verifies that all release definitions referenced in the state are destroyed. This will be invoked
// *after* terraform destroys the resource but *before* the state is wiped clean.
func checkReleaseDefinitionDestroyed(s *terraform.State) error {
for _, resource := range s.RootModule().Resources {
if resource.Type != "azuredevops_release_definition" {
continue
}

// indicates the release definition still exists - this should fail the test
if _, err := getReleaseDefinitionFromResource(resource); err == nil {
return fmt.Errorf("Unexpectedly found a release definition that should be deleted")
}
}

return nil
}

// given a resource from the state, return a release definition (and error)
func getReleaseDefinitionFromResource(resource *terraform.ResourceState) (*release.ReleaseDefinition, error) {
releaseDefID, err := strconv.Atoi(resource.Primary.ID)
if err != nil {
return nil, err
}

projectID := resource.Primary.Attributes["project_id"]
clients := testutils.GetProvider().Meta().(*client.AggregatedClient)
return clients.ReleaseClient.GetReleaseDefinition(clients.Ctx, release.GetReleaseDefinitionArgs{
Project: &projectID,
DefinitionId: &releaseDefID,
})
}
Loading