diff --git a/examples/main.tf b/examples/main.tf new file mode 100644 index 0000000..5cceb5e --- /dev/null +++ b/examples/main.tf @@ -0,0 +1,49 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXAMPLE FULL USAGE OF THE TERRAFORM-KUBERNETES-CLUSTER-ROLE MODULE +# +# And some more meaningful information. +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +module "terraform-kubernetes-cluster-role" { + source = "git@github.com:mineiros-io/terraform-google-service-account.git?ref=v0.1.2" + # All required module arguments + + account_id = "service-account-id" + + + # All optional module arguments set to the default values + display_name = "Service Account" + project = "project id" + + service_account_keys_count = 1 + + # All optional module configuration arguments set to the default values. + # Those are maintained for terraform 0.12 but can still be used in terraform 0.13 + # Starting with terraform 0.13 you can additionally make use of module level + # count, for_each and depends_on features. + module_enabled = true + module_depends_on = [] +} +#----------------------------------------------------------------------------------------------#------------------------ +# SERVICE ACCOUNT KEY OUTPUT +# ---------------------------------------------------------------------------------------------------------------------- +output "service_account_key" { + description = "All attributes of the created `google_service_account_key` resource." + value = try(module.terraform-kubernetes-cluster-role.service_account_key, null) + sensitive = true +} +# ---------------------------------------------------------------------------------------------------------------------- +# EXAMPLE PROVIDER CONFIGURATION +# ---------------------------------------------------------------------------------------------------------------------- + +provider "google" { + version = "~> 4.0" +} + +#---------------------------------------------------------------------------------------------------------------------- +# ENVIRONMENT VARIABLES: +# ---------------------------------------------------------------------------------------------------------------------- +# You can provide your credentials via the +# https://cloud.google.com/docs/authentication/application-default-credentials#GAC +# ---------------------------------------------------------------------------------------------------------------------- + diff --git a/main.tf b/main.tf index 7b153c9..f7c49e0 100644 --- a/main.tf +++ b/main.tf @@ -59,3 +59,12 @@ resource "google_organization_iam_member" "organization" { member = "serviceAccount:${google_service_account.service_account[0].email}" } + +resource "google_service_account_key" "key" { + count = var.service_account_keys_count + + service_account_id = google_service_account.service_account[0].name + key_algorithm = var.key_algorithm + public_key_type = var.public_key_type + private_key_type = var.private_key_type +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index 89a24cd..82ccded 100644 --- a/outputs.tf +++ b/outputs.tf @@ -31,3 +31,9 @@ output "organization_iam_member" { description = "All attributes of the created `google_organization_iam_member` resource." value = try(google_organization_iam_member.organization, null) } + +output "service_account_key" { + description = "All attributes of the created `google_service_account_key` resource." + value = try(google_service_account_key.key, null) + sensitive = true +} \ No newline at end of file diff --git a/test/unit-complete/_generated_google.tf b/test/unit-complete/_generated_google.tf index 3135f7c..bb486dd 100644 --- a/test/unit-complete/_generated_google.tf +++ b/test/unit-complete/_generated_google.tf @@ -1,5 +1,4 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT -// TERRAMATE: originated from generate_hcl block on /test/terramate_google.tm.hcl variable "gcp_project" { default = null diff --git a/test/unit-complete/main.tf b/test/unit-complete/main.tf index 4dbfcd8..264c5b8 100644 --- a/test/unit-complete/main.tf +++ b/test/unit-complete/main.tf @@ -149,3 +149,14 @@ module "test2" { } ] } + + +module "test-sa-key" { + source = "../.." + + module_enabled = true + + account_id = "test-sa-key-${local.random_suffix}" + service_account_keys_count = 1 + +} \ No newline at end of file diff --git a/test/unit-disabled/_generated_google.tf b/test/unit-disabled/_generated_google.tf index 7e8f36e..7f43a8d 100644 --- a/test/unit-disabled/_generated_google.tf +++ b/test/unit-disabled/_generated_google.tf @@ -1,5 +1,4 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT -// TERRAMATE: originated from generate_hcl block on /test/terramate_google.tm.hcl variable "gcp_project" { default = null diff --git a/test/unit-minimal/_generated_google.tf b/test/unit-minimal/_generated_google.tf index a79b92b..48fb18a 100644 --- a/test/unit-minimal/_generated_google.tf +++ b/test/unit-minimal/_generated_google.tf @@ -1,5 +1,4 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT -// TERRAMATE: originated from generate_hcl block on /test/terramate_google.tm.hcl variable "gcp_project" { default = null diff --git a/variables.tf b/variables.tf index f4cb4b5..4e934c7 100644 --- a/variables.tf +++ b/variables.tf @@ -78,6 +78,30 @@ variable "computed_members_map" { } } +variable "service_account_keys_count" { + type = number + description = "(Optional) The number of service account keys to be generated attached to this account." + default = 0 +} + +variable "key_algorithm" { + type = string + description = "(Optional) The algorithm used to generate the key." + default = "KEY_ALG_RSA_2048" +} + +variable "public_key_type" { + type = string + description = "(Optional) The output format of the public key requested." + default = "TYPE_X509_PEM_FILE" +} + +variable "private_key_type" { + type = string + description = "(Optional) The output format of the private key." + default = "TYPE_GOOGLE_CREDENTIALS_FILE" +} + # ------------------------------------------------------------------------------ # MODULE CONFIGURATION PARAMETERS # These variables are used to configure the module. diff --git a/versions.tf b/versions.tf index 3574861..ee96780 100644 --- a/versions.tf +++ b/versions.tf @@ -1,5 +1,4 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT -// TERRAMATE: originated from generate_hcl block on /terramate.tm.hcl terraform { required_version = "~> 1.0, != 1.1.0, != 1.1.1"