Skip to content

Commit

Permalink
feat: update GCP terraform connection naming for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
konturn committed Jun 8, 2023
1 parent 8cc051d commit 8fc8726
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (all || resource_serviceendpoint_gcp) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_gcp
//go:build (all || resource_serviceendpoint_gcp_terraform) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_gcp_terraform
// +build !exclude_serviceendpoints

package acceptancetests
Expand All @@ -12,19 +12,19 @@ import (
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

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

resourceType := "azuredevops_serviceendpoint_gcp"
resourceType := "azuredevops_serviceendpoint_gcp_terraform"
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: hclSvcEndpointGcpResource(projectName, serviceEndpointName),
Config: hclSvcEndpointGcpTerraformResource(projectName, serviceEndpointName),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
Expand All @@ -39,7 +39,7 @@ func TestAccServiceEndpointGcp_Basic(t *testing.T) {
})
}

func TestAccServiceEndpointGcp_Complete(t *testing.T) {
func TestAccServiceEndpointGcpTerraform_Complete(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
description := testutils.GenerateResourceName()
Expand All @@ -48,15 +48,15 @@ func TestAccServiceEndpointGcp_Complete(t *testing.T) {
tokenUri := "tokenUri"
projectId := "projectId"

resourceType := "azuredevops_serviceendpoint_gcp"
resourceType := "azuredevops_serviceendpoint_gcp_terraform"
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: hclSvcEndpointGcpResourceComplete(projectName, serviceEndpointName, description, scope, clientEmail, tokenUri, projectId),
Config: hclSvcEndpointGcpTerraformResourceComplete(projectName, serviceEndpointName, description, scope, clientEmail, tokenUri, projectId),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
Expand All @@ -74,30 +74,30 @@ func TestAccServiceEndpointGcp_Complete(t *testing.T) {
})
}

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

description := testutils.GenerateResourceName()
serviceEndpointNameSecond := testutils.GenerateResourceName()
tokenUri := "tokenUri"

resourceType := "azuredevops_serviceendpoint_gcp"
resourceType := "azuredevops_serviceendpoint_gcp_terraform"
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: hclSvcEndpointGcpResource(projectName, serviceEndpointNameFirst),
Config: hclSvcEndpointGcpTerraformResource(projectName, serviceEndpointNameFirst),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst), resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
),
},
{
Config: hclSvcEndpointGcpResourceUpdate(projectName, serviceEndpointNameSecond, description, tokenUri),
Config: hclSvcEndpointGcpTerraformResourceUpdate(projectName, serviceEndpointNameSecond, description, tokenUri),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameSecond),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
Expand All @@ -110,40 +110,40 @@ func TestAccServiceEndpointGcp_update(t *testing.T) {
})
}

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

resourceType := "azuredevops_serviceendpoint_gcp"
resourceType := "azuredevops_serviceendpoint_gcp_terraform"
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: hclSvcEndpointGcpResource(projectName, serviceEndpointName),
Config: hclSvcEndpointGcpTerraformResource(projectName, serviceEndpointName),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
),
},
{
Config: hclSvcEndpointGcpResourceRequiresImport(projectName, serviceEndpointName),
Config: hclSvcEndpointGcpTerraformResourceRequiresImport(projectName, serviceEndpointName),
ExpectError: testutils.RequiresImportError(serviceEndpointName),
},
},
})
}

func hclSvcEndpointGcpResource(projectName string, serviceEndpointName string) string {
return hclSvcEndpointGcpResourceUpdate(projectName, serviceEndpointName, "description", "tokenUri")
func hclSvcEndpointGcpTerraformResource(projectName string, serviceEndpointName string) string {
return hclSvcEndpointGcpTerraformResourceUpdate(projectName, serviceEndpointName, "description", "tokenUri")
}

func hclSvcEndpointGcpResourceUpdate(projectName string, serviceEndpointName string, description string, tokenUri string) string {
func hclSvcEndpointGcpTerraformResourceUpdate(projectName string, serviceEndpointName string, description string, tokenUri string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_gcp" "test" {
resource "azuredevops_serviceendpoint_gcp_terraform" "test" {
project_id = azuredevops_project.project.id
private_key = "secretkey"
token_uri = "%s"
Expand All @@ -156,9 +156,9 @@ func hclSvcEndpointGcpResourceUpdate(projectName string, serviceEndpointName str
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointGcpResourceComplete(projectName string, serviceEndpointName string, description string, clientEmail string, scope string, tokenUri string, projectId string) string {
func hclSvcEndpointGcpTerraformResourceComplete(projectName string, serviceEndpointName string, description string, clientEmail string, scope string, tokenUri string, projectId string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_serviceendpoint_gcp" "test" {
resource "azuredevops_serviceendpoint_gcp_terraform" "test" {
project_id = azuredevops_project.project.id
private_key = "secretkey"
token_uri = "%s"
Expand All @@ -174,16 +174,16 @@ func hclSvcEndpointGcpResourceComplete(projectName string, serviceEndpointName s
return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource)
}

func hclSvcEndpointGcpResourceRequiresImport(projectName string, serviceEndpointName string) string {
template := hclSvcEndpointGcpResource(projectName, serviceEndpointName)
func hclSvcEndpointGcpTerraformResourceRequiresImport(projectName string, serviceEndpointName string) string {
template := hclSvcEndpointGcpTerraformResource(projectName, serviceEndpointName)
return fmt.Sprintf(`
%s
resource "azuredevops_serviceendpoint_gcp" "import" {
project_id = azuredevops_serviceendpoint_gcp.test.project_id
resource "azuredevops_serviceendpoint_gcp_terraform" "import" {
project_id = azuredevops_serviceendpoint_gcp_terraform.test.project_id
private_key = "secretkey"
service_endpoint_name = azuredevops_serviceendpoint_gcp.test.service_endpoint_name
description = azuredevops_serviceendpoint_gcp.test.description
gcp_project_id = azuredevops_serviceendpoint_gcp.test.gcp_project_id
service_endpoint_name = azuredevops_serviceendpoint_gcp_terraform.test.service_endpoint_name
description = azuredevops_serviceendpoint_gcp_terraform.test.description
gcp_project_id = azuredevops_serviceendpoint_gcp_terraform.test.gcp_project_id
}
`, template)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build (all || resource_serviceendpoint_gcp) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_gcp
//go:build (all || resource_serviceendpoint_gcp_terraform) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_gcp_terraform
// +build !exclude_serviceendpoints

package serviceendpoint
Expand All @@ -19,11 +19,11 @@ import (
"github.com/stretchr/testify/require"
)

var gcpTestServiceEndpointID = uuid.New()
var gcpForTerraformTestServiceEndpointID = uuid.New()
var gcpRandomServiceEndpointProjectID = uuid.New()
var gcpTestServiceEndpointProjectID = &gcpRandomServiceEndpointProjectID
var gcpForTerraformTestServiceEndpointProjectID = &gcpRandomServiceEndpointProjectID

var gcpTestServiceEndpoint = serviceendpoint.ServiceEndpoint{
var gcpForTerraformTestServiceEndpoint = serviceendpoint.ServiceEndpoint{
Authorization: &serviceendpoint.EndpointAuthorization{
Parameters: &map[string]string{
"Issuer": "GCP_TEST_client_email",
Expand All @@ -36,15 +36,15 @@ var gcpTestServiceEndpoint = serviceendpoint.ServiceEndpoint{
Data: &map[string]string{
"project": "GCP_TEST_project_id",
},
Id: &gcpTestServiceEndpointID,
Id: &gcpForTerraformTestServiceEndpointID,
Name: converter.String("UNIT_TEST_CONN_NAME"),
Owner: converter.String("library"), // Supported values are "library", "agentcloud"
Type: converter.String("GoogleCloudServiceEndpoint"),
Url: converter.String("https://www.googleapis.com/"),
ServiceEndpointProjectReferences: &[]serviceendpoint.ServiceEndpointProjectReference{
{
ProjectReference: &serviceendpoint.ProjectReference{
Id: gcpTestServiceEndpointProjectID,
Id: gcpForTerraformTestServiceEndpointProjectID,
},
Name: converter.String("UNIT_TEST_CONN_NAME"),
Description: converter.String("UNIT_TEST_CONN_DESCRIPTION"),
Expand All @@ -55,12 +55,12 @@ var gcpTestServiceEndpoint = serviceendpoint.ServiceEndpoint{
// verifies that the flatten/expand round trip yields the same service endpoint
func TestServiceEndpointGcp_ExpandFlatten_Roundtrip(t *testing.T) {
resourceData := schema.TestResourceDataRaw(t, ResourceServiceEndpointGcp().Schema, nil)
flattenServiceEndpointGcp(resourceData, &gcpTestServiceEndpoint, gcpTestServiceEndpointProjectID)
flattenServiceEndpointGcp(resourceData, &gcpForTerraformTestServiceEndpoint, gcpForTerraformTestServiceEndpointProjectID)

serviceEndpointAfterRoundTrip, projectID, err := expandServiceEndpointGcp(resourceData)

require.Equal(t, gcpTestServiceEndpoint, *serviceEndpointAfterRoundTrip)
require.Equal(t, gcpTestServiceEndpointProjectID, projectID)
require.Equal(t, gcpForTerraformTestServiceEndpoint, *serviceEndpointAfterRoundTrip)
require.Equal(t, gcpForTerraformTestServiceEndpointProjectID, projectID)
require.Nil(t, err)
}

Expand All @@ -71,12 +71,12 @@ func TestServiceEndpointGcp_Create_DoesNotSwallowError(t *testing.T) {

r := ResourceServiceEndpointGcp()
resourceData := schema.TestResourceDataRaw(t, r.Schema, nil)
flattenServiceEndpointGcp(resourceData, &gcpTestServiceEndpoint, gcpTestServiceEndpointProjectID)
flattenServiceEndpointGcp(resourceData, &gcpForTerraformTestServiceEndpoint, gcpForTerraformTestServiceEndpointProjectID)

buildClient := azdosdkmocks.NewMockServiceendpointClient(ctrl)
clients := &client.AggregatedClient{ServiceEndpointClient: buildClient, Ctx: context.Background()}

expectedArgs := serviceendpoint.CreateServiceEndpointArgs{Endpoint: &gcpTestServiceEndpoint}
expectedArgs := serviceendpoint.CreateServiceEndpointArgs{Endpoint: &gcpForTerraformTestServiceEndpoint}
buildClient.
EXPECT().
CreateServiceEndpoint(clients.Ctx, expectedArgs).
Expand All @@ -94,14 +94,14 @@ func TestServiceEndpointGcp_Read_DoesNotSwallowError(t *testing.T) {

r := ResourceServiceEndpointGcp()
resourceData := schema.TestResourceDataRaw(t, r.Schema, nil)
flattenServiceEndpointGcp(resourceData, &gcpTestServiceEndpoint, gcpTestServiceEndpointProjectID)
flattenServiceEndpointGcp(resourceData, &gcpForTerraformTestServiceEndpoint, gcpForTerraformTestServiceEndpointProjectID)

buildClient := azdosdkmocks.NewMockServiceendpointClient(ctrl)
clients := &client.AggregatedClient{ServiceEndpointClient: buildClient, Ctx: context.Background()}

expectedArgs := serviceendpoint.GetServiceEndpointDetailsArgs{
EndpointId: gcpTestServiceEndpoint.Id,
Project: converter.String(gcpTestServiceEndpointProjectID.String()),
EndpointId: gcpForTerraformTestServiceEndpoint.Id,
Project: converter.String(gcpForTerraformTestServiceEndpointProjectID.String()),
}
buildClient.
EXPECT().
Expand All @@ -120,15 +120,15 @@ func TestServiceEndpointGcp_Delete_DoesNotSwallowError(t *testing.T) {

r := ResourceServiceEndpointGcp()
resourceData := schema.TestResourceDataRaw(t, r.Schema, nil)
flattenServiceEndpointGcp(resourceData, &gcpTestServiceEndpoint, gcpTestServiceEndpointProjectID)
flattenServiceEndpointGcp(resourceData, &gcpForTerraformTestServiceEndpoint, gcpForTerraformTestServiceEndpointProjectID)

buildClient := azdosdkmocks.NewMockServiceendpointClient(ctrl)
clients := &client.AggregatedClient{ServiceEndpointClient: buildClient, Ctx: context.Background()}

expectedArgs := serviceendpoint.DeleteServiceEndpointArgs{
EndpointId: gcpTestServiceEndpoint.Id,
EndpointId: gcpForTerraformTestServiceEndpoint.Id,
ProjectIds: &[]string{
gcpTestServiceEndpointProjectID.String(),
gcpForTerraformTestServiceEndpointProjectID.String(),
},
}
buildClient.
Expand All @@ -148,14 +148,14 @@ func TestServiceEndpointGcp_Update_DoesNotSwallowError(t *testing.T) {

r := ResourceServiceEndpointGcp()
resourceData := schema.TestResourceDataRaw(t, r.Schema, nil)
flattenServiceEndpointGcp(resourceData, &gcpTestServiceEndpoint, gcpTestServiceEndpointProjectID)
flattenServiceEndpointGcp(resourceData, &gcpForTerraformTestServiceEndpoint, gcpForTerraformTestServiceEndpointProjectID)

buildClient := azdosdkmocks.NewMockServiceendpointClient(ctrl)
clients := &client.AggregatedClient{ServiceEndpointClient: buildClient, Ctx: context.Background()}

expectedArgs := serviceendpoint.UpdateServiceEndpointArgs{
Endpoint: &gcpTestServiceEndpoint,
EndpointId: gcpTestServiceEndpoint.Id,
Endpoint: &gcpForTerraformTestServiceEndpoint,
EndpointId: gcpForTerraformTestServiceEndpoint.Id,
}

buildClient.
Expand Down
2 changes: 1 addition & 1 deletion azuredevops/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Provider() *schema.Provider {
"azuredevops_serviceendpoint_dockerregistry": serviceendpoint.ResourceServiceEndpointDockerRegistry(),
"azuredevops_serviceendpoint_azurecr": serviceendpoint.ResourceServiceEndpointAzureCR(),
"azuredevops_serviceendpoint_github": serviceendpoint.ResourceServiceEndpointGitHub(),
"azuredevops_serviceendpoint_gcp": serviceendpoint.ResourceServiceEndpointGcp(),
"azuredevops_serviceendpoint_gcp_terraform": serviceendpoint.ResourceServiceEndpointGcp(),
"azuredevops_serviceendpoint_incomingwebhook": serviceendpoint.ResourceServiceEndpointIncomingWebhook(),
"azuredevops_serviceendpoint_github_enterprise": serviceendpoint.ResourceServiceEndpointGitHubEnterprise(),
"azuredevops_serviceendpoint_kubernetes": serviceendpoint.ResourceServiceEndpointKubernetes(),
Expand Down
2 changes: 1 addition & 1 deletion azuredevops/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestProvider_HasChildResources(t *testing.T) {
"azuredevops_project_pipeline_settings",
"azuredevops_check_branch_control",
"azuredevops_check_business_hours",
"azuredevops_serviceendpoint_gcp",
"azuredevops_serviceendpoint_gcp_terraform",
"azuredevops_serviceendpoint_github",
"azuredevops_serviceendpoint_github_enterprise",
"azuredevops_serviceendpoint_dockerregistry",
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/serviceendpoint_gcp.html.markdown
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
layout: "azuredevops"
page_title: "AzureDevops: azuredevops_serviceendpoint_gcp"
page_title: "AzureDevops: azuredevops_serviceendpoint_gcp_terraform"
description: |-
Manages a GCP service endpoint within Azure DevOps organization.
---

# azuredevops_serviceendpoint_gcp
# azuredevops_serviceendpoint_gcp_terraform
Manages a GCP service endpoint for Terraform within Azure DevOps. Using this service endpoint requires you to first install the [Azure Terraform Extension for Azure DevOps from Microsoft DevLabs](https://marketplace.visualstudio.com/items?itemName=ms-devlabs.custom-terraform-tasks).

## Example Usage
Expand All @@ -19,7 +19,7 @@ resource "azuredevops_project" "example" {
description = "Managed by Terraform"
}
resource "azuredevops_serviceendpoint_gcp" "example" {
resource "azuredevops_serviceendpoint_gcp_terraform" "example" {
project_id = azuredevops_project.example.id
token_uri = "https://oauth2.example.com/token"
client_email = "[email protected]"
Expand Down Expand Up @@ -58,5 +58,5 @@ The following attributes are exported:
Azure DevOps Service Endpoint GCP can be imported using **projectID/serviceEndpointID** or **projectName/serviceEndpointID**

```sh
terraform import azuredevops_serviceendpoint_gcp.example 00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000
terraform import azuredevops_serviceendpoint_gcp_terraform.example 00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000
```

0 comments on commit 8fc8726

Please sign in to comment.