Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

feat(ephemeral): adding ephemeral values support for resource_user an… - #523

Open
ocalzi wants to merge 2 commits into
hashicorp:mainfrom
ocalzi:feat/ephemeral_resource_user
Open

feat(ephemeral): adding ephemeral values support for resource_user an…#523
ocalzi wants to merge 2 commits into
hashicorp:mainfrom
ocalzi:feat/ephemeral_resource_user

Conversation

@ocalzi

@ocalzi ocalzi commented Jun 28, 2025

Copy link
Copy Markdown

Changes:

  • bump go version
  • add ephemeral values support to write-only argument password_wo to resource_user
  • update documentation

Build locally and tested with sucess:

PLAN:

│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp/googleworkspace in /Users/XY/Downloads/learn-terraform-google-workspace-main/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with
│ published releases.
╵
ephemeral.random_password.db_password: Opening...
ephemeral.random_password.db_password: Opening complete after 0s
ephemeral.random_password.db_password: Closing...
ephemeral.random_password.db_password: Closing complete after 0s

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:

  # googleworkspace_user.users["Jim"] will be created
  + resource "googleworkspace_user" "users" {
      + agreed_to_terms                    = (known after apply)
      + creation_time                      = (known after apply)
      + customer_id                        = (known after apply)
      + deletion_time                      = (known after apply)
      + etag                               = (known after apply)
      + hash_function                      = "MD5"
      + id                                 = (known after apply)
      + include_in_global_address_list     = true
      + is_admin                           = (known after apply)
      + is_delegated_admin                 = (known after apply)
      + is_enforced_in_2_step_verification = (known after apply)
      + is_enrolled_in_2_step_verification = (known after apply)
      + is_mailbox_setup                   = (known after apply)
      + last_login_time                    = (known after apply)
      + non_editable_aliases               = (known after apply)
      + org_unit_path                      = (known after apply)
      + password_wo                        = (write-only attribute)
      + password_wo_version                = 1
      + primary_email                      = "jhalpert@example.com"
      + recovery_email                     = "jhalpert@gmail.com"
      + suspension_reason                  = (known after apply)
      + thumbnail_photo_etag               = (known after apply)
      + thumbnail_photo_url                = (known after apply)

      + languages (known after apply)

      + name {
          + family_name = "Halpert"
          + full_name   = (known after apply)
          + given_name  = "Jim"
        }

      + organizations {
          + department = "sales"
          + primary    = true
          + title      = "agent"
          + type       = "work"
        }
    }

  # googleworkspace_user.users["Michael"] will be created
  + resource "googleworkspace_user" "users" {
      + agreed_to_terms                    = (known after apply)
      + creation_time                      = (known after apply)
      + customer_id                        = (known after apply)
      + deletion_time                      = (known after apply)
      + etag                               = (known after apply)
      + hash_function                      = "MD5"
      + id                                 = (known after apply)
      + include_in_global_address_list     = true
      + is_admin                           = (known after apply)
      + is_delegated_admin                 = (known after apply)
      + is_enforced_in_2_step_verification = (known after apply)
      + is_enrolled_in_2_step_verification = (known after apply)
      + is_mailbox_setup                   = (known after apply)
      + last_login_time                    = (known after apply)
      + non_editable_aliases               = (known after apply)
      + org_unit_path                      = (known after apply)
      + password_wo                        = (write-only attribute)
      + password_wo_version                = 1
      + primary_email                      = "mscott@example.com"
      + recovery_email                     = "mscott@hotmail.com"
      + suspension_reason                  = (known after apply)
      + thumbnail_photo_etag               = (known after apply)
      + thumbnail_photo_url                = (known after apply)

      + languages (known after apply)

      + name {
          + family_name = "Scott"
          + full_name   = (known after apply)
          + given_name  = "Michael"
        }

      + organizations {
          + department = "sales"
          + primary    = true
          + title      = "manager"
          + type       = "work"
        }
    }

  # googleworkspace_user.users["Pam"] will be created
  + resource "googleworkspace_user" "users" {
      + agreed_to_terms                    = (known after apply)
      + creation_time                      = (known after apply)
      + customer_id                        = (known after apply)
      + deletion_time                      = (known after apply)
      + etag                               = (known after apply)
      + hash_function                      = "MD5"
      + id                                 = (known after apply)
      + include_in_global_address_list     = true
      + is_admin                           = (known after apply)
      + is_delegated_admin                 = (known after apply)
      + is_enforced_in_2_step_verification = (known after apply)
      + is_enrolled_in_2_step_verification = (known after apply)
      + is_mailbox_setup                   = (known after apply)
      + last_login_time                    = (known after apply)
      + non_editable_aliases               = (known after apply)
      + org_unit_path                      = (known after apply)
      + password_wo                        = (write-only attribute)
      + password_wo_version                = 1
      + primary_email                      = "pbeesly@example.com"
      + recovery_email                     = "pbeesly@gmail.com"
      + suspension_reason                  = (known after apply)
      + thumbnail_photo_etag               = (known after apply)
      + thumbnail_photo_url                = (known after apply)

      + languages (known after apply)

      + name {
          + family_name = "Beesly"
          + full_name   = (known after apply)
          + given_name  = "Pam"
        }

      + organizations {
          + department = "admin"
          + primary    = true
          + title      = "receptionist"
          + type       = "work"
        }
    }

Plan: 3 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + user_email = [
      + "jhalpert@example.com",
      + "mscott@example.com",
      + "pbeesly@example.com",
    ]

APPLY:

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

ephemeral.random_password.db_password: Opening...
ephemeral.random_password.db_password: Opening complete after 0s
googleworkspace_user.users["Jim"]: Creating...
googleworkspace_user.users["Pam"]: Creating...
googleworkspace_user.users["Michael"]: Creating...
googleworkspace_user.users["Michael"]: Still creating... [00m10s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [00m10s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [00m10s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [00m20s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [00m20s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [00m20s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [00m30s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [00m30s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [00m30s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [00m40s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [00m40s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [00m40s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [00m50s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [00m50s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [00m50s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m00s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m00s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m00s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m10s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m10s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m10s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m20s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m20s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m20s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m30s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m30s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m30s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m40s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m40s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m40s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [01m50s elapsed]
googleworkspace_user.users["Michael"]: Still creating... [01m50s elapsed]
googleworkspace_user.users["Pam"]: Still creating... [01m50s elapsed]
googleworkspace_user.users["Pam"]: Creation complete after 1m50s [id=106731811473452596794]
googleworkspace_user.users["Michael"]: Still creating... [02m00s elapsed]
googleworkspace_user.users["Jim"]: Still creating... [02m00s elapsed]
googleworkspace_user.users["Jim"]: Creation complete after 2m1s [id=105919094940464869105]
googleworkspace_user.users["Michael"]: Still creating... [02m10s elapsed]
googleworkspace_user.users["Michael"]: Creation complete after 2m11s [id=104633277174626846250]
ephemeral.random_password.db_password: Closing...
ephemeral.random_password.db_password: Closing complete after 0s

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

user_email = [
      "jhalpert@example.com",
      "mscott@example.com",
       "pbeesly@example.com",
]

Resource definition:

ephemeral "random_password" "db_password" {
  length           = 16
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

resource "googleworkspace_user" "users" {
  for_each = { for user in local.users : user.first_name => user }

  primary_email = each.value.email
  password_wo = md5(ephemeral.random_password.db_password.result)
  password_wo_version = 1
  hash_function = each.value.password_hash_function

  name {
    family_name = each.value.last_name
    given_name  = each.value.first_name
  }

  organizations {
    department = each.value.dept
    primary    = true
    title      = each.value.title
    type       = "work"
  }
  recovery_email = each.value.recovery_email
}

Please let me know if I need to add more details, it’s my first PR since a long time.

Regards,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant