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

Add support for ArgoCD service connections #501

Merged
merged 16 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,368 @@
//go:build (all || resource_serviceendpoint_argocd) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_argocd
// +build !exclude_serviceendpoints

package acceptancetests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

func TestAccServiceEndpointArgoCD_basic(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasic(projectName, serviceEndpointName, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "url"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_basic_usernamepassword(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasicUsernamePassword(projectName, serviceEndpointName, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "authentication_basic.#", "1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_complete_token(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
description := t.Name()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceComplete(projectName, serviceEndpointName, description),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "authentication_token.#", "1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "url", "https://url.com/1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_complete_usernamepassword(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
description := t.Name()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceCompleteUsernamePassword(projectName, serviceEndpointName, description),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "authentication_basic.#", "1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "url", "https://url.com/1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_update(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointNameFirst := testutils.GenerateResourceName()

description := t.Name()
serviceEndpointNameSecond := testutils.GenerateResourceName()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasic(projectName, serviceEndpointNameFirst, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst), resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
),
},
{
Config: hclSvcEndpointArgoCDResourceUpdate(projectName, serviceEndpointNameSecond, description),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameSecond),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "authentication_token.#", "1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "url", "https://url.com/2"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameSecond),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_update_usernamepassword(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointNameFirst := testutils.GenerateResourceName()

description := t.Name()
serviceEndpointNameSecond := testutils.GenerateResourceName()

resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasicUsernamePassword(projectName, serviceEndpointNameFirst, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst), resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
),
},
{
Config: hclSvcEndpointArgoCDResourceUpdateUsernamePassword(projectName, serviceEndpointNameSecond, description),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameSecond),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "authentication_basic.#", "1"),
resource.TestCheckResourceAttr(tfSvcEpNode, "url", "https://url.com/2"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameSecond),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
),
},
},
})
}

func TestAccServiceEndpointArgoCD_RequiresImportErrorStep(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasic(projectName, serviceEndpointName, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
),
},
{
Config: hclSvcEndpointArgoCDResourceRequiresImport(projectName, serviceEndpointName, t.Name()),
ExpectError: testutils.RequiresImportError(serviceEndpointName),
},
},
})
}

func TestAccServiceEndpointArgoCD_RequiresImportErrorStepUsernamePassword(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_argocd"
tfSvcEpNode := resourceType + ".test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointArgoCDResourceBasicUsernamePassword(projectName, serviceEndpointName, t.Name()),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
),
},
{
Config: hclSvcEndpointArgoCDResourceRequiresImport(projectName, serviceEndpointName, t.Name()),
ExpectError: testutils.RequiresImportError(serviceEndpointName),
},
},
})
}

func hclSvcEndpointArgoCDResourceBasic(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
authentication_token {
token = "redacted"
}
url = "http://url.com/1"
description = "%s"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceBasicUsernamePassword(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
authentication_basic {
username = "u"
password = "redacted"
}
url = "http://url.com/1"
description = "%s"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceCompleteUsernamePassword(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
description = "%s"
authentication_basic {
username = "u"
password = "redacted"
}
url = "https://url.com/1"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceComplete(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
description = "%s"
authentication_token {
token = "redacted"
}
url = "https://url.com/1"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceUpdate(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
description = "%s"
authentication_token {
token = "redacted2"
}
url = "https://url.com/2"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceUpdateUsernamePassword(projectName string, serviceEndpointName string, description string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_argocd" "test" {
project_id = azuredevops_project.project.id
service_endpoint_name = "%s"
description = "%s"
authentication_basic {
username = "u2"
password = "redacted2"
}
url = "https://url.com/2"
}`, serviceEndpointName, description)

projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointArgoCDResourceRequiresImport(projectName string, serviceEndpointName string, description string) string {
template := hclSvcEndpointArgoCDResourceBasic(projectName, serviceEndpointName, description)
return fmt.Sprintf(`
%s
resource "azuredevops_serviceendpoint_argocd" "import" {
project_id = azuredevops_serviceendpoint_argocd.test.project_id
service_endpoint_name = azuredevops_serviceendpoint_argocd.test.service_endpoint_name
description = azuredevops_serviceendpoint_argocd.test.description
url = azuredevops_serviceendpoint_argocd.test.url
authentication_token {
token = "redacted"
}
}
`, template)
}
func hclSvcEndpointArgoCDResourceRequiresImportUsernamePassword(projectName string, serviceEndpointName string, description string) string {
template := hclSvcEndpointArgoCDResourceBasicUsernamePassword(projectName, serviceEndpointName, description)
return fmt.Sprintf(`
%s
resource "azuredevops_serviceendpoint_argocd" "import" {
project_id = azuredevops_serviceendpoint_argocd.test.project_id
service_endpoint_name = azuredevops_serviceendpoint_argocd.test.service_endpoint_name
description = azuredevops_serviceendpoint_argocd.test.description
url = azuredevops_serviceendpoint_argocd.test.url
authentication_basic {
username = "u"
password = "redacted"
}
}
`, template)
}
Loading