{"id":22448214,"url":"https://github.com/ridwanbejo/terraform-airflow-user","last_synced_at":"2025-03-27T11:29:00.260Z","repository":{"id":206700532,"uuid":"717332685","full_name":"ridwanbejo/terraform-airflow-user","owner":"ridwanbejo","description":"Terraform module for managing Airflow Users and Roles ","archived":false,"fork":false,"pushed_at":"2023-11-11T17:26:56.000Z","size":11,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-01T16:12:17.090Z","etag":null,"topics":["airflow","automation","devops","hashicorp","hcl","iac","infrastructure-as-code","terraform","terraform-module"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ridwanbejo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-11T06:17:21.000Z","updated_at":"2024-01-08T02:05:16.000Z","dependencies_parsed_at":"2023-11-11T18:24:57.551Z","dependency_job_id":"696d610c-7924-48d5-b136-6b3790296fc7","html_url":"https://github.com/ridwanbejo/terraform-airflow-user","commit_stats":null,"previous_names":["ridwanbejo/terraform-airflow-user"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-airflow-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-airflow-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-airflow-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-airflow-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridwanbejo","download_url":"https://codeload.github.com/ridwanbejo/terraform-airflow-user/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245835453,"owners_count":20680207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["airflow","automation","devops","hashicorp","hcl","iac","infrastructure-as-code","terraform","terraform-module"],"created_at":"2024-12-06T04:21:54.089Z","updated_at":"2025-03-27T11:29:00.236Z","avatar_url":"https://github.com/ridwanbejo.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform Airflow User\n\nThis is a Terraform module for managing Users and Roles at Apache Airflow. You can use this module both for commercial or non-commercial purposes.\n\nCurrently, you can manage these resources in Airflow by using this module:\n\n- Users\n- Roles\n- Connect to Airflow API with Basic Auth\n\nTested in:\n\n- Apache Airflow ✅\n- Astronomer ❌\n\n## A. Prerequisites\n\nRequirements:\n\n- Terraform with version \u003e= 1.4\n- DrFaust92/airflow\n- Hashicorp/random\n- Airflow hostname\n- Airflow username -\u003e `TF_VAR_airflow_username`\n- Airflow password -\u003e `TF_VAR_airflow_password`\n\n## B. How to use this module for your Terraform project ?\n\n- Copy `example` project from this module. You can extend it as per your requirements\n- Configure Airflow hostname by modifying the `providers.tf`. For example `http://localhost:8080/`\n- Configure `TF_VAR_airflow_username` and `TF_VAR_airflow_username` as environment variables. For example:\n\n```\n$ export TF_VAR_airflow_username=airflow\n$ export TF_VAR_airflow_password=airflow\n```\n\n- Create `terraform.tfvars` inside the Project. Then copy this sample terraform.tfvars into the file:\n\n```\nairflow_roles = [\n  {\n    name    = \"custom-role-1\"\n    actions = [\n      {\n        name     = \"can_read\"\n        resource = \"Audit Logs\"\n      }\n    ]\n  },\n  {\n    name    = \"custom-role-2\"\n    actions = [\n      {\n        name     = \"can_read\"\n        resource = \"Audit Logs\"\n      },\n      {\n        name     = \"can_read\"\n        resource = \"DAGs\"\n      }\n    ]\n  },\n  {\n    name    = \"custom-role-3\"\n    actions = [\n      {\n        name     = \"can_read\"\n        resource = \"Variables\"\n      }\n    ]\n  },\n]\n\nairflow_users = [\n  {\n    email      = \"ridwanbejo@gmail.com\"\n    first_name = \"Ridwan\"\n    last_name  = \"Bejo\"\n    username   = \"ridwanbejo\"\n    roles      = [\"Viewer\"]\n  },\n  {\n    email      = \"sakura.machiya@gmail.com\"\n    first_name = \"Sakura\"\n    last_name  = \"Machiya\"\n    username   = \"sakuramachi\"\n    roles      = [\"Viewer\"]\n  },\n  {\n    email      = \"peter.dart@gmail.com\"\n    first_name = \"Peter\"\n    last_name  = \"Dart\"\n    username   = \"peterdart\"\n    roles      = [\"custom-role-1\"]\n  },\n  {\n    email      = \"eliza.fangerbau@gmail.com\"\n    first_name = \"Eliza\"\n    last_name  = \"Fangerbau\"\n    username   = \"elizafang\"\n    roles      = [\"custom-role-2\"]\n  },\n  {\n    email      = \"michelle.wang@gmail.com\"\n    first_name = \"Michelle\"\n    last_name  = \"Wang\"\n    username   = \"michwang\"\n    roles      = [\"custom-role-2\", \"custom-role-3\"]\n  }\n]\n ```\n\n- Adjust the tfvars based on your requirements. The tfvars above is just example. Then, Save it\n- Run these commands:\n\n```\n$ terraform init\n$ terraform plan\n```\nThis is the output when you run terraform plan successfully:\n\n```\n...\n\n # module.tf_airflow_users.random_password.password[\"sakuramachi\"] will be created\n  + resource \"random_password\" \"password\" {\n      + bcrypt_hash      = (sensitive value)\n      + id               = (known after apply)\n      + length           = 16\n      + lower            = true\n      + min_lower        = 0\n      + min_numeric      = 0\n      + min_special      = 0\n      + min_upper        = 0\n      + number           = true\n      + numeric          = true\n      + override_special = \"!#$%\u0026*()-_=+[]{}\u003c\u003e:?\"\n      + result           = (sensitive value)\n      + special          = true\n      + upper            = true\n    }\n\nPlan: 13 to add, 0 to change, 0 to destroy.\n\nChanges to Outputs:\n  + airflow_users = {\n      + elizafang   = \"eliza.fangerbau@gmail.com\"\n      + michwang    = \"michelle.wang@gmail.com\"\n      + peterdart   = \"peter.dart@gmail.com\"\n      + ridwanbejo  = \"ridwanbejo@gmail.com\"\n      + sakuramachi = \"sakura.machiya@gmail.com\"\n    }\n```\n\nAfter you feel confidence with the terraform plan output, let's apply it.\n\n```\n$ terraform apply -auto-approve\n```\n\n- If it succeed, you must see this kind of output on your terminal\n\n```\n...\n\nmodule.tf_airflow_users.random_password.password[\"elizafang\"]: Creation complete after 0s [id=none]\nmodule.tf_airflow_users.random_password.password[\"peterdart\"]: Creation complete after 0s [id=none]\nmodule.tf_airflow_users.random_password.password[\"ridwanbejo\"]: Creation complete after 0s [id=none]\nmodule.tf_airflow_users.airflow_role.roles[\"custom-role-1\"]: Creation complete after 0s [id=custom-role-1]\nmodule.tf_airflow_users.airflow_role.roles[\"custom-role-2\"]: Creation complete after 0s [id=custom-role-2]\nmodule.tf_airflow_users.airflow_role.roles[\"custom-role-3\"]: Creation complete after 0s [id=custom-role-3]\nmodule.tf_airflow_users.airflow_user.users[\"elizafang\"]: Creating...\nmodule.tf_airflow_users.airflow_user.users[\"ridwanbejo\"]: Creating...\nmodule.tf_airflow_users.airflow_user.users[\"sakuramachi\"]: Creating...\nmodule.tf_airflow_users.airflow_user.users[\"michwang\"]: Creating...\nmodule.tf_airflow_users.airflow_user.users[\"peterdart\"]: Creating...\nmodule.tf_airflow_users.airflow_user.users[\"sakuramachi\"]: Creation complete after 1s [id=sakuramachi]\nmodule.tf_airflow_users.airflow_user.users[\"elizafang\"]: Creation complete after 1s [id=elizafang]\nmodule.tf_airflow_users.airflow_user.users[\"michwang\"]: Creation complete after 1s [id=michwang]\nmodule.tf_airflow_users.airflow_user.users[\"ridwanbejo\"]: Creation complete after 1s [id=ridwanbejo]\nmodule.tf_airflow_users.airflow_user.users[\"peterdart\"]: Creation complete after 1s [id=peterdart]\n\nApply complete! Resources: 13 added, 0 changed, 0 destroyed.\n\nOutputs:\n\nairflow_users = {\n  \"elizafang\" = \"eliza.fangerbau@gmail.com\"\n  \"michwang\" = \"michelle.wang@gmail.com\"\n  \"peterdart\" = \"peter.dart@gmail.com\"\n  \"ridwanbejo\" = \"ridwanbejo@gmail.com\"\n  \"sakuramachi\" = \"sakura.machiya@gmail.com\"\n}\n```\n\nNow you can check the Airflow List Roles page and List User page to see the applied changes.\n\n## C. Understanding tfvars scenarios\n\nThere are some scenarios that you could choose by using this module. For example:\n\n1. create users without specifying custom role. For example you can choose `Viewer` role and assign it to users.\n\n```\nairflow_users = [\n  {\n    email      = \"ridwanbejo@gmail.com\"\n    first_name = \"Ridwan\"\n    last_name  = \"Bejo\"\n    username   = \"ridwanbejo\"\n    roles      = [\"Viewer\"]\n  },\n  {\n    email      = \"sakura.machiya@gmail.com\"\n    first_name = \"Sakura\"\n    last_name  = \"Machiya\"\n    username   = \"sakuramachi\"\n    roles      = [\"Viewer\"]\n  }\n]\n```\n\n\u003e In Airflow, there are some roles by default when you have Airflow fresh installation. Those roles are `Admin`, `Viewer`, `User`, `Op`, `Public`. I use `Viewer` because that was the default role which are provided by Airflow.\n\n2. create users with custom role\n\n```\nairflow_users = [\n  {\n    email      = \"peter.dart@gmail.com\"\n    first_name = \"Peter\"\n    last_name  = \"Dart\"\n    username   = \"peterdart\"\n    roles      = [\"custom-role-1\"]\n  },\n  {\n    email      = \"eliza.fangerbau@gmail.com\"\n    first_name = \"Eliza\"\n    last_name  = \"Fangerbau\"\n    username   = \"elizafang\"\n    roles      = [\"custom-role-2\"]\n  }\n]\n```\n\n3. create user with multiple roles\n\n```\nairflow_users = [\n  {\n    email      = \"michelle.wang@gmail.com\"\n    first_name = \"Michelle\"\n    last_name  = \"Wang\"\n    username   = \"michwang\"\n    roles      = [\"custom-role-2\", \"custom-role-3\"]\n  }\n]\n```\n\n## D. Ensuring quality\n\nI am trying to follow these approaches for ensuring quality of the tf-module:\n\n- **validate**, ensure my Terraform module is in correct configuration based on Terraform guideline\n- **auto-format**, ensure my Terraform script is edited with correct format based on Terraform guideline\n- **linter**, ensure my Terraform script is in correct format based on Terraform guideline\n- **tests**, ensure my Terraform module is processing correct variables and yield expected outputs\n- **security**, ensure my Terraform module is free from CVE and stay compliance\n- **automation**, run all above steps by using automation tool to improve development time and keep best quality before or after merging to Git repository\n\n\nThe tools:\n\n- [terraform validate](https://developer.hashicorp.com/terraform/cli/commands)\n- [terraform fmt](https://developer.hashicorp.com/terraform/cli/commands)\n- [tflint](https://github.com/terraform-lint48ers/tflint)\n- [terraform tests](https://developer.hashicorp.com/terraform/language/tests)\n- [tfsec](https://github.com/aquasecurity/tfsec)\n- [Pre-commit](https://pre-commit.com/)\n- Github Action [Setup Terraform pipeline](https://github.com/hashicorp/setup-terraform)\n\n## E. How to contribute ?\n\nIf you find any issue, you can raise it here at our [Issue Tracker](https://github.com/ridwanbejo/terraform-airflow-user/issues)\n\nIf you have something that you want to merge to this repo, just raise [Pull Requests](https://github.com/ridwanbejo/terraform-airflow-user/pulls)\n\nEnsure that you install all the tools from section D. for development purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-airflow-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridwanbejo%2Fterraform-airflow-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-airflow-user/lists"}