Skip to content
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

azuread_application_password: end_date and end_date_relative parameter should calculate the end date of the application password based on the start_date but it is calculated based on the current timestamp when TF apply is executed #843

Closed
ccsandhanshive opened this issue Jul 13, 2022 · 6 comments · Fixed by #844

Comments

@ccsandhanshive
Copy link

ccsandhanshive commented Jul 13, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritise this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritise the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureAD Provider) Version

Terraform v1.0.0

  • provider registry.terraform.io/hashicorp/azuread v2.20.0

Affected Resource(s)

  • azuread_application_password

Terraform Configuration Files

resource "azuread_application" "example" {
  display_name = "example"
}
resource "time_rotating" "example" {
  rotation_days = 7
}

resource "azuread_application_password" "example" {
  application_object_id = azuread_application.example.object_id
  end_date_relative     = "10h"
  start_date        = "2022-09-13T23:27:23Z"
  rotate_when_changed = {
    rotation = time_rotating.example.id
  }
}

Debug Output

│ error: KeyCredentialsInvalidEndDate: Key credential end date is invalid. 

Expected Behavior

  • As per Azure PowerShell, if start date is specified without any end date then the end-date would be calculated as 1 year after the start-date

  • For example, if start date is 1/1/2024 1:02:03 AM then the end date would be 1/1/2025 1:02:03 AM

  • However, in terraform, the end_date parameter is calculated based on the current timestamp (NOT the start_date)

    • If start_date is 2022-09-01T01:02:03Z and end_date_relative is "10h" then the calculated end_date is 2022-07-13T11:02:03Z (since the current timestamp is 2022-07-13T01:02:03Z)

    • The expected end_date is 2022-09-01T11:02:03Z

  • Similarly, if both end_date and end_date_relative aren't specified, the calculated end_date should be based on the start_date not the current timestamp

Actual Behavior

  • Terraform calculates end_date parameter based on the current timestamp and not the start_date parameter.

  • This leads to an error during the apply command if the calculated end_date ends up being before the start_date

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000
@ccsandhanshive
Copy link
Author

Are there any updates on this?

@ccsandhanshive ccsandhanshive changed the title end_date_relative parameter should calculate end_date parameter base on start_date parameter not current timestamp azuread_application_password: end_date and end_date_relative parameter should calculate the end date of the application password based on the start_date but it is calculated based on the current timestamp when TF apply is executed Jul 27, 2022
@manicminer manicminer added this to the v2.27.0 milestone Jul 31, 2022
@manicminer
Copy link
Contributor

Thanks for requesting this @ccsandhanshive. I agree that setting an expiry date relative to the start date makes more sense. Whilst this technically constitutes a breaking behavioral change, in practice seems unlikely to break any existing workflows and will not affect any already-created credentials, so I think we're probably OK to update this.

Thanks @Threpio for picking this up and submitting a PR! ⭐

@github-actions
Copy link

github-actions bot commented Aug 5, 2022

This functionality has been released in v2.27.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Threpio added a commit to Threpio/terraform-provider-azuread that referenced this issue Aug 5, 2022
…ord (hashicorp#844)

* Simple fix for end_date_relative bug

* Testing locally + logic

* There is no reason these two functions should be this different
@ccsandhanshive
Copy link
Author

@manicminer Thank you for adding functionality for end_date_relative parameter now it calculates end_date based on start_date which we have specified for start_date parameter.

The end_date parameter in azuread_application_password is an optional parameter and its default value is still 2 years after the current timestamp, not 2 or 1 year after start_date

As per azure Powershell default value for end_date is 1 year after start_date

If both end_date and end_date_relative aren't specified, the calculated end_date should be based on the start_date not the current timestamp

Could you please let us know if this behavior is expected behavior, if not then what is the reason that terraform has not added this functionality

@chennagouda14
Copy link

chennagouda14 commented Aug 5, 2022

@manicminer Thank you for adding this functionality for end_date_relative parameter in azuread_application_certificate resource, now the end_date_relative parameter calculates the end date of a certificate/key based on the start_date.

manicminer pushed a commit to Threpio/terraform-provider-azuread that referenced this issue Aug 25, 2022
…ord (hashicorp#844)

* Simple fix for end_date_relative bug

* Testing locally + logic

* There is no reason these two functions should be this different
manicminer added a commit that referenced this issue Aug 25, 2022
* Initial DataSource file created

* Update location

* Switch Case added for some types

* Basic docs, removed linter problem and added client

* Run tflint

* Forgetting that it has to define the provider in the datasource registration

* Adding the Registration function

* Assign data to state correctly

* Update docs/data-sources/principal_type.md

Additional Interpolation removed

Co-authored-by: Tom Bamford <tom@bamford.io>

* Update internal/services/directoryobjects/principal_type_data_source.go

Imports tidied up

Co-authored-by: Tom Bamford <tom@bamford.io>

* Update docs/data-sources/principal_type.md

Wording as per suggestion

Co-authored-by: Tom Bamford <tom@bamford.io>

* Updated as per other comments

* Removed redundant type for this data_source

* Import fmt and tests

* Fixing Tests + Documents

* Accidentally wrote the docs twice??

* Test config fixes, use provider context

* Rename data source, add missing nil checking

* TC config for directoryobjects package

* Docs to reflect renamed data source

* Docs wording for azuread_directory_object data source

* Update application_password.md

* Changelog for #844

* Fix for Issue #843 - end_date_relative for application_password (#844)

* Simple fix for end_date_relative bug

* Testing locally + logic

* There is no reason these two functions should be this different

* v2.27.0

* Add warning that OIDC auth only works in GitHub Actions

* Update docs/guides/service_principal_oidc.md

* Update to Go 1.19

* Remove tfproviderlint

* Docs: azuread_group.dynamic_membership.rule is required, not optional. Fixes #857

Co-authored-by: Tom Bamford <tom@bamford.io>
Co-authored-by: Sam Gladstone <42203151+samgladstone@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Sep 5, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants