oncall-engine/terraform
Joey Orlando 933e7256e3
move local developer resources to ./dev folder (#2479)
# What this PR does

As part of #1953, I wanted to be able to easily locally modify my
Grafana instance's access control provisioning configuration. In the
`grafana` container in `docker-compose-developer.yml`, we already have
this:
```yml
volumes:
  - ./provisioning:/etc/grafana/provisioning
```
The `dev` directory has a `.gitignore` setup which is better suited for
what I would like to do. By default, if I add
`./dev/grafana/provisioning/access-control/custom-roles.yml`, it will be
git-ignored. This would've not been the case with the `./provisioning`
directory

*Other stuff*
- create `./dev/grafana` folder. This folder contains resources that are
volume mounted into the `grafana` container in
`docker-compose-developer.yml`.
  - We already had a `./dev/grafana.dev.ini` file, relocated this here.
  - Relocated `./provisioning` to `./dev/grafana/provisioning`. 
- consolidate `./examples/terraform` into `./terraform` directory

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required) (N/A)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (N/A)
2023-07-10 06:09:22 -04:00
..
examples move local developer resources to ./dev folder (#2479) 2023-07-10 06:09:22 -04:00
README.md Add terraform readme (#2349) 2023-07-05 11:22:26 +00:00

Grafana OnCall Terraform Plugin

Use the Grafana Terraform provider to manage OnCall resources, such as schedules, escalation chains and more within your “as-code” workflow.

To learn more:

How to build OnCall Terraform plugin locally (developer notes)

Refer to Terraform provider README.md for more details.

  1. Clone Grafana OnCall Go Client repo and make local changes

  2. Clone Grafana Terraform plugin repo, check Readme and make local changes

  3. Set env variables

    Warning: you might want to set another OS_ARCH, provided value are for Apple Silicon

    export BINARY=terraform-provider-grafana
    OS_ARCH=darwin_arm64
    HOSTNAME=grafana.com
    NAMESPACE=raintank
    NAME=grafana
    VERSION=1.0.0
    
  4. Build provider

    go build -o ${BINARY}
    
  5. If there are changes to grafana/amixr-api-go-client/ make sure to replace it in provider's go.mod:

    Warning: this command is example, name or version of api client might and will change, check provider's go.mod

    // TODO: remove this after testing
    replace github.com/grafana/amixr-api-go-client v0.0.8 => /YOUR_LOCAL_PATH/amixr-api-go-client
    
  6. Create a .terraformrc in $HOME directory and paste the following

    provider_installation {
      dev_overrides {
          "grafana/grafana" = "/path/to/your/grafana/terraform-provider" # this path is the directory where the binary is built
      }
    
  7. Create a new directory and a main.tf file with the following content:

    terraform {
      required_providers {
        grafana = {
          source  = "grafana/grafana"
          version = "1.0.0"
        }
      }
    }
    
    provider "grafana" {
      alias = "oncall"
      oncall_access_token = 
      oncall_url          =  
    }
    
  8. Run the following commands to initialize Terraform and apply the configuration:

    terrafrom init
    terraform plan/apply