From 16485e940a0786c157f2da676838f7c3e982a30d Mon Sep 17 00:00:00 2001 From: kosta709 Date: Tue, 28 Jul 2020 00:44:06 +0300 Subject: [PATCH] change_account module --- README.md | 11 ++++- docs/data/account.md | 39 ++++++++++++++++ docs/data/idps.md | 66 +++++++++++++++++++++++++++ docs/data/team.md | 20 ++++++++ docs/resources/permissions.md | 6 +++ tf_modules/change_account/main.tf | 39 ++++++++++++++++ tf_modules/change_account/provider.tf | 4 ++ tf_modules/change_account/vars.tf | 13 ++++++ 8 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 docs/data/account.md create mode 100644 docs/data/idps.md create mode 100644 docs/data/team.md create mode 100644 docs/resources/permissions.md create mode 100644 tf_modules/change_account/main.tf create mode 100644 tf_modules/change_account/provider.tf create mode 100644 tf_modules/change_account/vars.tf diff --git a/README.md b/README.md index 0c8f0e19..37051279 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,12 @@ The provider is still under development, and can be used as a terraform [third-p ## Requirements -- [Terraform](https://www.terraform.io/downloads.html) 0.11+ ; +- [Terraform](https://www.terraform.io/downloads.html) 0.12+ ; - [Go](https://golang.org/doc/install) 1.12+ (to build the provider plugin). +## Download Provider +Download and extract terraform-provider-codefresh from [releases](https://github.com/codefresh-io/terraform-provider-codefresh/releases) + ## Building the Provider ```sh @@ -24,7 +27,11 @@ For Linux OS it can be: - _~/.terraform.d/plugins/linux\_amd64_ - _./terraform.d/plugins/linux\_amd64_. The relative path in your Terraform project. -To configure codefresh provider: +## [Documentations](./docs) + +## [Examples](./examples) + +## To configure codefresh provider: ```hcl provider "codefresh" { diff --git a/docs/data/account.md b/docs/data/account.md new file mode 100644 index 00000000..6945569e --- /dev/null +++ b/docs/data/account.md @@ -0,0 +1,39 @@ +# account data module + +``` +data "codefresh_account" "acc" { + name = "acc1" +} + +resource "codefresh_user" "user1" { + email = "user1@example.com" + user_name = "user1" + + accounts = [ + data.codefresh_account.acc.id + ] + + activate = true + + roles = [ + "Admin", + "User" + ] + + login { + idp_id = data.codefresh_idps.idp_azure.id + sso = true + } + + login { + idp_id = data.codefresh_idps.local.id + //sso = false + } + + + personal { + first_name = "John" + last_name = "Smith" + } +} +``` \ No newline at end of file diff --git a/docs/data/idps.md b/docs/data/idps.md new file mode 100644 index 00000000..828ba029 --- /dev/null +++ b/docs/data/idps.md @@ -0,0 +1,66 @@ +# data codefresh_idps +``` +data "codefresh_idps" "idp_azure" { + display_name = "codefresh-onprem-tst-2" + # client_name = "2222" + # _id = "5df234543" + client_type = "azure" +} + +data "codefresh_idps" "local" { + display_name = "local" +} + +resource "codefresh_account" "acc" { + name = "acc1" + + features = var.accountFeatures + + limits { + collaborators = 25 + data_retention_weeks = 5 + } + + build { + parallel = 25 + nodes = 7 + } + +} + +resource "codefresh_user" "user1" { + email = "user1@example.com" + user_name = "user1" + + activate = true + + roles = [ + "Admin", + "User" + ] + + login { + idp_id = data.codefresh_idps.idp_azure.id + sso = true + } + + login { + idp_id = data.codefresh_idps.local.id + //sso = false + } + + personal { + first_name = "John" + last_name = "Smith" + } + + accounts = [ + codefresh_account.acc.id + ] +} + +resource "codefresh_idp_accounts" "acc_idp" { + idp_id = data.codefresh_idps.idp_azure.id + account_ids = [codefresh_account.acc.id] +} +``` \ No newline at end of file diff --git a/docs/data/team.md b/docs/data/team.md new file mode 100644 index 00000000..b1c3f7de --- /dev/null +++ b/docs/data/team.md @@ -0,0 +1,20 @@ +# data codefresh_team + +*Note*: Teams resources should be called with account specific access token + +``` +data "codefresh_team" "admin" { + provider = codefresh.acc1 + name = "users" +} + +resource "codefresh_permission" "permission2" { + provider = codefresh.acc1 + team = data.codefresh_team.admin.id + action = "create" + resource = "pipeline" + tags = ["frontend"] +} + +``` + diff --git a/docs/resources/permissions.md b/docs/resources/permissions.md new file mode 100644 index 00000000..3395ae81 --- /dev/null +++ b/docs/resources/permissions.md @@ -0,0 +1,6 @@ +# resource codefresh_permission + +``` + + +``` \ No newline at end of file diff --git a/tf_modules/change_account/main.tf b/tf_modules/change_account/main.tf new file mode 100644 index 00000000..9267ff8b --- /dev/null +++ b/tf_modules/change_account/main.tf @@ -0,0 +1,39 @@ +data "codefresh_account" "acc" { + name = var.account_id +} + +resource "random_string" "random" { + length = 16 + special = false +} + +resource "codefresh_api_key" "new" { + account_id = data.codefresh_account.acc.id + user_id = data.codefresh_account.acc.admins[0] + name = "tfkey_${random_string.random.result}" + + scopes = [ + "agent", + "agents", + "audit", + "build", + "cluster", + "clusters", + "environments-v2", + "github-action", + "helm", + "kubernetes", + "pipeline", + "project", + "repos", + "runner-installation", + "step-type", + "step-types", + "view", + "workflow", + ] +} + +output "token" { + value = codefresh_api_key.new.token +} \ No newline at end of file diff --git a/tf_modules/change_account/provider.tf b/tf_modules/change_account/provider.tf new file mode 100644 index 00000000..615d72a3 --- /dev/null +++ b/tf_modules/change_account/provider.tf @@ -0,0 +1,4 @@ +provider "codefresh" { + api_url = var.api_url + token = var.token +} \ No newline at end of file diff --git a/tf_modules/change_account/vars.tf b/tf_modules/change_account/vars.tf new file mode 100644 index 00000000..699159ab --- /dev/null +++ b/tf_modules/change_account/vars.tf @@ -0,0 +1,13 @@ +variable api_url { + type = string +} + +# +variable token { + type = string + default = "" +} + +variable account_id { + type = string +}