Skip to content

Commit

Permalink
feat: Add support for azureblob and sharepointonline api connections
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmsantos committed Apr 17, 2024
1 parent 757346a commit f46080f
Show file tree
Hide file tree
Showing 24 changed files with 861 additions and 2 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Pre-Commit

on:
pull_request:
branches:
- main
- master

env:
TERRAFORM_DOCS_VERSION: v0.16.0
TFLINT_VERSION: v0.44.1

jobs:
collectInputs:
name: Collect workflow inputs
runs-on: ubuntu-latest
outputs:
directories: ${{ steps.dirs.outputs.directories }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get root directories
id: dirs
uses: clowdhaus/terraform-composite-actions/[email protected]

preCommitMinVersions:
name: Min TF pre-commit
needs: collectInputs
runs-on: ubuntu-latest
strategy:
matrix:
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Terraform min/max versions
id: minMax
uses: clowdhaus/[email protected]
with:
directory: ${{ matrix.directory }}

- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory != '.' }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'

- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory == '.' }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'

preCommitMaxVersion:
name: Max TF pre-commit
runs-on: ubuntu-latest
needs: collectInputs
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Terraform min/max versions
id: minMax
uses: clowdhaus/[email protected]

- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
install-hcledit: true
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**/*.tf'
- '.github/workflows/release.yml'

jobs:
release:
name: Release
runs-on: ubuntu-latest
# Skip running release workflow on forks
if: github.repository_owner == 'fdmsantos'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0

- name: Release
uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 18.0.0
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
[email protected]
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc

# Ignore Lock
.terraform.lock.hcl

# Ignore IDE Folders
.idea
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.71.0
hooks:
- id: terraform_fmt
- id: terraform_validate
- id: terraform_docs
args:
- '--args=--lockfile=false'
- id: terraform_tflint
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
44 changes: 44 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"branches": [
"main"
],
"ci": false,
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/github",
{
"successComment": "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:",
"labels": false,
"releasedLabels": false
}
],
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file."
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
],
"message": "chore(release): version ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

All notable changes to this project will be documented in this file.
125 changes: 123 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,123 @@
# terraform-azurerm-api-connections
Terraform Module to Create Azure API Connections
# Azure API Connections Terraform Module

[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)

Dynamic Terraform Module to Create Azure API Connections.

## Table of Contents

* [Module versioning rule](README.md#module-versioning-rule)
* [Supported Connections](README.md#supported-connections)
* [How to Use](README.md#how-to-use)
* [Azure Blob](README.md#azure-blob)
* [Sharepoint Online](README.md#sharepoint-online)
* [Examples](README.md#examples)
* [Contributing](README.md#contributing)
* [License](README.md#license)


## Module versioning rule

| Module version | AWS Provider version |
|----------------|----------------------|
| >= 1.x.x | => 5.31 |

## Supported Connections

- Azure Blob (All 4 types of authentication)
- Sharepoint Online

## How to Use

### Azure Blob

This example creates Api Connection to Azure blob storage using service principal as authentication. Please check [here](https://github.com/fdmsantos/terraform-azurerm-api-connections/tree/main/examples/azureblob) for examples to another supported authentication types.

```hcl
module "azureblob" {
source = "../../"
api_type = "azureblob"
connection_name = "azureblob-1"
deployment_name = "azureblob-deployment"
resource_group_name = "<resource_group_name>"
connection_display_name = "<display_name"
azureblob_authentication_type = "Service Principal"
auth_service_principal_client_id = "<service_principal_client_id>"
auth_service_principal_client_secret = "<service_principal_client_secret>"
auth_service_principal_tenant_id = "<service_principal_client_tenant_id>"
}
```

### Sharepoint Online

```hcl
module "sharepointonline" {
source = "../../"
api_type = "sharepointonline"
resource_group_name = "<resource_group_name>"
connection_display_name = "Demo Sharepoint Connection"
}
```

## Examples

- [azureblob](https://github.com/fdmsantos/terraform-azurerm-api-connections/tree/main/examples/azureblob) - Creates an api connection to azure blob storage.
- [sharepointonline](https://github.com/fdmsantos/terraform-azurerm-api-connections/tree/main/examples/sharepointonline) - Creates an api connection to sharepoint.

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

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.22 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 3.22 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [azurerm_resource_group_template_deployment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_template_deployment) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_api_type"></a> [api\_type](#input\_api\_type) | Specifies the type of the Managed API. | `string` | n/a | yes |
| <a name="input_auth_service_principal_client_id"></a> [auth\_service\_principal\_client\_id](#input\_auth\_service\_principal\_client\_id) | Service Principal Client Id. Required when `*_authentication_type` is `Service Principal` | `string` | `null` | no |
| <a name="input_auth_service_principal_client_secret"></a> [auth\_service\_principal\_client\_secret](#input\_auth\_service\_principal\_client\_secret) | Service Principal Client Secret. Required when `*_authentication_type` is `Service Principal` | `string` | `null` | no |
| <a name="input_auth_service_principal_tenant_id"></a> [auth\_service\_principal\_tenant\_id](#input\_auth\_service\_principal\_tenant\_id) | Service Principal Tenant Id. Required when `*_authentication_type` is `Service Principal` | `string` | `null` | no |
| <a name="input_azureblob_authentication_type"></a> [azureblob\_authentication\_type](#input\_azureblob\_authentication\_type) | Specifies Authentication Type for `azureblob` api connection. | `string` | `"Logic Apps Managed Identity"` | no |
| <a name="input_azureblob_storage_account_access_key"></a> [azureblob\_storage\_account\_access\_key](#input\_azureblob\_storage\_account\_access\_key) | Specifies storage access key for `azureblob` api connection. Required when `azureblob_authentication_type` is `Access Key` | `string` | `null` | no |
| <a name="input_azureblob_storage_account_name"></a> [azureblob\_storage\_account\_name](#input\_azureblob\_storage\_account\_name) | Specifies storage account name for `azureblob` api connection. Required when `azureblob_authentication_type` is `Access Key` | `string` | `null` | no |
| <a name="input_connection_display_name"></a> [connection\_display\_name](#input\_connection\_display\_name) | A display name for this API Connection. Changing this forces a new API Connection to be created. | `string` | `null` | no |
| <a name="input_connection_name"></a> [connection\_name](#input\_connection\_name) | The Name which should be used for this API Connection. Changing this forces a new API Connection to be created. | `string` | `null` | no |
| <a name="input_deployment_name"></a> [deployment\_name](#input\_deployment\_name) | The name which should be used for this Resource Group Template Deployment. Changing this forces a new Resource Group Template Deployment to be created. | `string` | `null` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Specifies the name of the Resource Group where the logic should exists. Changing this forces a new resource to be created. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_connection_id"></a> [connection\_id](#output\_connection\_id) | Api Connection Resource ID. |
| <a name="output_connection_name"></a> [connection\_name](#output\_connection\_name) | Api Connection Name. |
| <a name="output_logic_app_parameter"></a> [logic\_app\_parameter](#output\_logic\_app\_parameter) | Output to use in Logic App Parameters to configure this connection. |
| <a name="output_managed_api_id"></a> [managed\_api\_id](#output\_managed\_api\_id) | Managed API ID. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Contributing

The goal is to have the maximum number of supported Azure API connections. To help achieve this objective, contributions via issues or pull requests are welcome.

## License

Apache 2 Licensed. See [LICENSE](https://github.com/fdmsantos/terraform-azurerm-api-connections/tree/main/LICENSE) for full details.
Loading

0 comments on commit f46080f

Please sign in to comment.