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

Data source azuredevops_serviceendpoint_npm #795

Merged
merged 3 commits into from
Jun 21, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//go:build (all || data_sources || data_serviceendpoint_npm) && (!exclude_data_sources || !exclude_data_serviceendpoint_npm)
// +build all data_sources data_serviceendpoint_npm
// +build !exclude_data_sources !exclude_data_serviceendpoint_npm

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 TestAccServiceEndpointNpn_DataSource(t *testing.T) {
name := testutils.GenerateResourceName()

tfNode := "data.azuredevops_serviceendpoint_npm.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclServiceEndpointNpmDataSource(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", name),
),
},
},
})
}

func hclServiceEndpointNpmDataSource(name string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}

resource "azuredevops_serviceendpoint_npm" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = "%[1]s"
access_token = "redacted"
url = "http://url.com/"
}

data "azuredevops_serviceendpoint_npm" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = azuredevops_serviceendpoint_npm.test.service_endpoint_name
}
`, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package serviceendpoint

import (
"fmt"

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

func DataResourceServiceEndpointNpm() *schema.Resource {
r := dataSourceGenBaseServiceEndpointResource(dataSourceServiceEndpointNpmRead)

r.Schema["url"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
}

return r
}

func dataSourceServiceEndpointNpmRead(d *schema.ResourceData, m interface{}) error {
serviceEndpoint, projectID, err := dataSourceGetBaseServiceEndpoint(d, m)
if err != nil {
return err
}
if serviceEndpoint != nil {
doBaseFlattening(d, serviceEndpoint, projectID)
d.Set("url", serviceEndpoint.Url)

return nil
}
return fmt.Errorf("Error looking up service endpoint!")
}
1 change: 1 addition & 0 deletions azuredevops/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func Provider() *schema.Provider {
"azuredevops_variable_group": taskagent.DataVariableGroup(),
"azuredevops_serviceendpoint_azurerm": serviceendpoint.DataServiceEndpointAzureRM(),
"azuredevops_serviceendpoint_github": serviceendpoint.DataServiceEndpointGithub(),
"azuredevops_serviceendpoint_npm": serviceendpoint.DataResourceServiceEndpointNpm(),
},
Schema: map[string]*schema.Schema{
"org_service_url": {
Expand Down
1 change: 1 addition & 0 deletions azuredevops/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func TestProvider_HasChildDataSources(t *testing.T) {
"azuredevops_variable_group",
"azuredevops_serviceendpoint_azurerm",
"azuredevops_serviceendpoint_github",
"azuredevops_serviceendpoint_npm",
}

dataSources := Provider().DataSourcesMap
Expand Down
3 changes: 3 additions & 0 deletions website/azuredevops.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
<li>
<a href="/docs/providers/azuredevops/d/serviceendpoint_github.html">azuredevops_serviceendpoint_github</a>
</li>
<li>
<a href="/docs/providers/azuredevops/d/serviceendpoint_npm.html">azuredevops_serviceendpoint_npm</a>
</li>
</ul>
</li>

Expand Down
45 changes: 45 additions & 0 deletions website/docs/d/serviceendpoint_npm.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: "azuredevops"
page_title: "AzureDevops: azuredevops_serviceendpoint_npm"
description: |-
Gets information about an existing NPM Service Endpoint.
---

# Data Source : azuredevops_serviceendpoint_npm

Use this data source to access information about an existing NPM Service Endpoint.

## Example Usage

```hcl
data "azuredevops_serviceendpoint_npm" "example" {
project_id = azuredevops_project.example.id
service_endpoint_name = "Example npm"
}

output "service_endpoint_id" {
value = data.azuredevops_serviceendpoint_npm.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `project_id` - (Required) The ID of the project.

* `service_endpoint_id` - (Optional) the ID of the Service Endpoint.

* `service_endpoint_name` - (Optional) the Name of the Service Endpoint.

~> **NOTE:** One of either `service_endpoint_id` or `service_endpoint_name` must be specified.


## Attributes Reference

In addition to the Arguments list above - the following Attributes are exported:

* `authorization` - Specifies the Authorization Scheme Map.
* `url` - Specifies the URL of the npm registry to connect with.
* `description` - Specifies the description of the Service Endpoint.