Skip to content

Commit

Permalink
Terraform files to create ado project and repository
Browse files Browse the repository at this point in the history
Signed-off-by: Dipti Pai <[email protected]>
  • Loading branch information
dipti-pai authored and darkowlzz committed Aug 27, 2024
1 parent 5b91964 commit 1b51144
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tf-modules/azure/devops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# DevOps Module

Configuration in this directory creates an Azure DevOps Project and repository.

## Usage

Legacy shared modules with their own provider configurations are not compatible
with new features like for_each, count and depends_on as described
[here](https://developer.hashicorp.com/terraform/language/modules/develop/providers#legacy-shared-modules-with-provider-configurations).
To use these features by passing provider configuration to the legacy module,
create version.tf file with the following content -

```hcl
terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
}
}
}
```

In main.tf, create the provider configuration and pass it to the devops module.

```hcl
provider "azuredevops" {
org_service_url = "https://dev.azure.com/azuredevops_org"
personal_access_token = "azuredevops_pat"
}
module "devops" {
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/azure/devops"
providers = {
azuredevops = azuredevops
}
project_name = local.project_name
repository_name = local.repo_name
}
```
16 changes: 16 additions & 0 deletions tf-modules/azure/devops/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "azuredevops_project" "project" {
name = var.project_name
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
description = var.project_description
}

resource "azuredevops_git_repository" "application" {
project_id = azuredevops_project.project.id
name = var.repository_name
default_branch = "refs/heads/main"
initialization {
init_type = "Clean"
}
}
9 changes: 9 additions & 0 deletions tf-modules/azure/devops/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "repo_url" {
description = "Azure Devops Git repository HTTPS url"
value = azuredevops_git_repository.application.remote_url
}

output "project_id" {
description = "Azure Devops Project ID"
value = azuredevops_project.project.id
}
15 changes: 15 additions & 0 deletions tf-modules/azure/devops/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "project_name" {
description = "The name of the Azure DevOps project"
type = string
}

variable "project_description" {
description = "The description of the Azure DevOps project"
type = string
default = "Test Project for Flux E2E test - Managed by Terraform"
}

variable "repository_name" {
description = "The name of the Azure DevOps repository"
type = string
}
8 changes: 8 additions & 0 deletions tf-modules/azure/devops/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
version = ">= 1.2.0"
}
}
}

0 comments on commit 1b51144

Please sign in to comment.