-
Notifications
You must be signed in to change notification settings - Fork 317
Custom service endpoint support #683
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
825478a
5bf9f22
05b0d52
905375b
48e9c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package serviceendpoint | ||
|
|
||
| import ( | ||
| "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/utils/converter" | ||
| "github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/tfhelper" | ||
| ) | ||
|
|
||
| // ResourceServiceEndpointCustom schema and implementation for Custom service endpoint resource | ||
| func ResourceServiceEndpointCustom() *schema.Resource { | ||
| r := genBaseServiceEndpointResource(flattenServiceEndpointCustom, expandServiceEndpointCustom) | ||
| r.Schema["service_type"] = &schema.Schema{ | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: "The Service Type of the Custom service connection.", | ||
| } | ||
| r.Schema["server_url"] = &schema.Schema{ | ||
| Type: schema.TypeString, | ||
| ValidateFunc: validation.IsURLWithHTTPorHTTPS, | ||
| Required: true, | ||
| Description: "The server URL of the Custom service connection.", | ||
| } | ||
| r.Schema["username"] = &schema.Schema{ | ||
| Type: schema.TypeString, | ||
| DefaultFunc: schema.EnvDefaultFunc("AZDO_CUSTOM_SERVICE_CONNECTION_USERNAME", nil), | ||
| Description: "The username to use for the Custom service connection.", | ||
| Optional: true, | ||
| } | ||
| r.Schema["password"] = &schema.Schema{ | ||
| Type: schema.TypeString, | ||
| DefaultFunc: schema.EnvDefaultFunc("AZDO_CUSTOM_SERVICE_CONNECTION_PASSWORD", nil), | ||
| Description: "The password or token key to use for the Custom service connection.", | ||
| Sensitive: true, | ||
| Optional: true, | ||
| DiffSuppressFunc: tfhelper.DiffFuncSuppressSecretChanged, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recommend remove the |
||
| } | ||
| r.Schema["data"] = &schema.Schema{ | ||
| Type: schema.TypeMap, | ||
| Description: "Optional payload required for the creation of the endpoint", | ||
| } | ||
| secretHashKey, secretHashSchema := tfhelper.GenerateSecreteMemoSchema("password") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hash keys can be deleted. This functions has be deprecated. |
||
| r.Schema[secretHashKey] = secretHashSchema | ||
| return r | ||
| } | ||
|
|
||
| func expandServiceEndpointCustom(d *schema.ResourceData) (*serviceendpoint.ServiceEndpoint, *uuid.UUID, error) { | ||
| serviceEndpoint, projectID := doBaseExpansion(d) | ||
| serviceEndpoint.Type = converter.String(d.Get("service_type").(string)) | ||
| serviceEndpoint.Url = converter.String(d.Get("server_url").(string)) | ||
| serviceEndpoint.Authorization = &serviceendpoint.EndpointAuthorization{ | ||
| Parameters: &map[string]string{ | ||
| "username": d.Get("username").(string), | ||
| "password": d.Get("password").(string), | ||
| }, | ||
| Scheme: converter.String("UsernamePassword"), | ||
| } | ||
| serviceEndpoint.Data = d.Get("data").(*map[string]string) | ||
| return serviceEndpoint, projectID, nil | ||
| } | ||
|
|
||
| func flattenServiceEndpointCustom(d *schema.ResourceData, serviceEndpoint *serviceendpoint.ServiceEndpoint, projectID *uuid.UUID) { | ||
| doBaseFlattening(d, serviceEndpoint, projectID) | ||
| d.Set("service_type", *serviceEndpoint.Type) | ||
| d.Set("server_url", *serviceEndpoint.Url) | ||
| d.Set("username", (*serviceEndpoint.Authorization.Parameters)["username"]) | ||
| d.Set("data", *serviceEndpoint.Data) | ||
| tfhelper.HelpFlattenSecret(d, "password") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| layout: "azuredevops" | ||
| page_title: "AzureDevops: azuredevops_serviceendpoint_custom" | ||
| description: |- | ||
| Manages a custom service endpoint within Azure DevOps, which can be used to authenticate to any external server using | ||
| basic authentication via a username and password. | ||
| --- | ||
|
|
||
| # azuredevops_serviceendpoint_custom | ||
|
|
||
| Manages a custom service endpoint within Azure DevOps, which can be used to authenticate to any external server using | ||
| basic authentication via a username and password. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```hcl | ||
| resource "azuredevops_project" "example" { | ||
| name = "Example Project" | ||
| visibility = "private" | ||
| version_control = "Git" | ||
| work_item_template = "Agile" | ||
| description = "Managed by Terraform" | ||
| } | ||
|
|
||
| resource "azuredevops_serviceendpoint_custom" "example" { | ||
| project_id = azuredevops_project.example.id | ||
| service_type = "custom type name" | ||
| server_url = "https://some-server.example.com" | ||
| username = "username" | ||
| password = "password" | ||
| service_endpoint_name = "Example Generic" | ||
| description = "Managed by Terraform" | ||
| } | ||
| ``` | ||
|
|
||
| ## Argument Reference | ||
|
|
||
| The following arguments are supported: | ||
|
|
||
| - `project_id` - (Required) The ID of the project. | ||
| - `service_endpoint_name` - (Required) The service endpoint name. | ||
| - `service_type` - (Required) The Service Type of the server associated with the service endpoint. | ||
| - `server_url` - (Required) The URL of the server associated with the service endpoint. | ||
| - `username` - (Optional) The username used to authenticate to the server url using basic authentication. | ||
| - `password` - (Optional) The password or token key used to authenticate to the server url using basic authentication. | ||
| - `description` - (Optional) The Service Endpoint description. Defaults to `Managed by Terraform`. | ||
|
|
||
| Obs.: Access [Azure DevOps Service REST API 7.1 - Service Endpoints Types List](https://dev.azure.com/{organization}/_apis/serviceendpoint/types?api-version=7.1-preview.1) to get the Type. | ||
|
|
||
| ## Attributes Reference | ||
|
|
||
| The following attributes are exported: | ||
|
|
||
| - `id` - The ID of the service endpoint. | ||
| - `project_id` - The ID of the project. | ||
| - `service_endpoint_name` - The name of the service endpoint. | ||
|
|
||
| ## Relevant Links | ||
|
|
||
| - [Azure DevOps Service REST API 6.0 - Service Endpoints](https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints?view=azure-devops-rest-6.0) | ||
| - [Azure DevOps Service REST API 7.1 - Service Endpoints Types List](https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/types/list?view=azure-devops-rest-7.1&tabs=HTTP) | ||
|
|
||
| ## Import | ||
|
|
||
| Azure DevOps Service Endpoint Generic can be imported using **projectID/serviceEndpointID** or | ||
| **projectName/serviceEndpointID** | ||
|
|
||
| ```sh | ||
| terraform import azuredevops_serviceendpoint_custom.example 00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000 | ||
| ``` |
Uh oh!
There was an error while loading. Please reload this page.