Skip to content

Feature: Add JFrog V2 Service Endpoint Data Source (Issue #1231) #1232

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
123392b
feat: add jfrog v2 serviceendpoint data resources
jasonouellet Nov 19, 2024
cf06f39
feat: add jfrog v2 data doc
jasonouellet Nov 19, 2024
9cc5d07
add: jfrog v2 data to provider
jasonouellet Nov 19, 2024
2591e83
add: acceptance tests
jasonouellet Dec 10, 2024
dd87c4c
fix: code review comments
jasonouellet Dec 20, 2024
f78778e
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
c46f5d5
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
928db8c
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
ac246f1
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
ebeaa67
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
d2e418a
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 12, 2025
ed6989c
Update website/docs/d/serviceendpoint_jfrog_artifactory_v2.html.markdown
jasonouellet Jan 12, 2025
2b42bd1
Update website/docs/d/serviceendpoint_jfrog_distribution_v2.markdown
jasonouellet Jan 12, 2025
63ecf0a
Update website/docs/d/serviceendpoint_jfrog_platform_v2.markdown
jasonouellet Jan 12, 2025
b8fcc20
Update website/docs/d/serviceendpoint_jfrog_xray_v2.html.markdown
jasonouellet Jan 13, 2025
799f6c3
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 13, 2025
baea2b2
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet Jan 13, 2025
c319bb0
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
3f1ef56
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
3ddf396
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
dc61358
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
532aae1
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
f3317fa
Merge branch 'microsoft:main' into feature/jfrog_v2_data
jasonouellet May 5, 2025
9edc989
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
c0ddf88
Update azuredevops/internal/service/serviceendpoint/data_serviceendpo…
jasonouellet May 5, 2025
738c25c
Apply suggestions from code review
jasonouellet May 5, 2025
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,55 @@
//go:build (all || data_sources || data_serviceendpoint_jfrog_artifactory_v2) && (!exclude_data_sources || !exclude_data_serviceendpoint_jfrog_artifactory_v2)
// +build all data_sources data_serviceendpoint_jfrog_artifactory_v2
// +build !exclude_data_sources !exclude_data_serviceendpoint_jfrog_artifactory_v2

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

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

func hclServiceEndpointJfrogArtifactoryV2DataSource(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_jfrog_artifactory_v2" "test" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This HCL is not configured correctly.

project_id = azuredevops_project.test.id
service_endpoint_name = "%[1]s"
token = "0000000000000000000000000000000000000000"
description = "Managed by Terraform"
}

data "azuredevops_serviceendpoint_jfrog_artifactory_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = azuredevops_serviceendpoint_jfrog_artifactory_v2.test.service_endpoint_name
}
`, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build (all || data_sources || data_serviceendpoint_jfrog_distribution_v2) && (!exclude_data_sources || !exclude_data_serviceendpoint_jfrog_distribution_v2)
// +build all data_sources data_serviceendpoint_jfrog_distribution_v2
// +build !exclude_data_sources !exclude_data_serviceendpoint_jfrog_distribution_v2

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

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

func hclServiceEndpointJfrogDistributionV2DataSource(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_jfrog_distribution_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = "%[1]s"
token = "0000000000000000000000000000000000000000"
description = "Managed by Terraform"
}

data "azuredevops_serviceendpoint_jfrog_distribution_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = azuredevops_serviceendpoint_jfrog_distribution_v2.test.service_endpoint_name
}
`, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build (all || data_sources || data_serviceendpoint_jfrog_platform_v2) && (!exclude_data_sources || !exclude_data_serviceendpoint_jfrog_platform_v2)
// +build all data_sources data_serviceendpoint_jfrog_platform_v2
// +build !exclude_data_sources !exclude_data_serviceendpoint_jfrog_platform_v2

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

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

func hclServiceEndpointJfrogPlatformV2DataSource(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_jfrog_platform_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = "%[1]s"
token = "0000000000000000000000000000000000000000"
description = "Managed by Terraform"
}

data "azuredevops_serviceendpoint_jfrog_platform_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = azuredevops_serviceendpoint_jfrog_platform_v2.test.service_endpoint_name
}
`, name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build (all || data_sources || data_serviceendpoint_jfrog_xray_v2) && (!exclude_data_sources || !exclude_data_serviceendpoint_jfrog_xray_v2)
// +build all data_sources data_serviceendpoint_jfrog_xray_v2
// +build !exclude_data_sources !exclude_data_serviceendpoint_jfrog_xray_v2

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

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

func hclServiceEndpointJfrogXrayV2DataSource(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_jfrog_xray_v2" "test" {
project_id = azuredevops_project.test.id
service_endpoint_name = "%[1]s"
token = "0000000000000000000000000000000000000000"
description = "Managed by Terraform"
}

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

import (
"fmt"
"maps"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"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/validate"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not used.

)

// DataSourceServiceEndpointJFrogArtifactoryV2 schema and implementation for JFrog Artifactory service endpoint resource
func DataSourceServiceEndpointJFrogArtifactoryV2() *schema.Resource {
r := &schema.Resource{
Read: DataSourceServiceEndpointJFrogArtifactoryV2Read,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(1 * time.Minute),
},
Schema: dataSourceGenBaseSchema(),
}

maps.Copy(r.Schema, map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary },

},
})

return r
}

func DataSourceServiceEndpointJFrogArtifactoryV2Read(d *schema.ResourceData, m interface{}) error {
serviceEndpoint, err := dataSourceGetBaseServiceEndpoint(d, m)
if err != nil {
return err
}

if err = checkServiceConnection(serviceEndpoint); err != nil {
return err
}
doBaseFlattening(d, serviceEndpoint)
d.Set("url", serviceEndpoint.Url)
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package serviceendpoint

import (
"fmt"
"maps"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"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/validate"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not used.

)

// DataSourceServiceEndpointJFrogDistributionV2 schema and implementation for JFrog Distribution service endpoint resource
func DataSourceServiceEndpointJFrogDistributionV2() *schema.Resource {
r := &schema.Resource{
Read: DataSourceServiceEndpointJFrogDistributionV2Read,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(1 * time.Minute),
},
Schema: dataSourceGenBaseSchema(),
}
maps.Copy(r.Schema, map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Computed: true,
},
})

return r
}

func DataSourceServiceEndpointJFrogDistributionV2Read(d *schema.ResourceData, m interface{}) error {
serviceEndpoint, err := dataSourceGetBaseServiceEndpoint(d, m)
if err != nil {
return err
}

if err = checkServiceConnection(serviceEndpoint); err != nil {
return err
}
doBaseFlattening(d, serviceEndpoint)
d.Set("url", serviceEndpoint.Url)
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package serviceendpoint

import (
"fmt"
"maps"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"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/validate"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not used.

)

// DataSourceServiceEndpointJFrogPlatformV2 schema and implementation for JFrog Platform service endpoint resource
func DataSourceServiceEndpointJFrogPlatformV2() *schema.Resource {
r := &schema.Resource{
Read: DataSourceServiceEndpointJFrogPlatformV2Read,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(1 * time.Minute),
},
Schema: dataSourceGenBaseSchema(),
}

maps.Copy(r.Schema, map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Computed: true,
},
})

return r
}

func DataSourceServiceEndpointJFrogPlatformV2Read(d *schema.ResourceData, m interface{}) error {
serviceEndpoint, err := dataSourceGetBaseServiceEndpoint(d, m)
if err != nil {
return err
}

if err = checkServiceConnection(serviceEndpoint); err != nil {
return err
}
doBaseFlattening(d, serviceEndpoint)
d.Set("url", serviceEndpoint.Url)
return nil
}
Loading