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

Add support for Azure DevOps RunPipelines service endpoint #184

Merged

Conversation

zhmurko
Copy link
Contributor

@zhmurko zhmurko commented Sep 11, 2020

All Submissions:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code follows the code style of this project.
  • I ran lint checks locally prior to submission.
  • Have you checked to ensure there aren't other open PRs for the same update/change?

What about the current behavior has changed?

This pull request introduces a new resource azuredevops_serviceendpoint_devops that allows to manage Azure DevOps Service Connection. This connection is used to trigger subsequent builds from Azure Pipelines with task: RunPipelines@1 yaml definition.

Fix for Issue Number: #182

Does this introduce a change to go.mod, go.sum or vendor/?

  • Yes
  • No

Does this introduce a breaking change?

  • Yes
  • No

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Other information

@ghost
Copy link

ghost commented Sep 11, 2020

CLA assistant check
All CLA requirements met.

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 11, 2020

build has failed by 60 minutes timeout. need a rebuild or increase azdo job timeout.

@xuzhang3
Copy link
Collaborator

@zhmurko Is 'azdoapi' a new devops extension developed by your team? I cannot find an extension type azdoapi . If you means Azure Repos/Team Foundation Server, the type should be externaltfs
image

Error message:

--- FAIL: TestAccServiceEndpointAzureDevOps_PersonalTokenBasic (24.82s)
    testing.go:673: Step 0 error: errors during apply:
        
        Error: Error creating service endpoint in Azure DevOps: Unable to find service connection type 'azdoapi' using authentication scheme 'Token'.
        
          on /tmp/tf-test450287256/main.tf line 10:
          (source code not available)

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 14, 2020

hello @xuzhang3 thank you for looking into this issue.
I was pretty sure that's generally pre-installed type of Service Connection, but it turns out that it's one of Extensions installed from Marketplace manually: CSE-DevOps.RunPipelines
The "azdoapi" is a type of "Azure DevOps Service Connection" as shown on the screenshot below:

The value was picked up from API call to https://dev.azure.com/my-org-name/_apis/serviceendpoint/endpoints on save action via UI on Azure DevOps Cloud portal.
We use this service connection to trigger subsequent builds from YAML pipelines and really desire to create such endpoints with Terraform code altogether with the infrastructure.

@xuzhang3 xuzhang3 self-assigned this Sep 15, 2020
Azure DevOps Service Endpoint can be imported using the serviceendpoint id (resourceId in your browser's url bar), e.g.

```sh
terraform import azuredevops_serviceendpoint_devops.serviceendpoint db0541e6-ae9f-474d-ab83-1f7913839080
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
terraform import azuredevops_serviceendpoint_devops.serviceendpoint db0541e6-ae9f-474d-ab83-1f7913839080
terraform import azuredevops_serviceendpoint_devops.serviceendpoint projectID/00000000-0000-0000-0000-000000000000`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] updated this documentation page


## Import

Azure DevOps Service Endpoint can be imported using the serviceendpoint id (resourceId in your browser's url bar), e.g.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Azure DevOps Service Endpoint can be imported using the serviceendpoint id (resourceId in your browser's url bar), e.g.
Azure DevOps Service Endpoint can be imported using the `project id`, `service connection id` , e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] updated this documentation page

}

// Convert internal Terraform data structure to an AzDO data structure:
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused code lines can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] removed the commented examples

}

// Convert AzDO data structure to internal Terraform data structure
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused code lines can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] removed the commented examples

// ResourceServiceEndpointAzureDevOps schema and implementation for Azure DevOps service endpoint resource
func ResourceServiceEndpointAzureDevOps() *schema.Resource {
r := genBaseServiceEndpointResource(flattenServiceEndpointAzureDevOps, expandServiceEndpointAzureDevOps)
r.Schema["organization"] = &schema.Schema{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rename organization to organization_name or org_name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] renamed organization to organization_name and updated the documentation page

MinItems: 1,
MaxItems: 1,
Elem: authPersonal,
ConflictsWith: []string{},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Conflict schema can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] removed ConflictsWith

authPersonal.Schema[patHashKey] = patHashSchema
r.Schema["auth_personal"] = &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I skip the auth_personal configuration, after execute terraform apply, I got error:

Error: Error updating service endpoint in Azure DevOps: Unable to find service connection type 'azdoapi' using authentication scheme 'InstallationToken'.

  on main.tf line 5, in resource "azuredevops_serviceendpoint_devops" "serviceendpoint":
   5: resource "azuredevops_serviceendpoint_devops" "serviceendpoint" {


Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a unit test for default settings with empty auth_personal personal block

)

const (
azdoPersonalAccessToken = "personal_access_token"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate with personalAccessToken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] removed this constant value


```hcl
resource "azuredevops_project" "project" {
project_name = "Sample Project"
Copy link
Collaborator

Choose a reason for hiding this comment

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

project_name has been renamed to name in the latest master

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] renamed project_name to name in project definition in this example


// validates that an apply followed by another apply (i.e., resource update) will be reflected in AzDO and the
// underlying terraform state.
func TestAccServiceEndpointAzureDevOps_CreateAndUpdate(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test case is duplicate with TestAccServiceEndpointAzureDevOps_PersonalTokenUpdate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[x] removed this test case and added a test case for default settings

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 16, 2020

@xuzhang3 thank you for suggestions, I'm going to review and implement them soon

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 22, 2020

hi @xuzhang3
please review the updated pull request, all your suggestions are implemented.

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 22, 2020

and one question, does it worth to rename this resource to azuredevops_serviceendpoint_runpipeline to avoid confusions? in the UI this service connection is called just as a "Azure DevOps Service Connection", that may lead to miscommunication.

@xuzhang3 xuzhang3 self-requested a review September 22, 2020 09:11
@xuzhang3
Copy link
Collaborator

and one question, does it worth to rename this resource to azuredevops_serviceendpoint_runpipelines to avoid confusions? in the UI this service connection is called just as a "Azure DevOps Service Connection", that may lead to miscommunication.

I would suggest rename with azuredevops_serviceendpoint_pipelinerunner or azuredevops_serviceendpoint_pipelinedelegator, this extension is kind like the admin of another pipeline.

@zhmurko
Copy link
Contributor Author

zhmurko commented Sep 23, 2020

so I will refactor the code and docs with azuredevops_serviceendpoint_pipelinerunner resource name.

Copy link
Collaborator

@xuzhang3 xuzhang3 left a comment

Choose a reason for hiding this comment

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

Few changes requested but otherwise looks good. Can we rename function name prefix azdo to another name like pipelineRunner or something else, it's a bit odd with prefix azdo

}

func azdoPersonalAccessTokenField() *schema.Resource {
field_name := "personal_access_token"
Copy link
Collaborator

Choose a reason for hiding this comment

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

variable name style should follow camel style

}

// Convert internal Terraform data structure to an AzDO data structure:
func expandServiceEndpointAzureDevOps(d *schema.ResourceData) (*serviceendpoint.ServiceEndpoint, *string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

function expandServiceEndpointAzureDevOps never throw an error, I would suggest remove the error from the return parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* rename files to *_serviceendpoint_runpipeline.*

* update docs

* update acc-tests

* update package serviceendpoint

* update package serviceendpoint tests

* register in provider

* update testutils tempalates

* update provider test

* improve docs
@zhmurko zhmurko changed the title Add support for Azure DevOps Pipelines service endpoint Add support for Azure DevOps RunPipelines service endpoint Dec 5, 2020
@zhmurko
Copy link
Contributor Author

zhmurko commented Dec 7, 2020

hi @xuzhang3
the refactoring has been completed. The build now fails again on Unable to find service connection type 'azdoapi' message, and I believe it's related to disabled/removed plugin RunPipelines from AzureDevOps. Could you please enable it so acceptance test can pass.

@xuzhang3
Copy link
Collaborator

xuzhang3 commented Jan 5, 2021

LGTM

@xuzhang3 xuzhang3 merged commit 21fd222 into microsoft:master Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Add support for service endpoint for Azure DevOps
2 participants