diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..88cb251 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +# EditorConfig is awesome: http://EditorConfig.org +# Uses editorconfig to maintain consistent coding styles + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true + +[*.{tf,tfvars}] +indent_size = 2 +indent_style = space + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +[Makefile] +tab_width = 2 +indent_style = tab + +[COMMIT_EDITMSG] +max_line_length = 0 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..9ea52ce --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# Default owners - required for review/approval +* @bryantbiggs diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..13556e5 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at contact@clowd.haus. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..d4cb1e0 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,78 @@ +name: Pre-Commit + +on: + pull_request: + branches: + - main + - master + +env: + TERRAFORM_DOCS_VERSION: v0.16.0 + +jobs: + collectInputs: + name: Collect workflow inputs + runs-on: ubuntu-latest + outputs: + directories: ${{ steps.dirs.outputs.directories }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Get root directories + id: dirs + uses: clowdhaus/terraform-composite-actions/directories@v1.4.0 + + 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@v2 + + - name: Terraform min/max versions + id: minMax + uses: clowdhaus/terraform-min-max@v1.0.4 + 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/pre-commit@v1.4.0 + with: + terraform-version: ${{ steps.minMax.outputs.minVersion }} + 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/pre-commit@v1.4.0 + with: + terraform-version: ${{ steps.minMax.outputs.minVersion }} + 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@v2 + 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/terraform-min-max@v1.0.4 + + - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.4.0 + with: + terraform-version: ${{ steps.minMax.outputs.maxVersion }} + terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }} diff --git a/.github/workflows/semantic-releaser.yml b/.github/workflows/semantic-releaser.yml new file mode 100644 index 0000000..804a5fc --- /dev/null +++ b/.github/workflows/semantic-releaser.yml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + branches: + - main + paths: + - '**.tf' + - '!examples/**.tf' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Release + uses: cycjimmy/semantic-release-action@v2 + with: + semantic_version: 18.0.0 + extra_plugins: | + @semantic-release/changelog@6.0.0 + @semantic-release/git@10.0.0 + conventional-changelog-conventionalcommits@4.6.3 + env: + GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..788c463 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# terraform lockfile +.terraform.lock.hcl + +# Crash log files +crash.log + +# Exclude all .tfvars files, which are likely to contain sentitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +# +*.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ba45548 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +repos: + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.64.1 + 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 diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..7885cfa --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,20 @@ +{ + "branches": [ + "main" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + } + ], + "@semantic-release/github" + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a58a4f5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 Clowd Haus, LLC. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff338f5 --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +# AWS Managed Grafana Terraform module + +Terraform module which creates AWS Managed Grafana resources. + +## Usage + +See [`examples`](https://github.com/clowdhaus/terraform-aws-managed-grafana/tree/main/examples) directory for working examples to reference: + +```hcl +module "managed_grafana" { + source = "clowdhaus/managed-grafana/aws" + + # Workspace + name = "example" + description = "AWS Managed Grafana service example workspace" + account_access_type = "CURRENT_ACCOUNT" + authentication_providers = ["AWS_SSO"] + permission_type = "SERVICE_MANAGED" + data_sources = ["CLOUDWATCH", "PROMETHEUS", "XRAY"] + notification_destinations = ["SNS"] + + # Workspace SAML configuration + saml_admin_role_values = ["admin"] + saml_editor_role_values = ["editor"] + saml_email_assertion = "mail" + saml_groups_assertion = "groups" + saml_login_assertion = "mail" + saml_name_assertion = "displayName" + saml_org_assertion = "org" + saml_role_assertion = "role" + saml_idp_metadata_url = "https://my_idp_metadata.url" + + # Role associations + role_associations = { + "ADMIN" = { + "group_ids" = ["1111111111-abcdefgh-1234-5678-abcd-999999999999"] + } + "EDITOR" = { + "user_ids" = ["2222222222-abcdefgh-1234-5678-abcd-999999999999"] + } + } + + tags = { + Terraform = "true" + Environment = "dev" + } +} +``` + +## Examples + +Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-aws-managed-grafana/tree/main/examples) are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you! + +- [Complete](https://github.com/clowdhaus/terraform-aws-managed-grafana/tree/main/examples/complete) + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 4.4 | + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | >= 4.4 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [aws_grafana_license_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_license_association) | resource | +| [aws_grafana_role_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_role_association) | resource | +| [aws_grafana_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace) | resource | +| [aws_grafana_workspace_saml_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace_saml_configuration) | resource | +| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | +| [aws_iam_policy_document.assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [account\_access\_type](#input\_account\_access\_type) | The type of account access for the workspace. Valid values are `CURRENT_ACCOUNT` and `ORGANIZATION` | `string` | `"CURRENT_ACCOUNT"` | no | +| [associate\_license](#input\_associate\_license) | Determines whether a license will be associated with the workspace | `bool` | `true` | no | +| [authentication\_providers](#input\_authentication\_providers) | The authentication providers for the workspace. Valid values are `AWS_SSO`, `SAML`, or both | `list(string)` |
[| no | +| [create](#input\_create) | Determines whether a resources will be created | `bool` | `true` | no | +| [create\_iam\_role](#input\_create\_iam\_role) | Determines whether a an IAM role is created or to use an existing IAM role | `bool` | `true` | no | +| [data\_sources](#input\_data\_sources) | The data sources for the workspace. Valid values are `AMAZON_OPENSEARCH_SERVICE`, `CLOUDWATCH`, `PROMETHEUS`, `XRAY`, `TIMESTREAM`, `SITEWISE` | `list(string)` | `[]` | no | +| [description](#input\_description) | The workspace description | `string` | `null` | no | +| [iam\_role\_arn](#input\_iam\_role\_arn) | Existing IAM role ARN for the workspace. Required if `create_iam_role` is set to `false` | `string` | `null` | no | +| [iam\_role\_description](#input\_iam\_role\_description) | The description of the workspace IAM role | `string` | `null` | no | +| [iam\_role\_force\_detach\_policies](#input\_iam\_role\_force\_detach\_policies) | Determines whether the workspace IAM role policies will be forced to detach | `bool` | `true` | no | +| [iam\_role\_max\_session\_duration](#input\_iam\_role\_max\_session\_duration) | Maximum session duration (in seconds) that you want to set for the IAM role | `number` | `null` | no | +| [iam\_role\_name](#input\_iam\_role\_name) | Name to use on workspace IAM role created | `string` | `null` | no | +| [iam\_role\_path](#input\_iam\_role\_path) | Workspace IAM role path | `string` | `null` | no | +| [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the IAM role | `string` | `null` | no | +| [iam\_role\_tags](#input\_iam\_role\_tags) | A map of additional tags to add to the IAM role created | `map(string)` | `{}` | no | +| [license\_type](#input\_license\_type) | The type of license for the workspace license association. Valid values are `ENTERPRISE` and `ENTERPRISE_FREE_TRIAL` | `string` | `"ENTERPRISE"` | no | +| [name](#input\_name) | The Grafana workspace name | `string` | `null` | no | +| [notification\_destinations](#input\_notification\_destinations) | The notification destinations. If a data source is specified here, Amazon Managed Grafana will create IAM roles and permissions needed to use these destinations. Must be set to `SNS` | `list(string)` | `[]` | no | +| [organization\_role\_name](#input\_organization\_role\_name) | The role name that the workspace uses to access resources through Amazon Organizations | `string` | `null` | no | +| [organizational\_units](#input\_organizational\_units) | The Amazon Organizations organizational units that the workspace is authorized to use data sources from | `list(string)` | `[]` | no | +| [permission\_type](#input\_permission\_type) | The permission type of the workspace. If `SERVICE_MANAGED` is specified, the IAM roles and IAM policy attachments are generated automatically. If `CUSTOMER_MANAGED` is specified, the IAM roles and IAM policy attachments will not be created | `string` | `"SERVICE_MANAGED"` | no | +| [role\_associations](#input\_role\_associations) | Map of maps to assocaite user/group IDs to a role. Map key can be used as the `role` | `any` | `{}` | no | +| [saml\_admin\_role\_values](#input\_saml\_admin\_role\_values) | SAML authentication admin role values | `list(string)` | `[]` | no | +| [saml\_allowed\_organizations](#input\_saml\_allowed\_organizations) | SAML authentication allowed organizations | `list(string)` | `[]` | no | +| [saml\_editor\_role\_values](#input\_saml\_editor\_role\_values) | SAML authentication editor role values | `list(string)` | `[]` | no | +| [saml\_email\_assertion](#input\_saml\_email\_assertion) | SAML authentication email assertion | `string` | `null` | no | +| [saml\_groups\_assertion](#input\_saml\_groups\_assertion) | SAML authentication groups assertion | `string` | `null` | no | +| [saml\_idp\_metadata\_url](#input\_saml\_idp\_metadata\_url) | SAML authentication IDP Metadata URL. Note that either `saml_idp_metadata_url` or `saml_idp_metadata_xml` | `string` | `null` | no | +| [saml\_idp\_metadata\_xml](#input\_saml\_idp\_metadata\_xml) | SAML authentication IDP Metadata XML. Note that either `saml_idp_metadata_url` or `saml_idp_metadata_xml` | `string` | `null` | no | +| [saml\_login\_assertion](#input\_saml\_login\_assertion) | SAML authentication email assertion | `string` | `null` | no | +| [saml\_login\_validity\_duration](#input\_saml\_login\_validity\_duration) | SAML authentication login validity duration | `number` | `null` | no | +| [saml\_name\_assertion](#input\_saml\_name\_assertion) | SAML authentication name assertion | `string` | `null` | no | +| [saml\_org\_assertion](#input\_saml\_org\_assertion) | SAML authentication org assertion | `string` | `null` | no | +| [saml\_role\_assertion](#input\_saml\_role\_assertion) | SAML authentication role assertion | `string` | `null` | no | +| [stack\_set\_name](#input\_stack\_set\_name) | The AWS CloudFormation stack set name that provisions IAM roles to be used by the workspace | `string` | `null` | no | +| [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | +| [use\_iam\_role\_name\_prefix](#input\_use\_iam\_role\_name\_prefix) | Determines whether the IAM role name (`wokspace_iam_role_name`) is used as a prefix | `bool` | `true` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [license\_expiration](#output\_license\_expiration) | If `license_type` is set to `ENTERPRISE`, this is the expiration date of the enterprise license | +| [license\_free\_trial\_expiration](#output\_license\_free\_trial\_expiration) | If `license_type` is set to `ENTERPRISE_FREE_TRIAL`, this is the expiration date of the free trial | +| [saml\_configuration\_status](#output\_saml\_configuration\_status) | Status of the SAML configuration | +| [workspace\_arn](#output\_workspace\_arn) | The Amazon Resource Name (ARN) of the Grafana workspace | +| [workspace\_endpoint](#output\_workspace\_endpoint) | The endpoint of the Grafana workspace | +| [workspace\_grafana\_version](#output\_workspace\_grafana\_version) | The version of Grafana running on the workspace | +| [workspace\_iam\_role\_arn](#output\_workspace\_iam\_role\_arn) | IAM role ARN of the Grafana workspace | +| [workspace\_iam\_role\_name](#output\_workspace\_iam\_role\_name) | IAM role name of the Grafana workspace | +| [workspace\_iam\_role\_unique\_id](#output\_workspace\_iam\_role\_unique\_id) | Stable and unique string identifying the IAM role | + + +## License + +Apache-2.0 Licensed. See [LICENSE](https://github.com/clowdhaus/terraform-aws-managed-grafana/blob/main/LICENSE). diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..cdb1baa --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# Terraform AWS Managed Grafana Examples + +- [Complete](https://github.com/clowdhaus/terraform-aws-managed-grafana/tree/main/examples/complete) diff --git a/examples/complete/README.md b/examples/complete/README.md new file mode 100644 index 0000000..453641b --- /dev/null +++ b/examples/complete/README.md @@ -0,0 +1,64 @@ +# Complete AWS Managed Grafana Example + +Configuration in this directory creates: + +- Disabled Grafana workspace +- Default Grafana workspace (using defaults provided by the module) +- Complete Grafana workspace showing example of possible configurations + +## Usage + +To run this example you need to execute: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 4.4 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [managed\_grafana](#module\_managed\_grafana) | ../.. | n/a | +| [managed\_grafana\_default](#module\_managed\_grafana\_default) | ../.. | n/a | +| [managed\_grafana\_disabled](#module\_managed\_grafana\_disabled) | ../.. | n/a | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [license\_expiration](#output\_license\_expiration) | If `license_type` is set to `ENTERPRISE`, this is the expiration date of the enterprise license | +| [license\_free\_trial\_expiration](#output\_license\_free\_trial\_expiration) | If `license_type` is set to `ENTERPRISE_FREE_TRIAL`, this is the expiration date of the free trial | +| [saml\_configuration\_status](#output\_saml\_configuration\_status) | Status of the SAML configuration | +| [workspace\_arn](#output\_workspace\_arn) | The Amazon Resource Name (ARN) of the Grafana workspace | +| [workspace\_endpoint](#output\_workspace\_endpoint) | The endpoint of the Grafana workspace | +| [workspace\_grafana\_version](#output\_workspace\_grafana\_version) | The version of Grafana running on the workspace | +| [workspace\_iam\_role\_arn](#output\_workspace\_iam\_role\_arn) | IAM role ARN of the Grafana workspace | +| [workspace\_iam\_role\_name](#output\_workspace\_iam\_role\_name) | IAM role name of the Grafana workspace | +| [workspace\_iam\_role\_unique\_id](#output\_workspace\_iam\_role\_unique\_id) | Stable and unique string identifying the IAM role | + + +Apache-2.0 Licensed. See [LICENSE](https://github.com/clowdhaus/terraform-aws-managed-grafana/blob/main/LICENSE). diff --git a/examples/complete/main.tf b/examples/complete/main.tf new file mode 100644 index 0000000..933714f --- /dev/null +++ b/examples/complete/main.tf @@ -0,0 +1,86 @@ +provider "aws" { + region = local.region +} + +locals { + region = "us-east-1" + name = "managed-grafana-ex-${replace(basename(path.cwd), "_", "-")}" + description = "AWS Managed Grafana service for ${local.name}" + + tags = { + Name = local.name + Example = local.name + Repository = "https://github.com/clowdhaus/terraform-aws-managed-grafana" + } +} + +################################################################################ +# Managed Grafana Module +################################################################################ + +module "managed_grafana_disabled" { + source = "../.." + + name = local.name + create = false +} + +module "managed_grafana_default" { + source = "../.." + + name = "${local.name}-default" + associate_license = false + + tags = local.tags +} + +module "managed_grafana" { + source = "../.." + + # Workspace + name = local.name + associate_license = false + description = local.description + account_access_type = "CURRENT_ACCOUNT" + authentication_providers = ["AWS_SSO"] + permission_type = "SERVICE_MANAGED" + data_sources = ["CLOUDWATCH", "PROMETHEUS", "XRAY"] + notification_destinations = ["SNS"] + stack_set_name = local.name + + # Workspace IAM role + create_iam_role = true + iam_role_name = local.name + use_iam_role_name_prefix = true + iam_role_description = local.description + iam_role_path = "/grafana/" + iam_role_force_detach_policies = true + iam_role_max_session_duration = 7200 + iam_role_tags = { role = true } + + # # Workspace SAML configuration + # saml_admin_role_values = ["admin"] + # saml_editor_role_values = ["editor"] + # saml_email_assertion = "mail" + # saml_groups_assertion = "groups" + # saml_login_assertion = "mail" + # saml_name_assertion = "displayName" + # saml_org_assertion = "org" + # saml_role_assertion = "role" + # saml_idp_metadata_url = "https://my_idp_metadata.url" + + # Role associations + # Ref: https://github.com/aws/aws-sdk/issues/25 + # Ref: https://github.com/hashicorp/terraform-provider-aws/issues/18812 + # WARNING: https://github.com/hashicorp/terraform-provider-aws/issues/24166 + # role_associations = { + # "ADMIN" = { + # "group_ids" = ["1111111111-abcdefgh-1234-5678-abcd-999999999999"] + # } + # "EDITOR" = { + # "user_ids" = ["2222222222-abcdefgh-1234-5678-abcd-999999999999"] + # } + # } + + tags = local.tags +} diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf new file mode 100644 index 0000000..1b4e81e --- /dev/null +++ b/examples/complete/outputs.tf @@ -0,0 +1,60 @@ +################################################################################ +# Workspace +################################################################################ + +output "workspace_arn" { + description = "The Amazon Resource Name (ARN) of the Grafana workspace" + value = module.managed_grafana.workspace_arn +} + +output "workspace_endpoint" { + description = "The endpoint of the Grafana workspace" + value = module.managed_grafana.workspace_endpoint +} + +output "workspace_grafana_version" { + description = "The version of Grafana running on the workspace" + value = module.managed_grafana.workspace_grafana_version +} + +################################################################################ +# Workspace IAM Role +################################################################################ + +output "workspace_iam_role_name" { + description = "IAM role name of the Grafana workspace" + value = module.managed_grafana.workspace_iam_role_name +} + +output "workspace_iam_role_arn" { + description = "IAM role ARN of the Grafana workspace" + value = module.managed_grafana.workspace_iam_role_arn +} + +output "workspace_iam_role_unique_id" { + description = "Stable and unique string identifying the IAM role" + value = module.managed_grafana.workspace_iam_role_unique_id +} + +################################################################################ +# Workspace SAML Configuration +################################################################################ + +output "saml_configuration_status" { + description = "Status of the SAML configuration" + value = module.managed_grafana.saml_configuration_status +} + +################################################################################ +# License Association +################################################################################ + +output "license_free_trial_expiration" { + description = "If `license_type` is set to `ENTERPRISE_FREE_TRIAL`, this is the expiration date of the free trial" + value = module.managed_grafana.license_free_trial_expiration +} + +output "license_expiration" { + description = "If `license_type` is set to `ENTERPRISE`, this is the expiration date of the enterprise license" + value = module.managed_grafana.license_expiration +} diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf new file mode 100644 index 0000000..03533eb --- /dev/null +++ b/examples/complete/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.13.1" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.4" + } + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a8ac5c9 --- /dev/null +++ b/main.tf @@ -0,0 +1,110 @@ +data "aws_partition" "current" {} + +################################################################################ +# Workspace +################################################################################ + +resource "aws_grafana_workspace" "this" { + count = var.create ? 1 : 0 + + name = var.name + description = var.description + + account_access_type = var.account_access_type + authentication_providers = var.authentication_providers + permission_type = var.permission_type + + data_sources = var.data_sources + notification_destinations = var.notification_destinations + organization_role_name = var.organization_role_name + organizational_units = var.organizational_units + role_arn = var.create_iam_role ? aws_iam_role.this[0].arn : var.iam_role_arn + stack_set_name = coalesce(var.stack_set_name, var.name) +} + +################################################################################ +# Workspace IAM Role +################################################################################ + +locals { + iam_role_name = coalesce(var.iam_role_name, var.name) +} + +data "aws_iam_policy_document" "assume" { + count = var.create && var.create_iam_role ? 1 : 0 + + statement { + sid = "GrafanaAssume" + effect = "Allow" + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["grafana.${data.aws_partition.current.dns_suffix}"] + } + } +} + +resource "aws_iam_role" "this" { + count = var.create && var.create_iam_role ? 1 : 0 + + name = var.use_iam_role_name_prefix ? null : local.iam_role_name + name_prefix = var.use_iam_role_name_prefix ? "${local.iam_role_name}-" : null + description = var.iam_role_description + path = var.iam_role_path + + assume_role_policy = data.aws_iam_policy_document.assume[0].json + force_detach_policies = var.iam_role_force_detach_policies + max_session_duration = var.iam_role_max_session_duration + permissions_boundary = var.iam_role_permissions_boundary + + tags = merge(var.tags, var.iam_role_tags) +} + +################################################################################ +# Workspace SAML Configuration +################################################################################ + +resource "aws_grafana_workspace_saml_configuration" "this" { + count = var.create && contains(var.authentication_providers, "SAML") ? 1 : 0 + + editor_role_values = var.saml_editor_role_values + workspace_id = aws_grafana_workspace.this[0].id + + idp_metadata_url = var.saml_idp_metadata_url + idp_metadata_xml = var.saml_idp_metadata_xml + + admin_role_values = var.saml_admin_role_values + allowed_organizations = var.saml_allowed_organizations + email_assertion = var.saml_email_assertion + groups_assertion = var.saml_groups_assertion + login_assertion = var.saml_login_assertion + login_validity_duration = var.saml_login_validity_duration + name_assertion = var.saml_name_assertion + org_assertion = var.saml_org_assertion + role_assertion = var.saml_role_assertion +} + +################################################################################ +# License Association +################################################################################ + +resource "aws_grafana_license_association" "this" { + count = var.create && var.associate_license ? 1 : 0 + + license_type = var.license_type + workspace_id = aws_grafana_workspace.this[0].id +} + +################################################################################ +# Role Association +################################################################################ + +resource "aws_grafana_role_association" "this" { + for_each = { for k, v in var.role_associations : k => v if var.create } + + role = try(each.value.role, each.key) + group_ids = try(each.value.group_ids, null) + user_ids = try(each.value.user_ids, null) + workspace_id = aws_grafana_workspace.this[0].id +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..6262c97 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,60 @@ +################################################################################ +# Workspace +################################################################################ + +output "workspace_arn" { + description = "The Amazon Resource Name (ARN) of the Grafana workspace" + value = try(aws_grafana_workspace.this[0].arn, null) +} + +output "workspace_endpoint" { + description = "The endpoint of the Grafana workspace" + value = try(aws_grafana_workspace.this[0].endpoint, null) +} + +output "workspace_grafana_version" { + description = "The version of Grafana running on the workspace" + value = try(aws_grafana_workspace.this[0].grafana_version, null) +} + +################################################################################ +# Workspace IAM Role +################################################################################ + +output "workspace_iam_role_name" { + description = "IAM role name of the Grafana workspace" + value = try(aws_iam_role.this[0].name, null) +} + +output "workspace_iam_role_arn" { + description = "IAM role ARN of the Grafana workspace" + value = try(aws_iam_role.this[0].arn, null) +} + +output "workspace_iam_role_unique_id" { + description = "Stable and unique string identifying the IAM role" + value = try(aws_iam_role.this[0].unique_id, null) +} + +################################################################################ +# Workspace SAML Configuration +################################################################################ + +output "saml_configuration_status" { + description = "Status of the SAML configuration" + value = try(aws_grafana_workspace_saml_configuration.this[0].status, null) +} + +################################################################################ +# License Association +################################################################################ + +output "license_free_trial_expiration" { + description = "If `license_type` is set to `ENTERPRISE_FREE_TRIAL`, this is the expiration date of the free trial" + value = try(aws_grafana_license_association.this[0].free_trial_expiration, null) +} + +output "license_expiration" { + description = "If `license_type` is set to `ENTERPRISE`, this is the expiration date of the enterprise license" + value = try(aws_grafana_license_association.this[0].license_expiration, null) +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..a4f9472 --- /dev/null +++ b/variables.tf @@ -0,0 +1,241 @@ +variable "create" { + description = "Determines whether a resources will be created" + type = bool + default = true +} + +variable "tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + +################################################################################ +# Workspace +################################################################################ + +variable "name" { + description = "The Grafana workspace name" + type = string + default = null +} + +variable "description" { + description = "The workspace description" + type = string + default = null +} + +variable "account_access_type" { + description = "The type of account access for the workspace. Valid values are `CURRENT_ACCOUNT` and `ORGANIZATION`" + type = string + default = "CURRENT_ACCOUNT" +} + +variable "authentication_providers" { + description = "The authentication providers for the workspace. Valid values are `AWS_SSO`, `SAML`, or both" + type = list(string) + default = ["AWS_SSO"] +} + +variable "permission_type" { + description = "The permission type of the workspace. If `SERVICE_MANAGED` is specified, the IAM roles and IAM policy attachments are generated automatically. If `CUSTOMER_MANAGED` is specified, the IAM roles and IAM policy attachments will not be created" + type = string + default = "SERVICE_MANAGED" +} + +variable "data_sources" { + description = "The data sources for the workspace. Valid values are `AMAZON_OPENSEARCH_SERVICE`, `CLOUDWATCH`, `PROMETHEUS`, `XRAY`, `TIMESTREAM`, `SITEWISE`" + type = list(string) + default = [] +} + +variable "notification_destinations" { + description = "The notification destinations. If a data source is specified here, Amazon Managed Grafana will create IAM roles and permissions needed to use these destinations. Must be set to `SNS`" + type = list(string) + default = [] +} + +variable "organization_role_name" { + description = "The role name that the workspace uses to access resources through Amazon Organizations" + type = string + default = null +} + +variable "organizational_units" { + description = "The Amazon Organizations organizational units that the workspace is authorized to use data sources from" + type = list(string) + default = [] +} + +variable "stack_set_name" { + description = "The AWS CloudFormation stack set name that provisions IAM roles to be used by the workspace" + type = string + default = null +} + +################################################################################ +# Workspace IAM Role +################################################################################ + +variable "create_iam_role" { + description = "Determines whether a an IAM role is created or to use an existing IAM role" + type = bool + default = true +} + +variable "iam_role_arn" { + description = "Existing IAM role ARN for the workspace. Required if `create_iam_role` is set to `false`" + type = string + default = null +} + +variable "iam_role_name" { + description = "Name to use on workspace IAM role created" + type = string + default = null +} + +variable "use_iam_role_name_prefix" { + description = "Determines whether the IAM role name (`wokspace_iam_role_name`) is used as a prefix" + type = bool + default = true +} + +variable "iam_role_description" { + description = "The description of the workspace IAM role" + type = string + default = null +} + +variable "iam_role_path" { + description = "Workspace IAM role path" + type = string + default = null +} + +variable "iam_role_force_detach_policies" { + description = "Determines whether the workspace IAM role policies will be forced to detach" + type = bool + default = true +} + +variable "iam_role_max_session_duration" { + description = "Maximum session duration (in seconds) that you want to set for the IAM role" + type = number + default = null +} + +variable "iam_role_permissions_boundary" { + description = "ARN of the policy that is used to set the permissions boundary for the IAM role" + type = string + default = null +} + +variable "iam_role_tags" { + description = "A map of additional tags to add to the IAM role created" + type = map(string) + default = {} +} + +################################################################################ +# Workspace SAML Configuration +################################################################################ + +variable "saml_editor_role_values" { + description = "SAML authentication editor role values" + type = list(string) + default = [] +} + +variable "saml_idp_metadata_url" { + description = "SAML authentication IDP Metadata URL. Note that either `saml_idp_metadata_url` or `saml_idp_metadata_xml`" + type = string + default = null +} + +variable "saml_idp_metadata_xml" { + description = "SAML authentication IDP Metadata XML. Note that either `saml_idp_metadata_url` or `saml_idp_metadata_xml`" + type = string + default = null +} + +variable "saml_admin_role_values" { + description = "SAML authentication admin role values" + type = list(string) + default = [] +} + +variable "saml_allowed_organizations" { + description = "SAML authentication allowed organizations" + type = list(string) + default = [] +} + +variable "saml_email_assertion" { + description = "SAML authentication email assertion" + type = string + default = null +} + +variable "saml_groups_assertion" { + description = "SAML authentication groups assertion" + type = string + default = null +} + +variable "saml_login_assertion" { + description = "SAML authentication email assertion" + type = string + default = null +} + +variable "saml_login_validity_duration" { + description = "SAML authentication login validity duration" + type = number + default = null +} + +variable "saml_name_assertion" { + description = "SAML authentication name assertion" + type = string + default = null +} + +variable "saml_org_assertion" { + description = "SAML authentication org assertion" + type = string + default = null +} + +variable "saml_role_assertion" { + description = "SAML authentication role assertion" + type = string + default = null +} + +################################################################################ +# License Association +################################################################################ + +variable "associate_license" { + description = "Determines whether a license will be associated with the workspace" + type = bool + default = true +} + +variable "license_type" { + description = "The type of license for the workspace license association. Valid values are `ENTERPRISE` and `ENTERPRISE_FREE_TRIAL`" + type = string + default = "ENTERPRISE" +} + +################################################################################ +# Role Association +################################################################################ + +variable "role_associations" { + description = "Map of maps to assocaite user/group IDs to a role. Map key can be used as the `role`" + type = any + default = {} +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..03533eb --- /dev/null +++ b/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.13.1" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.4" + } + } +}
"AWS_SSO"
]