This Terraform module ensures continuous rotation of Entra ID application secrets using a blue-green strategy, guaranteeing that there is always at least one valid password available. It supports rotation intervals in minutes, hours, and months.
The secret validity period defaults to the Entra ID maximum of 24 months, with a
3-month overlap. The module outputs lifecycle data of the secrets, such as
start_date
and end_date
, and maintains the validity of the secrets at the
time of the last apply. A secret is considered valid if the apply time falls
between its start_date
and end_date
. The active_secret
is the valid secret
with the longest remaining validity.
It is advisable to store the active secret value in a secrets manager, such as Azure Key Vault, to ensure that the actual application can securely access it.
Assuming the default validity and overlap, the module's rotation logic is as follows:
Blue: |----------24-----------········18········|----------24-----------········18········|--
Green:···········21········-----------24----------|········18········-----------24----------|
Overlap: ·3· ·3· ·3·
- Initial apply: Creates the
blue
secret as the active one and thegreen
secret with astart_date
21 months in the future. - Month 21 to 42: Switches
active_secret
togreen
. - Month 42 to 45: Destroys and creates a new
blue
secret with astart_date
equals apply time and switchesactive_secret
toblue
. - Month 45 to 60: Destroys and creates a new
green
secret with astart_date
three months prior to theend_date
of the blue secret.
This rotation strategy ensures seamless secret management and consistent availability of valid credentials.
module "app_secrets" {
source = "mhennecke/app-secret-rotation/azuread"
version = "0.9.0"
application_id = "/applications/<your-application-id>"
}
output "active_secret_key_id" {
value = module.app_secrets.secrets_lifecycle[module.app_secrets.active_secret].key_id
}
output "active_secret_value" {
value = module.app_secrets.secrets_values[module.app_secrets.active_secret]
sensitive = true
}
Run terraform test
to run the unit tests. Due to the nature of the module,
time_sleep
resources are used in the tests for verifying the different sercet rotation scenarios.
This module is licensed under the MIT License. See the LICENSE file for more details.
This module is maintained by Marius Hennecke.
Contributions are welcome! Please submit a pull request with a description of your changes.
If you find any issues or have suggestions for improvement, please open an issue or a pull request on the GitHub repository.