1
0
Форкнуть 0
Terraform Azure DevOps provider
Перейти к файлу
xuzhang3 2f358bf6e6
Merge pull request #1218 from xuzhang3/f/support_init_repo_after_created
[Enhance] - `azuredevops_git_repository` support initialization of uninitialized repository
2024-11-07 17:04:38 +08:00
.azdo bump go to v1.22 2024-08-23 13:30:39 +08:00
.devcontainer change goreleaser to fix build error 2023-07-02 15:54:12 -03:00
.github remove github action 2021-03-12 16:51:40 +08:00
.vscode upgrade to Terraform SDK v2 2022-01-24 16:50:40 +08:00
azdosdkmocks Merge pull request #1032 from chienfuchen32/wiki 2024-05-21 10:40:40 +08:00
azuredevops fix lint 2024-11-07 16:59:13 +08:00
docs update resource.StateChangeConf to retry.StateChangeConf 2024-10-25 17:31:52 +08:00
examples update build definition default agent pool name 2021-10-13 13:46:21 +08:00
mocks update mock files and sdk connection 2024-02-19 15:33:56 +08:00
scripts Merge remote-tracking branch 'upstream/main' into k8s-env 2023-11-30 13:38:43 -03:00
vendor update vendor 2024-10-18 11:02:17 +08:00
version Add UserAgent for HTTP headers (#305) 2020-05-10 17:02:04 -05:00
website add support for server_url and azurestack 2024-11-05 17:16:01 +08:00
.gitignore Update gitignore to exclude JetBrains Fleet config 2024-03-24 21:22:02 +01:00
.go-version bump go to v1.22 2024-08-23 13:30:39 +08:00
.golangci.yml upgrade to Terraform SDK v2 2022-01-24 16:50:40 +08:00
.goreleaser.yml Change release archive name (#368) 2020-06-10 10:24:00 +08:00
CHANGELOG.md changelog v1.4.0 2024-10-24 13:10:06 +08:00
CODE_OF_CONDUCT.md update code of conduct doc 2024-05-23 16:45:53 +08:00
GNUmakefile bump golangci-lint to v1.56.2 2024-02-19 17:50:24 +08:00
LICENSE Update License (#165) 2020-08-26 10:33:12 +01:00
PROVIDER_NAME.txt Remove hack prep; Make repository look like terraform provider (#33) 2019-09-18 20:32:27 -07:00
PROVIDER_VERSION.txt Remove hack prep; Make repository look like terraform provider (#33) 2019-09-18 20:32:27 -07:00
README.md feat: Add azuredevops_group_entitlment 2023-08-30 02:56:04 +00:00
SECURITY.md Initial commit 2019-09-24 07:32:54 -07:00
ado-ci.yml bump go to v1.22 2024-08-23 13:30:39 +08:00
go.mod detect group deleted 2024-10-18 11:00:54 +08:00
go.sum detect group deleted 2024-10-18 11:00:54 +08:00
main.go accepted suggested changes 2022-08-02 15:14:15 +00:00

README.md

Terraform Provider for Azure DevOps (Devops Resource Manager)

Gitter Go Report Card

The AzureRM Provider supports Terraform 0.12.x and later.

Usage Example

# Make sure to set the following environment variables:
#   AZDO_PERSONAL_ACCESS_TOKEN
#   AZDO_ORG_SERVICE_URL
terraform {
  required_providers {
    azuredevops = {
      source = "microsoft/azuredevops"
      version = ">=0.1.0"
    }
  }
}

resource "azuredevops_project" "project" {
  name = "My Awesome Project"
  description  = "All of my awesomee things"
}

resource "azuredevops_git_repository" "repository" {
  project_id = azuredevops_project.project.id
  name       = "My Awesome Repo"
  initialization {
    init_type = "Clean"
  }
}

resource "azuredevops_build_definition" "build_definition" {
  project_id = azuredevops_project.project.id
  name       = "My Awesome Build Pipeline"
  path       = "\\"

  repository {
    repo_type   = "TfsGit"
    repo_id     = azuredevops_git_repository.repository.id
    branch_name = azuredevops_git_repository.repository.default_branch
    yml_path    = "azure-pipelines.yml"
  }
}

Developer Requirements

  • Terraform version 0.13.x +
  • Go version 1.16.x (to build the provider plugin)

If you're on Windows you'll also need:

If you what to use the makefile build strategy on Windows it's required to install

For GNU32 Make, make sure its bin path is added to PATH environment variable.*

For Git Bash for Windows, at the step of "Adjusting your PATH environment", please choose "Use Git and optional Unix tools from Windows Command Prompt".*

As described below we provide some PowerShell scripts to build the provider on Windows, without the requiremet to install any Unix based tools aside Go.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.16+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

Using the GOPATH model

First clone the repository to: $GOPATH/src/github.com/microsoft/terraform-provider-azuredevops

$ mkdir -p $GOPATH/src/github.com/terraform-providers && cd "$_"
$ git clone git@github.com:microsoft/terraform-provider-azuredevops.git
$ cd terraform-provider-azuredevops

Once you've cloned, run the ./scripts/build.sh and ./scripts/local-install.sh, as recommended here. These commands will sideload the plugin for Terraform.

Using a directory separate from GOPATH

The infrastructure supports building and testing the provider outside GOPATH in an arbitrary directory. In this scenario all required packages of the provider during build will be managed via the pkg in $GOPATH. As with the GOPATH Model, you can redefine the GOPATH environment variable to prevent existing packages in the current GOPATH directory from being changed.

Build using make

Once inside the provider directory, you can run make tools to install the dependent tooling required to compile the provider.

At this point you can compile the provider by running make build, which will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-azuredevops
...

You can also cross-compile if necessary:

GOOS=windows GOARCH=amd64 make build

Unit tests

In order to run the Unit Tests for the provider, you can run:

$ make test

With VSCode Golang extension you can also run and debug the tests using run test, debug test run package tests, run file tests buttons.

Acceptance tests

The majority of tests in the provider are acceptance tests - which provisions real resources in Azure Devops and Azure. To run any acceptance tests you need to set AZDO_ORG_SERVICE_URL, AZDO_PERSONAL_ACCESS_TOKEN environment variables, some test have additional environment variables required to run. You can find out the required environment variables by running the test. Most of these variables can be set to dummy values.

The several options to run the tests are:

  • Run the entire acceptance test suite

    make testacc
    
  • Run a subset using a prefix

    make testacc TESTARGS='-run=TestAccBuildDefinitionBitbucket_Create' TESTTAGS='resource_build_definition'
    
  • With VSCode Golang extension you can also run the tests using run test, run package tests, run file tests buttons above the test

Scaffolding the Website Documentation

You can scaffold the documentation for a Data Source by running:

$ make scaffold-website BRAND_NAME="Agent Pool" RESOURCE_NAME="azuredevops_agent_pool" RESOURCE_TYPE="data"

You can scaffold the documentation for a Resource by running:

$ make scaffold-website BRAND_NAME="Agent Pool" RESOURCE_NAME="azuredevops_agent_pool" RESOURCE_TYPE="resource" RESOURCE_ID="00000000-0000-0000-0000-000000000000"

BRAND_NAME is the human readable name of the object that is handled by a Terraform resource or datasource, like Agent Pool, User Entitlement or Kubernetes Service Endpoint

Build using PowerShell scripts

If you like to develop on Windows, we provide a set of PowerShell scripts to build and test the provider. They don't offer the luxury of a Makefile environment but are quite sufficient to develop on Windows.

scripts\build.ps1

The build.ps1is used to build the provider. Aside this the script runs (if not skipped) the defined unit tests and is able to install the compiled provider locally.

Parameter Description
-SkipTests Skip running unit tests during build
-Install Install the provider locally, after a successful build
-DebugBuild Build the provider with extra debugging information
-GoMod Control the -mod build parameter: Valid values: '' (Empty string), 'vendor', 'readonly'

scripts\unittest.ps1

The script is used to execute unit tests. The script is also executed by build.ps1 if the -SkipTest are not specified.

Parameter Description
-TestFilter A GO regular expression which filters the test functions to be executed
-Tag Tests in the provider project are organized with GO build tags. The parameter accepts a list of tag names which should be tested.
-GoMod Control the -mod build parameter: Valid values: '' (Empty string), 'vendor', 'readonly'

scripts\acctest.ps1

The script is used to execute unit tests.

Parameter Description
-TestFilter A GO regular expression which filters the test functions to be executed
-Tag Tests in the provider project are organized with GO build tags. The parameter accepts a list of tag names which should be tested.
-GoMod Control the -mod build parameter: Valid values: '' (Empty string), 'vendor', 'readonly'

scripts\gofmtcheck.ps1

To validate if all .go files adhere to the required formatting rules, execute gofmtcheck.ps1

Parameter Description
-Fix Fix any formatting rule deviations automatically. If the parameter is not set, the script runs in report mode.

scripts\lint-check-go.ps1

Like with gofmtcheck.ps1 the script validate if all .go files adhere to the required formatting rules and if any style mistakes exist. In difference to gofmtcheck.ps1 the script uses Golint instead of Gofmt.

Environment variables for acceptance tests

The following Environment Variables must be set in your shell prior to running acceptance tests:

  • AZDO_ORG_SERVICE_URL
  • AZDO_PERSONAL_ACCESS_TOKEN
  • AZDO_DOCKERREGISTRY_SERVICE_CONNECTION_EMAIL
  • AZDO_DOCKERREGISTRY_SERVICE_CONNECTION_PASSWORD
  • AZDO_DOCKERREGISTRY_SERVICE_CONNECTION_USERNAME
  • AZDO_GITHUB_SERVICE_CONNECTION_PAT
  • AZDO_TEST_AAD_USER_EMAIL
  • AZDO_TEST_AAD_GROUP_ID

Note: Acceptance tests create real resources in Azure DevOps which often cost money to run.