diff --git a/examples/get-started/README.md b/examples/get-started/README.md new file mode 100644 index 000000000..cd4e3cab7 --- /dev/null +++ b/examples/get-started/README.md @@ -0,0 +1,151 @@ +# Get started with Aiven Provider for Terraform + +Introduction + + + + +## Prerequisites + +* [Install Terraform](https://www.terraform.io/downloads) +* [Sign up for Aiven](https://console.aiven.io/signup?utm_source=github&utm_medium=organic&utm_campaign=devportal&utm_content=repo) +* [Create an authentication token](https://docs.aiven.io/docs/platform/howto/create_authentication_token.html) + +## Create your first Aiven resources + +1. Ensure that you have Terraform v0.13.0 or higher installed. To check the version, run: + +```sh +$ terraform --version +``` + +The output is similar to the following: + +```sh +Terraform v1.6.2 ++ provider registry.terraform.io/aiven/aiven v4.9.2 +``` + +2. Clone this repository. + +3. Replace the placeholders in the `get-started.tf` file. It's recommended to use your organization name as a prefix for the project name. + +4. Initialize Terraform: + +```sh +$ terraform init +``` + +The output is similar to the following: + +```sh + +Initializing the backend... + +Initializing provider plugins... +- Finding aiven/aiven versions matching ">= 4.0.0, < 5.0.0"... +- Installing aiven/aiven v4.9.2... +- Installed aiven/aiven v4.9.2 +... +Terraform has been successfully initialized! +... +``` + +5. To create an execution plan and preview the changes that will be made, run: + +```sh +$ terraform plan + +``` + +6. To deploy your changes, run: + +```sh +$ terraform apply +``` + +The output will be similar to the following: +```sh + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + + # aiven_organization_group_project.group-proj will be created + + resource "aiven_organization_group_project" "group-proj" { +... +Plan: 2 to add, 0 to change, 0 to destroy. +``` + +7. Enter yes to confirm. The output will be similar to the following: + +```sh +Do you want to perform these actions? + Terraform will perform the actions described above. + Only 'yes' will be accepted to approve. + + Enter a value: yes + +aiven_project.example-project: Creating... +... +Apply complete! Resources: 2 added, 0 changed, 0 destroyed. +``` + +## Verify the changes in the Aiven Console + +You can see your project and user group in the [Aiven Console](https://console.aiven.io/): + +1. In the organization, click **Projects** and select your project. + +2. Click **Members** to see the user group you added to this project. + + +To see the user group details: + +1. Click **Admin**. + +2. Click **Groups**. + +3. Select the user group to see more information, including the members of the group. + + +## Clean up + +To delete the example project and user group: + +1. To preview the changes first, run: + +```sh +$ terraform plan -destroy +``` + +The output shows what changes will be made when you run the `destroy` command. + +2. To delete all resources, run: + +```sh +$ terraform destroy +``` + +3. Enter yes to confirm the changes: + +```sh +Plan: 0 to add, 0 to change, 4 to destroy +... + +Do you really want to destroy all resources? + Terraform will destroy all your managed infrastructure, as shown above. + There is no undo. Only 'yes' will be accepted to confirm. + + Enter a value: yes +``` + +The output will be similar to the following: + +```sh +... +aiven_organization_user_group_member.group-members: Destroying... +... +Destroy complete! Resources: 4 destroyed. +``` diff --git a/examples/get-started/get-started.tf b/examples/get-started/get-started.tf new file mode 100644 index 000000000..5b59353e0 --- /dev/null +++ b/examples/get-started/get-started.tf @@ -0,0 +1,48 @@ +terraform { + required_providers { + aiven = { + source = "aiven/aiven" + version = ">=4.0.0, <5.0.0" + } + } +} + +variable "aiven_api_token" {} + + +provider "aiven" { + api_token = var.aiven_api_token +} + +# Your organization +data "aiven_organization" "org" { + name = "YOUR_ORGANIZATION_NAME" +} + +# Create a project in your organization +resource "aiven_project" "example-project" { + project = "ORGANIZATION_NAME-first-project" + parent_id = data.aiven_organization.org.id +} + +# Create a user group +resource "aiven_organization_user_group" "group" { + organization_id = data.aiven_organization.org.id + name = "Example user group" + description = "The first user group for this organization." +} + +# Add an existing organization user to the group +resource "aiven_organization_user_group_member" "group-members" { + group_id = aiven_organization_user_group.group.group_id + organization_id = data.aiven_organization.org.id + user_id = "USER_ID" +} + +# Give the group access to your project with the developer role +resource "aiven_organization_group_project" "group-proj" { + group_id = aiven_organization_user_group.group.group_id + project = aiven_project.example-project.project + role = "developer" +} + diff --git a/examples/getting-started.tf b/examples/getting-started.tf deleted file mode 100644 index f6bc1ca89..000000000 --- a/examples/getting-started.tf +++ /dev/null @@ -1,59 +0,0 @@ -terraform { - required_providers { - aiven = { - source = "aiven/aiven" - version = ">=4.0.0, <5.0.0" - } - } -} - -variable "aiven_api_token" { - type = string -} - -provider "aiven" { - api_token = var.aiven_api_token -} - -resource "aiven_project" "foo" { - project = "project-1" - account_id = aiven_account_team.foo.account_id -} - -# Account -resource "aiven_account" "foo" { - name = "account1" -} - -# Account team -resource "aiven_account_team" "foo" { - account_id = aiven_account.foo.account_id - name = "account_team1" -} - -# Account team project -resource "aiven_account_team_project" "foo" { - account_id = aiven_account.foo.account_id - team_id = aiven_account_team.foo.team_id - project_name = aiven_project.foo.project - team_type = "admin" -} - -# Account team member -resource "aiven_account_team_member" "foo" { - account_id = aiven_account.foo.account_id - team_id = aiven_account_team.foo.team_id - user_email = "user+1@example.com" -} - -data "aiven_account_team" "team" { - name = aiven_account_team.foo.name - account_id = aiven_account_team.foo.account_id -} - -data "aiven_account_team_member" "member" { - team_id = aiven_account_team_member.foo.team_id - account_id = aiven_account_team_member.foo.account_id - user_email = aiven_account_team_member.foo.user_email -} -