Skip to content

Commit

Permalink
feat: add project
Browse files Browse the repository at this point in the history
  • Loading branch information
KoLiBer committed Aug 31, 2024
1 parent 672a7a4 commit 78a7636
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/.releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tagFormat: $${q}{version}
branches:
- main
- master
- +([0-9])?(.{+([0-9]),x}).x
- { name: next, prerelease: true }
- { name: beta, prerelease: true }
- { name: alpha, prerelease: true }
- { name: stable, prerelease: true }
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- "@semantic-release/github"
- - "@semantic-release/git"
- assets: [CHANGELOG.md]
42 changes: 42 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI/CD

on:
pull_request: { branches: ["*"] }
push:
branches:
- "+([0-9])?(.{+([0-9]),x}).x"
- master
- main
- next

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.9.5"
- uses: actions/cache@v2
with:
path: .terraform/
key: ${{ hashFiles('.terraform.lock.hcl') }}

- run: terraform init
- run: terraform fmt -check
- run: terraform validate -no-color

bump:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20

- run: npm i -g semantic-release @semantic-release/changelog @semantic-release/github @semantic-release/git
- run: cat .github/.releaserc.yml | envsubst > .releaserc.yml && semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# 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

# dotenv environment variables file
.env
25 changes: 25 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022-present, KoLiBer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,63 @@
# terraform-sentry-organization
Terraform Sentry Organization Module
# Terraform Sentry Organization

![pipeline](https://github.com/cktf/terraform-sentry-organization/actions/workflows/cicd.yml/badge.svg)
![release](https://img.shields.io/github/v/release/cktf/terraform-sentry-organization?display_name=tag)
![license](https://img.shields.io/github/license/cktf/terraform-sentry-organization)

**Organization** is a Terraform module useful for creating multiple teams and projects in **Sentry**

## Installation

Add the required configurations to your terraform config file and install module using command bellow:

```bash
terraform init
```

## Usage

```hcl
module "sentry" {
source = "cktf/organization/sentry"
slug = "myorg"
name = "MyOrg"
teams = {
backend = {
slug = "backend"
name = "Backend"
}
frontend = {
slug = "backend"
name = "Frontend"
}
}
projects = {
app1 = {
slug = "app1"
name = "App1"
teams = ["backend"]
}
app2 = {
slug = "app2"
name = "App2"
teams = ["backend", "frontend"]
platform = "django"
}
}
}
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

This project is licensed under the [MIT](LICENSE.md).
Copyright (c) KoLiBer (koliberr136a1@gmail.com)
9 changes: 9 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.5.0"
required_providers {
sentry = {
source = "jianyuan/sentry"
version = ">= 0.13.0"
}
}
}
24 changes: 24 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "id" {
value = local.org_id
sensitive = false
description = "Organization ID"
}

output "teams" {
value = { for key, val in sentry_team.this : key => val.id }
sensitive = false
description = "Organization Teams"
}

output "projects" {
value = {
for key, val in sentry_project.this : key => {
id = val.id
dsn_csp = sentry_key.this[key].dsn_csp
dsn_public = sentry_key.this[key].dsn_public
dsn_secret = sentry_key.this[key].dsn_secret
}
}
sensitive = false
description = "Organization Projects"
}
19 changes: 19 additions & 0 deletions projects.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "sentry_project" "this" {
depends_on = [sentry_team.this]
for_each = var.projects

organization = local.org_id
slug = each.value.slug
name = each.value.name
teams = each.value.teams
platform = each.value.platform
default_key = false
}

resource "sentry_key" "this" {
for_each = var.projects

organization = local.org_id
project = sentry_project.this[each.key].id
name = "default"
}
11 changes: 11 additions & 0 deletions root.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "sentry_organization" "this" {
count = var.id == null ? 1 : 0

slug = var.slug
name = var.name
agree_terms = true
}

locals {
org_id = coalesce(var.id, sentry_organization.this[0].id)
}
7 changes: 7 additions & 0 deletions teams.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "sentry_team" "this" {
for_each = var.teams

organization = local.org_id
slug = each.value.slug
name = each.value.name
}
42 changes: 42 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
variable "id" {
type = string
default = null
sensitive = false
description = "Organization ID"
}

variable "slug" {
type = string
default = ""
sensitive = false
description = "Organization Slug"
}

variable "name" {
type = string
default = ""
sensitive = false
description = "Organization Name"
}

variable "teams" {
type = map(object({
slug = string
name = string
}))
default = {}
sensitive = false
description = "Project Teams"
}

variable "projects" {
type = map(object({
slug = string
name = string
teams = optional(list(string), [])
platform = optional(string)
}))
default = {}
sensitive = false
description = "Project Projects"
}

0 comments on commit 78a7636

Please sign in to comment.