-
Notifications
You must be signed in to change notification settings - Fork 215
feat: Adds without_initial_secret to mongodbatlas_service_account
#4727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EspenAlbert
wants to merge
14
commits into
master
Choose a base branch
from
CLOUDP-444252_provider-allow-sa-without-secret
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
76ea54a
feat(service_account): Add without_initial_secret attribute
EspenAlbert f552dd6
adds changelog entry
EspenAlbert 085a44f
feat(service_account): Regenerate model from local dev spec only
EspenAlbert baf07b3
self review fixes
EspenAlbert 947d6c5
fix(codegen): Keep create-only plan modifier for computed optional bo…
EspenAlbert 33caf83
self review
EspenAlbert 1e6623c
self review
EspenAlbert 0d740f0
chore: fix broken test.
EspenAlbert 3ca8c35
remove accidental skip in qa
EspenAlbert 30a12f2
initial move to optional-only
EspenAlbert 3530b18
chore: moves the example to root
EspenAlbert bfa79df
feat(serviceaccount): Add managed secret to service account example
EspenAlbert 99cb770
self-review
EspenAlbert 0f737c3
address PR comments2
EspenAlbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:enhancement | ||
| resource/mongodbatlas_service_account: Adds `without_initial_secret` attribute to create a Service Account without generating an initial secret. `secret_expires_after_hours` is now optional when `without_initial_secret` is `true` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,62 @@ | ||
| # MongoDB Atlas Provider -- Service Account | ||
|
|
||
| This example shows how to create a Service Account in MongoDB Atlas. | ||
| This example shows how to create a Service Account without an Atlas-generated secret by setting `without_initial_secret = true`, then create its first secret as a managed resource. | ||
|
|
||
| Setting `without_initial_secret = true` means Atlas returns no secret from the create request, so every secret is created and rotated through `mongodbatlas_service_account_secret`, which is what a rotation submodule expects. | ||
|
|
||
| ## Important Notes | ||
|
|
||
| When you create a Service Account, Atlas automatically generates a secret. The secret value is returned only once, at creation time. | ||
| `without_initial_secret` and `secret_expires_after_hours` are mutually exclusive on the Service Account. Set `without_initial_secret = true` and omit `secret_expires_after_hours`, or set `secret_expires_after_hours` and omit `without_initial_secret`. Atlas rejects a create request that sets both. This example sets the expiration only on the secret resource. | ||
|
|
||
| The example includes a sensitive output `service_account_first_secret` that captures this initial secret. | ||
| You can retrieve it using (**warning**: this prints the secret to your terminal): | ||
| The example includes a sensitive output `secret` that captures the secret value. You can retrieve it using (**warning**: this prints the secret to your terminal): | ||
|
|
||
| ```bash | ||
| terraform output -raw service_account_first_secret | ||
| terraform output -raw secret | ||
| ``` | ||
|
|
||
| For secret rotation, see [Guide: Service Account Secret Rotation](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/service-account-secret-rotation). | ||
| For managing and rotating secrets, see [Guide: Service Account Secret Rotation](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/service-account-secret-rotation). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Service Account with Organization Owner permissions used for provider authentication. | ||
|
EspenAlbert marked this conversation as resolved.
|
||
|
|
||
| ## Variables Required to be set: | ||
| - `atlas_client_id`: MongoDB Atlas Service Account Client ID | ||
| - `atlas_client_secret`: MongoDB Atlas Service Account Client Secret | ||
| - `org_id`: Organization ID where the Service Account will be created | ||
| ## Variables Required to be set | ||
|
|
||
| - `atlas_client_id`: MongoDB Atlas Service Account Client ID. | ||
| - `atlas_client_secret`: MongoDB Atlas Service Account Client Secret. | ||
| - `org_id`: Atlas Organization ID where this configuration creates the Service Account. | ||
|
|
||
| ## Outputs | ||
| - `service_account_client_id`: The Client ID of the created Service Account | ||
| - `service_account_name`: The name of the Service Account | ||
| - `service_account_first_secret` (sensitive): The initial secret value (only available at creation) | ||
| - `service_accounts_results`: All Service Accounts in the organization | ||
|
|
||
| - `service_account_client_id`: The Client ID of the Service Account | ||
| - `secret_id`: The ID of the Service Account secret | ||
| - `secret` (sensitive): The secret value | ||
|
|
||
| ## Usage | ||
|
|
||
| **1. Create `terraform.tfvars`.** | ||
|
|
||
| ```hcl | ||
| atlas_client_id = "<ATLAS_CLIENT_ID>" | ||
| atlas_client_secret = "<ATLAS_CLIENT_SECRET>" | ||
| org_id = "your-org-id" | ||
| ``` | ||
|
|
||
| **2. Plan and apply.** | ||
|
|
||
| ```bash | ||
| terraform plan | ||
| terraform apply | ||
| ``` | ||
|
|
||
| **3. Read the secret** (**warning**: this prints the secret to your terminal). | ||
|
|
||
| ```bash | ||
| terraform output -raw secret | ||
| ``` | ||
|
|
||
| **4. Destroy.** | ||
|
|
||
| ```bash | ||
| terraform destroy | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,32 @@ | ||
| resource "mongodbatlas_service_account" "this" { | ||
| org_id = var.org_id | ||
| name = "example-service-account" | ||
| description = "Example Service Account" | ||
| roles = ["ORG_READ_ONLY"] | ||
| secret_expires_after_hours = 2160 # 90 days | ||
| } | ||
| # Create a Service Account without an Atlas-generated secret, then create the first secret | ||
| # explicitly with mongodbatlas_service_account_secret so this configuration owns it. | ||
|
|
||
| data "mongodbatlas_service_account" "this" { | ||
| org_id = var.org_id | ||
| client_id = mongodbatlas_service_account.this.client_id | ||
| resource "mongodbatlas_service_account" "this" { | ||
| org_id = var.org_id | ||
| name = "example-service-account" | ||
| description = "Example Service Account" | ||
| roles = ["ORG_READ_ONLY"] | ||
| without_initial_secret = true | ||
| } | ||
|
|
||
| data "mongodbatlas_service_accounts" "this" { | ||
| org_id = var.org_id | ||
| resource "mongodbatlas_service_account_secret" "this" { | ||
| org_id = var.org_id | ||
| client_id = mongodbatlas_service_account.this.client_id | ||
| secret_expires_after_hours = 2160 # 90 days | ||
| } | ||
|
|
||
| output "service_account_client_id" { | ||
| value = mongodbatlas_service_account.this.client_id | ||
| description = "The Client ID of the Service Account. Use it with a secret to authenticate." | ||
| value = mongodbatlas_service_account.this.client_id | ||
| } | ||
|
|
||
| output "service_account_name" { | ||
| value = data.mongodbatlas_service_account.this.name | ||
| output "secret_id" { | ||
| description = "The ID of the Service Account secret." | ||
| value = mongodbatlas_service_account_secret.this.secret_id | ||
| } | ||
|
|
||
| output "service_account_first_secret" { | ||
| description = "The secret value of the first secret created with the Service Account. Available only immediately after initial creation." | ||
| value = try(mongodbatlas_service_account.this.secrets[0].secret, null) | ||
| output "secret" { | ||
| description = "The secret value for the Service Account. Returned only when the secret is created." | ||
| sensitive = true | ||
| } | ||
|
|
||
| output "service_accounts_results" { | ||
| value = data.mongodbatlas_service_accounts.this.results | ||
| value = mongodbatlas_service_account_secret.this.secret | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,3 @@ terraform { | |
| } | ||
| required_version = ">= 1.10" | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.