Skip to content

Commit

Permalink
Add documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gigerdo committed Sep 9, 2024
1 parent c6827b7 commit 2fe8035
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
120 changes: 120 additions & 0 deletions docs/resources/organization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
page_title: "Elastic Cloud: ec_organization Resource"
description: |-
Manages an Elastic Cloud organization membership.
~> **This resource can only be used with Elastic Cloud SaaS**
---

# Resource: ec_organization

Manages an Elastic Cloud organization membership.

~> **This resource can only be used with Elastic Cloud SaaS**

## Example Usage

### Import

To import an organization into terraform, first define your organization configuration in your terraform file. For example:
```terraform
resource "ec_organization" "myorg" {
}
```

Then import the organization using your organization-id (The organization id can be found on [the organization page](https://cloud.elastic.co/account/members))
```bash
terraform import ec_organization.myorg <organization-id>
```

Now you can run `terraform plan` to see if there are any diffs between your config and how your organization is currently configured.

### Basic

```terraform
resource "ec_organization" "my_org" {
members = {
"[email protected]" = {
# All role definitions are optional
# Define roles for the whole organization
# Available roles are documented here: https://www.elastic.co/guide/en/cloud/current/ec-user-privileges.html#ec_organization_level_roles
organization_role = "billing-admin"
# Define deployment-specific roles
# Available roles are documented here: https://www.elastic.co/guide/en/cloud/current/ec-user-privileges.html#ec_instance_access_roles
deployment_roles = [
# A role can be given for all deployments
{
role = "editor"
for_all_deployments = true
},
# Or just for specific deployments
{
role = "editor"
deployment_ids = ["ce03a623751b4fc98d48400fec58b9c0"]
}
]
# Define roles for elasticsearch projects (Docs: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#es)
project_elasticsearch_roles = [
# A role can be given for all projects
{
role = "admin"
for_all_projects = true
},
# Or just for specific projects
{
role = "admin"
project_ids = ["c866244b611442d585e23a0cc8c9434c"]
}
]
project_observability_roles = [
# Same as for an elasticsearch project
# Available roles are documented here: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#observability
]
project_security_roles = [
# Same as for an elasticsearch project
# Available roles are documented here: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#security
]
}
}
}
```

### Use variables to give the same roles to multiple users

```terraform
# To simplify managing multiple members with the same roles, the roles can be assigned to local variables
locals {
deployment_admin = {
deployment_roles = [
{
role = "admin"
for_all_deployments = true
}
]
}
deployment_viewer = {
deployment_roles = [
{
role = "viewer"
for_all_deployments = true
}
]
}
}
resource "ec_organization" "my_org" {
members = {
"[email protected]" = local.deployment_admin
"[email protected]" = local.deployment_viewer
"[email protected]" = local.deployment_viewer
}
}
```
52 changes: 52 additions & 0 deletions examples/resources/ec_organization/basic.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
resource "ec_organization" "my_org" {
members = {
"[email protected]" = {
# All role definitions are optional

# Define roles for the whole organization
# Available roles are documented here: https://www.elastic.co/guide/en/cloud/current/ec-user-privileges.html#ec_organization_level_roles
organization_role = "billing-admin"

# Define deployment-specific roles
# Available roles are documented here: https://www.elastic.co/guide/en/cloud/current/ec-user-privileges.html#ec_instance_access_roles
deployment_roles = [
# A role can be given for all deployments
{
role = "editor"
for_all_deployments = true
},

# Or just for specific deployments
{
role = "editor"
deployment_ids = ["ce03a623751b4fc98d48400fec58b9c0"]
}
]

# Define roles for elasticsearch projects (Docs: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#es)
project_elasticsearch_roles = [
# A role can be given for all projects
{
role = "admin"
for_all_projects = true
},

# Or just for specific projects
{
role = "admin"
project_ids = ["c866244b611442d585e23a0cc8c9434c"]
}
]

project_observability_roles = [
# Same as for an elasticsearch project
# Available roles are documented here: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#observability
]

project_security_roles = [
# Same as for an elasticsearch project
# Available roles are documented here: https://www.elastic.co/docs/current/serverless/general/assign-user-roles#security
]
}
}
}
28 changes: 28 additions & 0 deletions examples/resources/ec_organization/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# To simplify managing multiple members with the same roles, the roles can be assigned to local variables
locals {
deployment_admin = {
deployment_roles = [
{
role = "admin"
for_all_deployments = true
}
]
}

deployment_viewer = {
deployment_roles = [
{
role = "viewer"
for_all_deployments = true
}
]
}
}

resource "ec_organization" "my_org" {
members = {
"[email protected]" = local.deployment_admin
"[email protected]" = local.deployment_viewer
"[email protected]" = local.deployment_viewer
}
}
34 changes: 34 additions & 0 deletions templates/resources/organization.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
page_title: "Elastic Cloud: {{ .Name }} {{ .Type }}"
description: |-
{{ .Description }}
---

# {{ .Type }}: {{ .Name }}

{{ .Description }}

## Example Usage

### Import

To import an organization into terraform, first define your organization configuration in your terraform file. For example:
```terraform
resource "ec_organization" "myorg" {
}
```

Then import the organization using your organization-id (The organization id can be found on [the organization page](https://cloud.elastic.co/account/members))
```bash
terraform import ec_organization.myorg <organization-id>
```

Now you can run `terraform plan` to see if there are any diffs between your config and how your organization is currently configured.

### Basic

{{ tffile "examples/resources/ec_organization/basic.tf" }}

### Use variables to give the same roles to multiple users

{{ tffile "examples/resources/ec_organization/locals.tf" }}

0 comments on commit 2fe8035

Please sign in to comment.