Skip to content

Commit

Permalink
Merge pull request #10 from dasmeta/DMVP-3484
Browse files Browse the repository at this point in the history
DMVP-3484: Fix publish problem
  • Loading branch information
aghamyan44 authored Feb 13, 2024
2 parents 6375495 + e12fcec commit 30c6e5c
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 0 deletions.
92 changes: 92 additions & 0 deletions modules/deployments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Terraform module to manage repository `Deployments`

## About

---
Deployment is environment which has its own variables to use in pipelines

## Provider configuration

---
```hcl
terraform {
required_providers {
bitbucket = {
source = "DrFaust92/bitbucket"
version = "2.30.2"
}
}
}
```
## Usage

---
```hcl
module "deployments" {
source = "./deployments"
deployments = local.deployments
repository_id = "my-repository-xxxx-id"
}
locals {
deployments = [
{
name = "development1"
stage = "Test"
variables = {
"key1" = ["value1", "secured"]
"key2" = ["value2", "secured"]
}
},
{
name = "development1"
stage = "Test"
variables = {
"key1" = ["value1", "secured"]
"key2" = ["value2"]
}
}
]
}
```
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_bitbucket"></a> [bitbucket](#requirement\_bitbucket) | 2.31.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_bitbucket"></a> [bitbucket](#provider\_bitbucket) | 2.31.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [bitbucket_deployment.depl](https://registry.terraform.io/providers/DrFaust92/bitbucket/2.31.0/docs/resources/deployment) | resource |
| [bitbucket_deployment_variable.depl-vars](https://registry.terraform.io/providers/DrFaust92/bitbucket/2.31.0/docs/resources/deployment_variable) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_deployments"></a> [deployments](#input\_deployments) | n/a | <pre>list(object({<br> name = string<br> stage = string<br> variables = list(object({<br> name = string<br> value = string<br> secured = bool<br> }))<br> }))</pre> | n/a | yes |
| <a name="input_repository_id"></a> [repository\_id](#input\_repository\_id) | n/a | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_variables"></a> [variables](#output\_variables) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8 changes: 8 additions & 0 deletions modules/deployments/deployment-veriables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "bitbucket_deployment_variable" "depl-vars" {
for_each = { for item in local.variables_flat : "${item.deploy}-${item.variable.key}" => item }

deployment = bitbucket_deployment.depl[each.value.deploy].id
key = each.value.variable.key
value = each.value.variable.value
secured = each.value.variable.secured
}
7 changes: 7 additions & 0 deletions modules/deployments/deployment.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "bitbucket_deployment" "depl" {
for_each = { for deployment in var.deployments : deployment.name => deployment }

repository = var.repository_id
name = each.value.name
stage = each.value.stage
}
12 changes: 12 additions & 0 deletions modules/deployments/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
locals {
variables_flat = flatten([for depl in var.deployments : [
for variable in depl.variables : {
deploy : depl.name
variable : {
key : variable.name,
value : variable.value,
secured : variable.secured
}
}
]])
}
3 changes: 3 additions & 0 deletions modules/deployments/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "variables" {
value = local.variables_flat
}
29 changes: 29 additions & 0 deletions modules/deployments/tests/full-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# full-example

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_bitbucket"></a> [bitbucket](#module\_bitbucket) | ../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
46 changes: 46 additions & 0 deletions modules/deployments/tests/full-example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module "bitbucket" {
source = "../"

name = "Repository-terraformed"
owner = "DevOps"
description = "Repository description"
website = "www.dasmeta.com"
language = "python"
fork_policy = "allow_forks"

project = {
create = true
name = "Project1"
key = "project1"
is_private = false
}

restrictions = {
action = "push"
branch = "master"
}

deployments = [
{
name = "development1"
stage = "Test"
variables = [
{ name = "key1", value = "value1", secured = true },
{ name = "key2", value = "value2", secured = false }
]
},
{
name = "development2"
stage = "Test"
variables = [
{ name = "key1", value = "value1", secured = true },
{ name = "key2", value = "value2", secured = false }
]
},
]

repository_variables = [
{ name = "key1", value = "value1", secured = true },
{ name = "key2", value = "value2", secured = false }
]
}
29 changes: 29 additions & 0 deletions modules/deployments/tests/minimal-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# minimal-example

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_bitbucket"></a> [bitbucket](#module\_bitbucket) | ../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6 changes: 6 additions & 0 deletions modules/deployments/tests/minimal-example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "bitbucket" {
source = "../"

name = "Repository-terraformed"
owner = "DevOps"
}
15 changes: 15 additions & 0 deletions modules/deployments/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "deployments" {
type = list(object({
name = string
stage = string
variables = list(object({
name = string
value = string
secured = bool
}))
}))
}

variable "repository_id" {
type = string
}
8 changes: 8 additions & 0 deletions modules/deployments/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
bitbucket = {
source = "DrFaust92/bitbucket"
version = "2.31.0"
}
}
}

0 comments on commit 30c6e5c

Please sign in to comment.