From 5e803b10edff3a7749f4046492c050b9ea79e6a6 Mon Sep 17 00:00:00 2001 From: Sharath Nair Date: Thu, 4 Aug 2022 15:31:28 +1000 Subject: Create datasource azuredevops_serviceendpoint_github, add common functions to create datasource schemas, fix documentation --- .../data_serviceendpoint_github_test.go | 61 ++++++++ .../internal/acceptancetests/testutils/hcl.go | 24 ++++ .../internal/service/serviceendpoint/commons.go | 127 +++++++++++++++++ .../data_serviceendpoint_azurerm.go | 157 ++------------------- .../serviceendpoint/data_serviceendpoint_github.go | 24 ++++ azuredevops/provider.go | 1 + website/azuredevops.erb | 3 + .../docs/d/serviceendpoint_azurerm.html.markdown | 9 +- .../docs/d/serviceendpoint_github.html.markdown | 66 +++++++++ 9 files changed, 320 insertions(+), 152 deletions(-) create mode 100644 azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go create mode 100644 azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go create mode 100644 website/docs/d/serviceendpoint_github.html.markdown diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go new file mode 100644 index 00000000..2c16e550 --- /dev/null +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go @@ -0,0 +1,61 @@ +//go:build (all || data_sources || data_serviceendpoint_github) && (!exclude_data_sources || !exclude_data_serviceendpoint_github) +// +build all data_sources data_serviceendpoint_github +// +build !exclude_data_sources !exclude_data_serviceendpoint_github + +package acceptancetests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils" +) + +func TestAccServiceEndpointGitHub_with_serviceEndpointID_DataSource(t *testing.T) { + serviceEndpointGitHubName := testutils.GenerateResourceName() + projectName := testutils.GenerateResourceName() + createServiceEndpointGitHubWithServiceEndpointIDData := fmt.Sprintf("%s\n%s", + testutils.HclServiceEndpointGitHubResource(projectName, serviceEndpointGitHubName), + testutils.HclServiceEndpointGitHubDataSourceWithServiceEndpointID(), + ) + + tfNode := "data.azuredevops_serviceendpoint_github.serviceendpoint" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testutils.PreCheck(t, nil) }, + Providers: testutils.GetProviders(), + Steps: []resource.TestStep{ + { + Config: createServiceEndpointGitHubWithServiceEndpointIDData, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointGitHubName), + resource.TestCheckResourceAttrSet(tfNode, "id"), + ), + }, + }, + }) +} + +func TestAccServiceEndpointGitHub_with_serviceEndpointName_DataSource(t *testing.T) { + serviceEndpointGitHubName := testutils.GenerateResourceName() + projectName := testutils.GenerateResourceName() + createServiceEndpointGitHubWithServiceEndpointNameData := fmt.Sprintf("%s\n%s", + testutils.HclServiceEndpointGitHubResource(projectName, serviceEndpointGitHubName), + testutils.HclServiceEndpointGitHubDataSourceWithServiceEndpointName(serviceEndpointGitHubName), + ) + + tfNode := "data.azuredevops_serviceendpoint_github.serviceendpoint" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testutils.PreCheck(t, nil) }, + Providers: testutils.GetProviders(), + Steps: []resource.TestStep{ + { + Config: createServiceEndpointGitHubWithServiceEndpointNameData, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointGitHubName), + resource.TestCheckResourceAttrSet(tfNode, "id"), + ), + }, + }, + }) +} diff --git a/azuredevops/internal/acceptancetests/testutils/hcl.go b/azuredevops/internal/acceptancetests/testutils/hcl.go index bfa916d1..036ef5b9 100644 --- a/azuredevops/internal/acceptancetests/testutils/hcl.go +++ b/azuredevops/internal/acceptancetests/testutils/hcl.go @@ -251,6 +251,30 @@ resource "azuredevops_serviceendpoint_github" "serviceendpoint" { return fmt.Sprintf("%s\n%s", projectResource, serviceEndpointResource) } +// HclServiceEndpointGitHubDataSourceWithServiceEndpointID HCL describing a data source for an AzDO service endpoint +func HclServiceEndpointGitHubDataSourceWithServiceEndpointID() string { + serviceEndpointDataSource := fmt.Sprintf(` +data "azuredevops_serviceendpoint_github" "serviceendpoint" { + project_id = azuredevops_project.project.id + id = azuredevops_serviceendpoint_github.serviceendpoint.id +} +`) + return fmt.Sprintf("%s", serviceEndpointDataSource) +} + +// HclServiceEndpointGitHubDataSourceWithServiceEndpointName HCL describing a data source for an AzDO service endpoint +func HclServiceEndpointGitHubDataSourceWithServiceEndpointName(serviceEndpointName string) string { + serviceEndpointDataSource := fmt.Sprintf(` +data "azuredevops_serviceendpoint_github" "serviceendpoint" { + project_id = azuredevops_project.project.id + service_endpoint_name = "%s" + depends_on = [azuredevops_serviceendpoint_github.serviceendpoint] +} +`, serviceEndpointName) + + return fmt.Sprintf("%s", serviceEndpointDataSource) +} + func HclServiceEndpointGitHubEnterpriseResource(projectName string, serviceEndpointName string) string { serviceEndpointResource := fmt.Sprintf(` resource "azuredevops_serviceendpoint_github_enterprise" "serviceendpoint" { diff --git a/azuredevops/internal/service/serviceendpoint/commons.go b/azuredevops/internal/service/serviceendpoint/commons.go index 938f7341..cef17094 100644 --- a/azuredevops/internal/service/serviceendpoint/commons.go +++ b/azuredevops/internal/service/serviceendpoint/commons.go @@ -381,3 +381,130 @@ func getServiceEndpoint(client *client.AggregatedClient, serviceEndpointID *uuid return nil, opState.Failed, fmt.Errorf(errMsgServiceCreate, serviceEndpointID, *projectID, serviceEndpoint.OperationStatus) } } + +func dataSourceGenBaseServiceEndpointResource(dataSourceReadFunc schema.ReadFunc) *schema.Resource { + return &schema.Resource{ + Read: dataSourceReadFunc, + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeString, + Required: true, + }, + + "service_endpoint_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ExactlyOneOf: []string{"service_endpoint_name", "id"}, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "id": { + Description: "The ID of the serviceendpoint", + Type: schema.TypeString, + Optional: true, + Computed: true, + ExactlyOneOf: []string{"service_endpoint_name", "id"}, + ValidateFunc: validation.IsUUID, + }, + + "authorization": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceMakeUnprotectedComputedSchema(r *schema.Resource, keyName string) { + r.Schema[keyName] = &schema.Schema{ + Type: schema.TypeString, + Computed: true, + } +} + +func dataSourceGetBaseServiceEndpoint(d *schema.ResourceData, m interface{}) (*serviceendpoint.ServiceEndpoint, *uuid.UUID, error) { + clients := m.(*client.AggregatedClient) + + var projectID *uuid.UUID + projectIDString := d.Get("project_id").(string) + parsedProjectID, err := uuid.Parse(projectIDString) + if err != nil { + return nil, nil, fmt.Errorf("Error parsing projectID from the Terraform data source declaration: %v", err) + } + + projectID = &parsedProjectID + + if serviceEndpointIDString, ok := d.GetOk("id"); ok { + var serviceEndpointID *uuid.UUID + parsedServiceEndpointID, err := uuid.Parse(serviceEndpointIDString.(string)) + if err != nil { + return nil, nil, fmt.Errorf("Error parsing serviceEndpointID from the Terraform data source declaration: %v", err) + } + serviceEndpointID = &parsedServiceEndpointID + + serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails( + clients.Ctx, + serviceendpoint.GetServiceEndpointDetailsArgs{ + EndpointId: serviceEndpointID, + Project: converter.String(projectID.String()), + }, + ) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil, projectID, nil + } + return nil, projectID, fmt.Errorf("Error looking up service endpoint with ID (%v) and projectID (%v): %v", serviceEndpointID, projectID, err) + } + + return serviceEndpoint, projectID, nil + } + + if serviceEndpointName, ok := d.GetOk("service_endpoint_name"); ok { + serviceEndpoint, err := dataSourceGetServiceEndpointByNameAndProject(clients, serviceEndpointName.(string), projectID) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil, projectID, nil + } + return nil, projectID, fmt.Errorf("Error looking up service endpoint with name (%v) and projectID (%v): %v", serviceEndpointName, projectID, err) + } + + return serviceEndpoint, projectID, nil + } + return nil, nil, nil +} + +func dataSourceGetServiceEndpointByNameAndProject(clients *client.AggregatedClient, serviceEndpointName string, projectID *uuid.UUID) (*serviceendpoint.ServiceEndpoint, error) { + serviceEndpointNameList := &[]string{serviceEndpointName} + + serviceEndpoints, err := clients.ServiceEndpointClient.GetServiceEndpointsByNames( + clients.Ctx, + serviceendpoint.GetServiceEndpointsByNamesArgs{ + Project: converter.String(projectID.String()), + EndpointNames: serviceEndpointNameList, + }, + ) + if err != nil { + return nil, err + } + + if len(*serviceEndpoints) == 0 { + return nil, fmt.Errorf("%v not found!", serviceEndpointName) + } + + if len(*serviceEndpoints) > 1 { + return nil, fmt.Errorf("%v returns more than one serviceEndpoint!", serviceEndpointName) + } + + return &(*serviceEndpoints)[0], nil +} diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go index fdbd63e9..5507acba 100644 --- a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go @@ -3,166 +3,27 @@ package serviceendpoint import ( "fmt" - "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/microsoft/azure-devops-go-api/azuredevops/v6/serviceendpoint" - "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/client" - "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils" - "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/converter" ) func DataServiceEndpointAzureRM() *schema.Resource { - return &schema.Resource{ - Read: dataSourceServiceEndpointAzureRMRead, - Schema: map[string]*schema.Schema{ - "project_id": { - Type: schema.TypeString, - Required: true, - }, - - "service_endpoint_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ExactlyOneOf: []string{"service_endpoint_name", "id"}, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "id": { - Description: "The ID of the serviceendpoint", - Type: schema.TypeString, - Optional: true, - Computed: true, - ExactlyOneOf: []string{"service_endpoint_name", "id"}, - ValidateFunc: validation.IsUUID, - }, - - "authorization": { - Type: schema.TypeMap, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "azurerm_management_group_id": { - Type: schema.TypeString, - Computed: true, - }, - - "azurerm_management_group_name": { - Type: schema.TypeString, - Computed: true, - }, - - "azurerm_subscription_id": { - Type: schema.TypeString, - Computed: true, - }, - - "azurerm_subscription_name": { - Type: schema.TypeString, - Computed: true, - }, - - "resource_group": { - Type: schema.TypeString, - Computed: true, - }, - - "azurerm_spn_tenantid": { - Type: schema.TypeString, - Computed: true, - }, - - "description": { - Type: schema.TypeString, - Computed: true, - }, - }, + r := dataSourceGenBaseServiceEndpointResource(dataSourceServiceEndpointAzureRMRead) + schemaKeys := []string{"azurerm_management_group_id", "azurerm_management_group_name", "azurerm_subscription_id", "azurerm_subscription_name", "resource_group", "azurerm_spn_tenantid"} + for _, k := range schemaKeys { + dataSourceMakeUnprotectedComputedSchema(r, k) } + return r } func dataSourceServiceEndpointAzureRMRead(d *schema.ResourceData, m interface{}) error { - clients := m.(*client.AggregatedClient) - - var projectID *uuid.UUID - projectIDString := d.Get("project_id").(string) - parsedProjectID, err := uuid.Parse(projectIDString) + serviceEndpoint, projectID, err := dataSourceGetBaseServiceEndpoint(d, m) if err != nil { - return fmt.Errorf("Error parsing projectID from the Terraform data source declaration: %v", err) + return err } - - projectID = &parsedProjectID - - if serviceEndpointIDString, ok := d.GetOk("id"); ok { - var serviceEndpointID *uuid.UUID - parsedServiceEndpointID, err := uuid.Parse(serviceEndpointIDString.(string)) - if err != nil { - return fmt.Errorf("Error parsing serviceEndpointID from the Terraform data source declaration: %v", err) - } - serviceEndpointID = &parsedServiceEndpointID - - serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails( - clients.Ctx, - serviceendpoint.GetServiceEndpointDetailsArgs{ - EndpointId: serviceEndpointID, - Project: converter.String(projectID.String()), - }, - ) - if err != nil { - if utils.ResponseWasNotFound(err) { - d.SetId("") - return nil - } - return fmt.Errorf("Error looking up service endpoint with ID (%v) and projectID (%v): %v", serviceEndpointID, projectID, err) - } - + if serviceEndpoint != nil { (*serviceEndpoint.Data)["creationMode"] = "" flattenServiceEndpointAzureRM(d, serviceEndpoint, projectID) return nil } - - if serviceEndpointName, ok := d.GetOk("service_endpoint_name"); ok { - // get service endpointdetails by name - serviceEndpoint, err := getServiceEndpointByNameAndProject(clients, serviceEndpointName.(string), projectID) - if err != nil { - if utils.ResponseWasNotFound(err) { - d.SetId("") - return nil - } - return fmt.Errorf("Error looking up service endpoint with name (%v) and projectID (%v): %v", serviceEndpointName, projectID, err) - } - - (*serviceEndpoint.Data)["creationMode"] = "" - flattenServiceEndpointAzureRM(d, serviceEndpoint, projectID) - return nil - } - return nil -} - -func getServiceEndpointByNameAndProject(clients *client.AggregatedClient, serviceEndpointName string, projectID *uuid.UUID) (*serviceendpoint.ServiceEndpoint, error) { - serviceEndpointNameList := &[]string{serviceEndpointName} - - serviceEndpoints, err := clients.ServiceEndpointClient.GetServiceEndpointsByNames( - clients.Ctx, - serviceendpoint.GetServiceEndpointsByNamesArgs{ - Project: converter.String(projectID.String()), - EndpointNames: serviceEndpointNameList, - }, - ) - if err != nil { - return nil, err - } - - if len(*serviceEndpoints) == 0 { - return nil, fmt.Errorf("%v not found!", serviceEndpointName) - } - - if len(*serviceEndpoints) > 1 { - return nil, fmt.Errorf("%v returns more than one serviceEndpoint!", serviceEndpointName) - } - - return &(*serviceEndpoints)[0], nil + return fmt.Errorf("Error looking up service endpoint!") } diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go new file mode 100644 index 00000000..c9677393 --- /dev/null +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go @@ -0,0 +1,24 @@ +package serviceendpoint + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataServiceEndpointGithub() *schema.Resource { + r := dataSourceGenBaseServiceEndpointResource(dataSourceServiceEndpointGithubRead) + return r +} + +func dataSourceServiceEndpointGithubRead(d *schema.ResourceData, m interface{}) error { + serviceEndpoint, projectID, err := dataSourceGetBaseServiceEndpoint(d, m) + if err != nil { + return err + } + if serviceEndpoint != nil { + doBaseFlattening(d, serviceEndpoint, projectID) + return nil + } + return fmt.Errorf("Error looking up service endpoint!") +} diff --git a/azuredevops/provider.go b/azuredevops/provider.go index b98c618f..f666b304 100644 --- a/azuredevops/provider.go +++ b/azuredevops/provider.go @@ -104,6 +104,7 @@ func Provider() *schema.Provider { "azuredevops_groups": graph.DataGroups(), "azuredevops_variable_group": taskagent.DataVariableGroup(), "azuredevops_serviceendpoint_azurerm": serviceendpoint.DataServiceEndpointAzureRM(), + "azuredevops_serviceendpoint_github": serviceendpoint.DataServiceEndpointGithub(), }, Schema: map[string]*schema.Schema{ "org_service_url": { diff --git a/website/azuredevops.erb b/website/azuredevops.erb index 52e64605..e095d76f 100644 --- a/website/azuredevops.erb +++ b/website/azuredevops.erb @@ -79,6 +79,9 @@
  • azuredevops_serviceendpoint_azurerm
  • +
  • + azuredevops_serviceendpoint_github +
  • diff --git a/website/docs/d/serviceendpoint_azurerm.html.markdown b/website/docs/d/serviceendpoint_azurerm.html.markdown index 14301c15..bde896ed 100644 --- a/website/docs/d/serviceendpoint_azurerm.html.markdown +++ b/website/docs/d/serviceendpoint_azurerm.html.markdown @@ -18,13 +18,13 @@ data "azuredevops_project" "sample" { name = "Sample Project" } -data "azuredevops_serviceendpoint_azurerm" "id" { +data "azuredevops_serviceendpoint_azurerm" "serviceendpoint" { project_id = data.azuredevops_project.sample.id id = "00000000-0000-0000-0000-000000000000" } output "service_endpoint_name" { - value = data.azuredevops_serviceendpoint_azurerm.service_endpoint_name + value = data.azuredevops_serviceendpoint_azurerm.serviceendpoint.service_endpoint_name } ``` @@ -35,13 +35,13 @@ data "azuredevops_project" "sample" { name = "Sample Project" } -data "azuredevops_serviceendpoint_azurerm" "id" { +data "azuredevops_serviceendpoint_azurerm" "serviceendpoint" { project_id = data.azuredevops_project.sample.id service_endpoint_name = "Example-Service-Endpoint" } output "service_endpoint_id" { - value = data.azuredevops_serviceendpoint_azurerm.id + value = data.azuredevops_serviceendpoint_azurerm.serviceendpoint.id } ``` @@ -56,6 +56,7 @@ The following arguments are supported: * `service_endpoint_name` - (Optional) the Name of the Service Endpoint. ~> **NOTE:** One of either `id` or `service_endpoint_name` must be specified. +~> **NOTE:** When supplying `service_endpoint_name`, take care to ensure that this is a unique name. ## Attributes Reference diff --git a/website/docs/d/serviceendpoint_github.html.markdown b/website/docs/d/serviceendpoint_github.html.markdown new file mode 100644 index 00000000..9030c167 --- /dev/null +++ b/website/docs/d/serviceendpoint_github.html.markdown @@ -0,0 +1,66 @@ +--- +layout: "azuredevops" +page_title: "AzureDevops: Data Source: azuredevops_serviceendpoint_github" +description: |- + Gets information about an existing AzureRM Service Endpoint. +--- + +# Data Source : azuredevops_serviceendpoint_github + +Use this data source to access information about an existing AzureRM service Endpoint. + +## Example Usage + +### By Service Endpoint ID + +```hcl +data "azuredevops_project" "sample" { + name = "Sample Project" +} + +data "azuredevops_serviceendpoint_github" "serviceendpoint" { + project_id = data.azuredevops_project.sample.id + id = "00000000-0000-0000-0000-000000000000" +} + +output "service_endpoint_name" { + value = data.azuredevops_serviceendpoint_github.serviceendpoint.service_endpoint_name +} +``` + +### By Service Endpoint Name + +```hcl +data "azuredevops_project" "sample" { + name = "Sample Project" +} + +data "azuredevops_serviceendpoint_github" "serviceendpoint" { + project_id = data.azuredevops_project.sample.id + service_endpoint_name = "Example-Service-Endpoint" +} + +output "service_endpoint_id" { + value = data.azuredevops_serviceendpoint_github.serviceendpoint.id +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `project_id` - (Required) The ID of the project. + +* `id` - (Optional) the ID of the Service Endpoint. + +* `service_endpoint_name` - (Optional) the Name of the Service Endpoint. + +~> **NOTE:** One of either `id` or `service_endpoint_name` must be specified. +~> **NOTE:** When supplying `service_endpoint_name`, take care to ensure that this is a unique name. + +## Attributes Reference + +In addition to the Arguments list above - the following Attributes are exported: + +* `authorization` - Specifies the Authorization Scheme Map. +* `description` - Specifies the description of the Service Endpoint. -- cgit v1.2.3 From 0662463c5122e314b9171cb98c32bc4a363fb7da Mon Sep 17 00:00:00 2001 From: Sharath Nair Date: Thu, 4 Aug 2022 15:36:19 +1000 Subject: Return projectID where possible --- azuredevops/internal/service/serviceendpoint/commons.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azuredevops/internal/service/serviceendpoint/commons.go b/azuredevops/internal/service/serviceendpoint/commons.go index cef17094..a0c5085d 100644 --- a/azuredevops/internal/service/serviceendpoint/commons.go +++ b/azuredevops/internal/service/serviceendpoint/commons.go @@ -481,7 +481,7 @@ func dataSourceGetBaseServiceEndpoint(d *schema.ResourceData, m interface{}) (*s return serviceEndpoint, projectID, nil } - return nil, nil, nil + return nil, projectID, nil } func dataSourceGetServiceEndpointByNameAndProject(clients *client.AggregatedClient, serviceEndpointName string, projectID *uuid.UUID) (*serviceendpoint.ServiceEndpoint, error) { -- cgit v1.2.3 From 3f8afc741bf8819c3d6a196604567d954bfc9c78 Mon Sep 17 00:00:00 2001 From: Sharath Nair Date: Thu, 4 Aug 2022 16:07:01 +1000 Subject: Add new datasource to provider_test.go --- azuredevops/provider_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azuredevops/provider_test.go b/azuredevops/provider_test.go index d14edeba..78fb2b3a 100644 --- a/azuredevops/provider_test.go +++ b/azuredevops/provider_test.go @@ -100,6 +100,7 @@ func TestProvider_HasChildDataSources(t *testing.T) { "azuredevops_groups", "azuredevops_variable_group", "azuredevops_serviceendpoint_azurerm", + "azuredevops_serviceendpoint_github", } dataSources := Provider().DataSourcesMap -- cgit v1.2.3 From 49e08bff21b443ee8653d9e7efdffbf4d8495708 Mon Sep 17 00:00:00 2001 From: Sharath Nair Date: Fri, 19 Aug 2022 17:06:39 +1000 Subject: Incorporate comments and fixes --- .../acceptancetests/data_serviceendpoint_azurerm_test.go | 4 ++-- .../acceptancetests/data_serviceendpoint_github_test.go | 4 ++-- azuredevops/internal/acceptancetests/testutils/hcl.go | 4 ++-- azuredevops/internal/service/serviceendpoint/commons.go | 8 ++++---- .../service/serviceendpoint/data_serviceendpoint_azurerm.go | 1 + .../service/serviceendpoint/data_serviceendpoint_github.go | 1 + website/docs/d/serviceendpoint_azurerm.html.markdown | 6 +++--- website/docs/d/serviceendpoint_github.html.markdown | 10 +++++----- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_azurerm_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_azurerm_test.go index 2ede34db..3fdb4f96 100644 --- a/azuredevops/internal/acceptancetests/data_serviceendpoint_azurerm_test.go +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_azurerm_test.go @@ -32,7 +32,7 @@ func TestAccServiceEndpointAzureRM_with_serviceEndpointID_DataSource(t *testing. Config: createServiceEndpointAzureRMWithServiceEndpointIDData, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointAzureRMName), - resource.TestCheckResourceAttrSet(tfNode, "id"), + resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"), ), }, }, @@ -58,7 +58,7 @@ func TestAccServiceEndpointAzureRM_with_serviceEndpointName_DataSource(t *testin Config: createServiceEndpointAzureRMWithServiceEndpointNameData, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointAzureRMName), - resource.TestCheckResourceAttrSet(tfNode, "id"), + resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"), ), }, }, diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go index 2c16e550..aa468508 100644 --- a/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_github_test.go @@ -29,7 +29,7 @@ func TestAccServiceEndpointGitHub_with_serviceEndpointID_DataSource(t *testing.T Config: createServiceEndpointGitHubWithServiceEndpointIDData, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointGitHubName), - resource.TestCheckResourceAttrSet(tfNode, "id"), + resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"), ), }, }, @@ -53,7 +53,7 @@ func TestAccServiceEndpointGitHub_with_serviceEndpointName_DataSource(t *testing Config: createServiceEndpointGitHubWithServiceEndpointNameData, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointGitHubName), - resource.TestCheckResourceAttrSet(tfNode, "id"), + resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"), ), }, }, diff --git a/azuredevops/internal/acceptancetests/testutils/hcl.go b/azuredevops/internal/acceptancetests/testutils/hcl.go index 036ef5b9..377ec3d3 100644 --- a/azuredevops/internal/acceptancetests/testutils/hcl.go +++ b/azuredevops/internal/acceptancetests/testutils/hcl.go @@ -256,7 +256,7 @@ func HclServiceEndpointGitHubDataSourceWithServiceEndpointID() string { serviceEndpointDataSource := fmt.Sprintf(` data "azuredevops_serviceendpoint_github" "serviceendpoint" { project_id = azuredevops_project.project.id - id = azuredevops_serviceendpoint_github.serviceendpoint.id + service_endpoint_id = azuredevops_serviceendpoint_github.serviceendpoint.id } `) return fmt.Sprintf("%s", serviceEndpointDataSource) @@ -428,7 +428,7 @@ func HclServiceEndpointAzureRMDataSourceWithServiceEndpointID() string { serviceEndpointDataSource := fmt.Sprintf(` data "azuredevops_serviceendpoint_azurerm" "serviceendpointrm" { project_id = azuredevops_project.project.id - id = azuredevops_serviceendpoint_azurerm.serviceendpointrm.id + service_endpoint_id = azuredevops_serviceendpoint_azurerm.serviceendpointrm.id } `) return fmt.Sprintf("%s", serviceEndpointDataSource) diff --git a/azuredevops/internal/service/serviceendpoint/commons.go b/azuredevops/internal/service/serviceendpoint/commons.go index a0c5085d..5069f804 100644 --- a/azuredevops/internal/service/serviceendpoint/commons.go +++ b/azuredevops/internal/service/serviceendpoint/commons.go @@ -395,16 +395,16 @@ func dataSourceGenBaseServiceEndpointResource(dataSourceReadFunc schema.ReadFunc Type: schema.TypeString, Optional: true, Computed: true, - ExactlyOneOf: []string{"service_endpoint_name", "id"}, + ExactlyOneOf: []string{"service_endpoint_name", "service_endpoint_id"}, ValidateFunc: validation.StringIsNotEmpty, }, - "id": { + "service_endpoint_id": { Description: "The ID of the serviceendpoint", Type: schema.TypeString, Optional: true, Computed: true, - ExactlyOneOf: []string{"service_endpoint_name", "id"}, + ExactlyOneOf: []string{"service_endpoint_name", "service_endpoint_id"}, ValidateFunc: validation.IsUUID, }, @@ -443,7 +443,7 @@ func dataSourceGetBaseServiceEndpoint(d *schema.ResourceData, m interface{}) (*s projectID = &parsedProjectID - if serviceEndpointIDString, ok := d.GetOk("id"); ok { + if serviceEndpointIDString, ok := d.GetOk("service_endpoint_id"); ok { var serviceEndpointID *uuid.UUID parsedServiceEndpointID, err := uuid.Parse(serviceEndpointIDString.(string)) if err != nil { diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go index 5507acba..a50b1f54 100644 --- a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_azurerm.go @@ -22,6 +22,7 @@ func dataSourceServiceEndpointAzureRMRead(d *schema.ResourceData, m interface{}) } if serviceEndpoint != nil { (*serviceEndpoint.Data)["creationMode"] = "" + d.Set("service_endpoint_id", serviceEndpoint.Id.String()) flattenServiceEndpointAzureRM(d, serviceEndpoint, projectID) return nil } diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go index c9677393..7cccc100 100644 --- a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_github.go @@ -17,6 +17,7 @@ func dataSourceServiceEndpointGithubRead(d *schema.ResourceData, m interface{}) return err } if serviceEndpoint != nil { + d.Set("service_endpoint_id", serviceEndpoint.Id.String()) doBaseFlattening(d, serviceEndpoint, projectID) return nil } diff --git a/website/docs/d/serviceendpoint_azurerm.html.markdown b/website/docs/d/serviceendpoint_azurerm.html.markdown index bde896ed..b233667f 100644 --- a/website/docs/d/serviceendpoint_azurerm.html.markdown +++ b/website/docs/d/serviceendpoint_azurerm.html.markdown @@ -20,7 +20,7 @@ data "azuredevops_project" "sample" { data "azuredevops_serviceendpoint_azurerm" "serviceendpoint" { project_id = data.azuredevops_project.sample.id - id = "00000000-0000-0000-0000-000000000000" + service_endpoint_id = "00000000-0000-0000-0000-000000000000" } output "service_endpoint_name" { @@ -51,11 +51,11 @@ The following arguments are supported: * `project_id` - (Required) The ID of the project. -* `id` - (Optional) the ID of the Service Endpoint. +* `service_endpoint_id` - (Optional) the ID of the Service Endpoint. * `service_endpoint_name` - (Optional) the Name of the Service Endpoint. -~> **NOTE:** One of either `id` or `service_endpoint_name` must be specified. +~> **NOTE:** One of either `service_endpoint_id` or `service_endpoint_name` must be specified. ~> **NOTE:** When supplying `service_endpoint_name`, take care to ensure that this is a unique name. ## Attributes Reference diff --git a/website/docs/d/serviceendpoint_github.html.markdown b/website/docs/d/serviceendpoint_github.html.markdown index 9030c167..f35d6ec2 100644 --- a/website/docs/d/serviceendpoint_github.html.markdown +++ b/website/docs/d/serviceendpoint_github.html.markdown @@ -2,12 +2,12 @@ layout: "azuredevops" page_title: "AzureDevops: Data Source: azuredevops_serviceendpoint_github" description: |- - Gets information about an existing AzureRM Service Endpoint. + Gets information about an existing GitHub Service Endpoint. --- # Data Source : azuredevops_serviceendpoint_github -Use this data source to access information about an existing AzureRM service Endpoint. +Use this data source to access information about an existing GitHub service Endpoint. ## Example Usage @@ -20,7 +20,7 @@ data "azuredevops_project" "sample" { data "azuredevops_serviceendpoint_github" "serviceendpoint" { project_id = data.azuredevops_project.sample.id - id = "00000000-0000-0000-0000-000000000000" + service_endpoint_id = "00000000-0000-0000-0000-000000000000" } output "service_endpoint_name" { @@ -51,11 +51,11 @@ The following arguments are supported: * `project_id` - (Required) The ID of the project. -* `id` - (Optional) the ID of the Service Endpoint. +* `service_endpoint_id` - (Optional) the ID of the Service Endpoint. * `service_endpoint_name` - (Optional) the Name of the Service Endpoint. -~> **NOTE:** One of either `id` or `service_endpoint_name` must be specified. +~> **NOTE:** One of either `service_endpoint_id` or `service_endpoint_name` must be specified. ~> **NOTE:** When supplying `service_endpoint_name`, take care to ensure that this is a unique name. ## Attributes Reference -- cgit v1.2.3 From 488f34861ff8d6baaa682221eee972351f191f58 Mon Sep 17 00:00:00 2001 From: xuzhang3 Date: Thu, 25 Aug 2022 11:12:41 +0800 Subject: format --- website/docs/d/serviceendpoint_azurerm.html.markdown | 4 ++-- website/docs/d/serviceendpoint_github.html.markdown | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/d/serviceendpoint_azurerm.html.markdown b/website/docs/d/serviceendpoint_azurerm.html.markdown index b233667f..42474e0b 100644 --- a/website/docs/d/serviceendpoint_azurerm.html.markdown +++ b/website/docs/d/serviceendpoint_azurerm.html.markdown @@ -19,8 +19,8 @@ data "azuredevops_project" "sample" { } data "azuredevops_serviceendpoint_azurerm" "serviceendpoint" { - project_id = data.azuredevops_project.sample.id - service_endpoint_id = "00000000-0000-0000-0000-000000000000" + project_id = data.azuredevops_project.sample.id + service_endpoint_id = "00000000-0000-0000-0000-000000000000" } output "service_endpoint_name" { diff --git a/website/docs/d/serviceendpoint_github.html.markdown b/website/docs/d/serviceendpoint_github.html.markdown index f35d6ec2..c6dff6d6 100644 --- a/website/docs/d/serviceendpoint_github.html.markdown +++ b/website/docs/d/serviceendpoint_github.html.markdown @@ -19,8 +19,8 @@ data "azuredevops_project" "sample" { } data "azuredevops_serviceendpoint_github" "serviceendpoint" { - project_id = data.azuredevops_project.sample.id - service_endpoint_id = "00000000-0000-0000-0000-000000000000" + project_id = data.azuredevops_project.sample.id + service_endpoint_id = "00000000-0000-0000-0000-000000000000" } output "service_endpoint_name" { -- cgit v1.2.3