diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_artifactory_v2_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_artifactory_v2_test.go new file mode 100644 index 000000000..2ec550e02 --- /dev/null +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_artifactory_v2_test.go @@ -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" { + 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) +} diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_distribution_v2_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_distribution_v2_test.go new file mode 100644 index 000000000..744d108a6 --- /dev/null +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_distribution_v2_test.go @@ -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) +} diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_platform_v2_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_platform_v2_test.go new file mode 100644 index 000000000..79c01f0d2 --- /dev/null +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_platform_v2_test.go @@ -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) +} diff --git a/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_xray_v2_test.go b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_xray_v2_test.go new file mode 100644 index 000000000..bd76a04ac --- /dev/null +++ b/azuredevops/internal/acceptancetests/data_serviceendpoint_jfrog_xray_v2_test.go @@ -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) +} diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_artifactory_v2.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_artifactory_v2.go new file mode 100644 index 000000000..0751788a1 --- /dev/null +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_artifactory_v2.go @@ -0,0 +1,56 @@ +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" +) + +// 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, + }, + }, + }) + + return r +} + +func DataSourceServiceEndpointJFrogArtifactoryV2Read(d *schema.ResourceData, m interface{}) error { + clients := m.(*client.AggregatedClient) + getArgs, err := serviceEndpointGetArgs(d) + if err != nil { + return err + } + + serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails(clients.Ctx, *getArgs) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil + } + return fmt.Errorf(" looking up service endpoint given ID (%v) and project ID (%v): %v", getArgs.EndpointId, getArgs.Project, err) + } + + if err = checkServiceConnection(serviceEndpoint); err != nil { + return err + } + d.Set("url", serviceEndpoint.Url) + return nil +} diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_distribution_v2.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_distribution_v2.go new file mode 100644 index 000000000..7f7c6e41c --- /dev/null +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_distribution_v2.go @@ -0,0 +1,54 @@ +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" +) + +// 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 { + clients := m.(*client.AggregatedClient) + getArgs, err := serviceEndpointGetArgs(d) + if err != nil { + return err + } + + serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails(clients.Ctx, *getArgs) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil + } + return fmt.Errorf(" looking up service endpoint given ID (%v) and project ID (%v): %v", getArgs.EndpointId, getArgs.Project, err) + } + + if err = checkServiceConnection(serviceEndpoint); err != nil { + return err + } + d.Set("url", serviceEndpoint.Url) + return nil +} diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_platform_v2.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_platform_v2.go new file mode 100644 index 000000000..e9f2079eb --- /dev/null +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_platform_v2.go @@ -0,0 +1,55 @@ +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" +) + +// 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 { + clients := m.(*client.AggregatedClient) + getArgs, err := serviceEndpointGetArgs(d) + if err != nil { + return err + } + + serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails(clients.Ctx, *getArgs) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil + } + return fmt.Errorf(" looking up service endpoint given ID (%v) and project ID (%v): %v", getArgs.EndpointId, getArgs.Project, err) + } + + if err = checkServiceConnection(serviceEndpoint); err != nil { + return err + } + d.Set("url", serviceEndpoint.Url) + return nil +} diff --git a/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_xray_v2.go b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_xray_v2.go new file mode 100644 index 000000000..bd3d5055e --- /dev/null +++ b/azuredevops/internal/service/serviceendpoint/data_serviceendpoint_jfrog_xray_v2.go @@ -0,0 +1,55 @@ +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" +) + +// DataSourceServiceEndpointJFrogXRayV2 schema and implementation for JFrog XRay service endpoint resource +func DataSourceServiceEndpointJFrogXRayV2() *schema.Resource { + r := &schema.Resource{ + Read: DataSourceServiceEndpointJFrogXRayV2Read, + 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 DataSourceServiceEndpointJFrogXRayV2Read(d *schema.ResourceData, m interface{}) error { + clients := m.(*client.AggregatedClient) + getArgs, err := serviceEndpointGetArgs(d) + if err != nil { + return err + } + + serviceEndpoint, err := clients.ServiceEndpointClient.GetServiceEndpointDetails(clients.Ctx, *getArgs) + if err != nil { + if utils.ResponseWasNotFound(err) { + d.SetId("") + return nil + } + return fmt.Errorf(" looking up service endpoint given ID (%v) and project ID (%v): %v", getArgs.EndpointId, getArgs.Project, err) + } + + if err = checkServiceConnection(serviceEndpoint); err != nil { + return err + } + d.Set("url", serviceEndpoint.Url) + return nil +} diff --git a/website/azuredevops.erb b/website/azuredevops.erb index 1f5969a53..b40c2d116 100644 --- a/website/azuredevops.erb +++ b/website/azuredevops.erb @@ -94,6 +94,18 @@