├── .changes ├── 0.10.0.md ├── 0.11.0.md ├── 0.11.1.md ├── 0.11.2.md ├── 0.12.0.md ├── 0.12.1.md ├── 0.13.0.md ├── 0.13.1-alpha1.md ├── 0.13.1.md ├── 0.9.1.md ├── 0.9.2.md └── unreleased │ └── .gitkeep ├── .changie.yaml ├── .copywrite.hcl ├── .github ├── CODEOWNERS ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── Bug_Report.yml │ ├── Feature_Request.yml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── SUPPORT.md ├── dependabot.yml ├── labeler-issue-triage.yml ├── labeler-pull-request-triage.yml └── workflows │ ├── build.yml │ ├── ci-changie.yml │ ├── compliance.yml │ ├── issue-comment-triage.yml │ ├── issue-opened.yml │ ├── lock.yml │ ├── pull-request.yml │ └── test.yml ├── .gitignore ├── .golangci.yml ├── .release ├── ci.hcl ├── release-metadata.hcl ├── security-scan.hcl └── terraform-provider-time-artifacts.hcl ├── CHANGELOG.md ├── GNUmakefile ├── LICENSE ├── META.d └── _summary.yaml ├── README.md ├── docs ├── cdktf │ ├── python │ │ ├── functions │ │ │ ├── duration_parse.md │ │ │ ├── rfc3339_parse.md │ │ │ └── unix_timestamp_parse.md │ │ ├── index.md │ │ └── resources │ │ │ ├── offset.md │ │ │ ├── rotating.md │ │ │ ├── sleep.md │ │ │ └── static.md │ └── typescript │ │ ├── functions │ │ ├── duration_parse.md │ │ ├── rfc3339_parse.md │ │ └── unix_timestamp_parse.md │ │ ├── index.md │ │ └── resources │ │ ├── offset.md │ │ ├── rotating.md │ │ ├── sleep.md │ │ └── static.md ├── functions │ ├── duration_parse.md │ ├── rfc3339_parse.md │ └── unix_timestamp_parse.md ├── index.md └── resources │ ├── offset.md │ ├── rotating.md │ ├── sleep.md │ └── static.md ├── examples ├── functions │ ├── duration_parse │ │ └── function.tf │ ├── rfc3339_parse │ │ └── function.tf │ └── unix_timestamp_parse │ │ └── function.tf └── resources │ ├── resource_triggers.tf │ ├── time_offset │ ├── import.sh │ ├── resource.tf │ ├── resource_multiple_offset.tf │ └── resource_triggers.tf │ ├── time_rotating │ ├── import_base_value.sh │ ├── import_rotation_value.sh │ └── resource.tf │ ├── time_sleep │ ├── import_create.sh │ ├── import_destroy.sh │ ├── resource_delay_create.tf │ ├── resource_delay_destroy.tf │ └── resource_triggers.tf │ └── time_static │ ├── import.sh │ ├── resource.tf │ └── resource_triggers.tf ├── go.mod ├── go.sum ├── internal ├── clock │ └── clock.go ├── modifiers │ └── timemodifier │ │ └── replace_if_outdated.go ├── provider │ ├── function_duration_parse.go │ ├── function_duration_parse_test.go │ ├── function_rfc3339_parse.go │ ├── function_rfc3339_parse_test.go │ ├── function_unix_timestamp_parse.go │ ├── function_unix_timestamp_parse_test.go │ ├── provider.go │ ├── provider_test.go │ ├── resource_time_offset.go │ ├── resource_time_offset_test.go │ ├── resource_time_rotating.go │ ├── resource_time_rotating_test.go │ ├── resource_time_sleep.go │ ├── resource_time_sleep_test.go │ ├── resource_time_static.go │ ├── resource_time_static_test.go │ └── testdata │ │ └── TestAccTimeRotating_LifecycleReplaceTriggeredBy │ │ └── test.tf └── timetesting │ ├── fake_clock.go │ ├── int64_between_knownvalue.go │ └── int64_between_knownvalue_test.go ├── main.go ├── templates ├── functions │ ├── duration_parse.md.tmpl │ └── rfc3339_parse.md.tmpl ├── index.md.tmpl └── resources │ ├── offset.md.tmpl │ ├── rotating.md.tmpl │ ├── sleep.md.tmpl │ └── static.md.tmpl ├── terraform-registry-manifest.json ├── tools ├── go.mod ├── go.sum └── tools.go └── version └── VERSION /.changes/0.10.0.md: -------------------------------------------------------------------------------- 1 | ## 0.10.0 (December 06, 2023) 2 | 3 | BUG FIXES: 4 | 5 | * resource/time_offset: Fix bug preventing multiple offset arguments from being set ([#189](https://github.com/hashicorp/terraform-provider-time/issues/189)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.11.0.md: -------------------------------------------------------------------------------- 1 | ## 0.11.0 (March 11, 2024) 2 | 3 | FEATURES: 4 | 5 | * functions/rfc3339_parse: Added a new `rfc3339_parse` function that parses an RFC3339 timestamp string and returns an object representation. ([#280](https://github.com/hashicorp/terraform-provider-time/issues/280)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.11.1.md: -------------------------------------------------------------------------------- 1 | ## 0.11.1 (March 11, 2024) 2 | 3 | NOTES: 4 | 5 | * No functional changes from v0.11.0. Minor documentation fixes. ([#299](https://github.com/hashicorp/terraform-provider-time/issues/299)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.11.2.md: -------------------------------------------------------------------------------- 1 | ## 0.11.2 (May 28, 2024) 2 | 3 | NOTES: 4 | 5 | * This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#327](https://github.com/hashicorp/terraform-provider-time/issues/327)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.12.0.md: -------------------------------------------------------------------------------- 1 | ## 0.12.0 (July 17, 2024) 2 | 3 | ENHANCEMENTS: 4 | 5 | * resource/time_static: If the `rfc3339` value is set in config and known at plan-time, all other attributes will also be known during plan. ([#255](https://github.com/hashicorp/terraform-provider-time/issues/255)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.12.1.md: -------------------------------------------------------------------------------- 1 | ## 0.12.1 (September 11, 2024) 2 | 3 | NOTES: 4 | 5 | * all: This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#351](https://github.com/hashicorp/terraform-provider-time/issues/351)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.13.0.md: -------------------------------------------------------------------------------- 1 | ## 0.13.0 (March 04, 2025) 2 | 3 | FEATURES: 4 | 5 | * functions/duration_parse: Added a new `duration_parse` function that parses [Go duration strings](https://pkg.go.dev/time#ParseDuration). ([#350](https://github.com/hashicorp/terraform-provider-time/issues/350)) 6 | * functions/unix_timestamp_parse: Added a new `unix_timestamp_parse` function that parses a unix timestamp integer and returns an object representation. ([#385](https://github.com/hashicorp/terraform-provider-time/issues/385)) 7 | 8 | -------------------------------------------------------------------------------- /.changes/0.13.1-alpha1.md: -------------------------------------------------------------------------------- 1 | ## 0.13.1-alpha1 (April 22, 2025) 2 | 3 | NOTES: 4 | 5 | * all: This release is being used to test new build and release actions. ([#413](https://github.com/hashicorp/terraform-provider-time/issues/413)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.13.1.md: -------------------------------------------------------------------------------- 1 | ## 0.13.1 (April 28, 2025) 2 | 3 | NOTES: 4 | 5 | * Update dependencies ([#410](https://github.com/hashicorp/terraform-provider-time/issues/410)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/0.9.1.md: -------------------------------------------------------------------------------- 1 | ## 0.9.1 (November 2, 2022) 2 | 3 | BUG FIXES: 4 | 5 | * resource/time_rotating: Correctly retrieve the Terraform state during update ([#132](https://github.com/hashicorp/terraform-provider-time/pull/132)) 6 | 7 | ## 0.9.0 (October 11, 2022) 8 | 9 | NOTES: 10 | 11 | * provider: Rewritten to use the new [`terraform-plugin-framework`](https://www.terraform.io/plugin/framework) ([#112](https://github.com/hashicorp/terraform-provider-time/pull/112)) 12 | 13 | ## 0.8.0 (August 10, 2022) 14 | 15 | BUG FIXES: 16 | 17 | * documentation: Changed wording from "Conflicts with other `offset_`/`rotation_` arguments." to "At least one of the `offset_`/`rotation_` arguments must be configured." to correctly reflect the use of `AtLeastOneOf` ([#105](https://github.com/hashicorp/terraform-provider-time/pull/105)) 18 | 19 | NOTES: 20 | 21 | * provider: Upgrade Go version to 1.18 ([#114](https://github.com/hashicorp/terraform-provider-time/pull/114)) 22 | * provider: Enable `golangci-lint` ([#105](https://github.com/hashicorp/terraform-provider-time/pull/105)) 23 | 24 | ## 0.7.2 (July 01, 2021) 25 | 26 | BUG FIXES: 27 | 28 | * resource/time_sleep: Prevent `context deadline exceeded` error when timeout duration is configured above 20 minutes ([#45](https://github.com/hashicorp/terraform-provider-time/issues/45)) 29 | 30 | ## 0.7.1 (May 04, 2021) 31 | 32 | BUG FIXES: 33 | 34 | * provider: Ensure `darwin/arm64` platform is included in releases 35 | 36 | ## 0.7.0 (February 19, 2021) 37 | 38 | Binary releases of this provider now include the darwin-arm64 platform. This version contains no further changes. 39 | 40 | ## 0.6.0 (October 04, 2020) 41 | 42 | BREAKING CHANGES: 43 | 44 | * Dropped support for Terraform 0.11 and lower ([#16](https://github.com/hashicorp/terraform-provider-time/issues/16)) 45 | 46 | ENHANCEMENTS 47 | 48 | * Made `time_sleep` context aware, allowing easier early cancellation ([#16](https://github.com/hashicorp/terraform-provider-time/issues/16)) 49 | 50 | ## 0.5.0 (May 13, 2020) 51 | 52 | FEATURES 53 | 54 | * **New Resource:** `time_sleep` ([#12](https://github.com/hashicorp/terraform-provider-time/issues/12)) 55 | 56 | # 0.4.0 (April 21, 2020) 57 | 58 | BREAKING CHANGES: 59 | 60 | * resource/time_offset: `keepers` argument renamed to `triggers` 61 | * resource/time_offset: Remove non-RFC3339 RFC and `unixdate` attribute 62 | * resource/time_rotating: `keepers` argument renamed to `triggers` 63 | * resource/time_rotating: Remove non-RFC3339 RFC and `unixdate` attributes 64 | * resource/time_static: `keepers` argument renamed to `triggers` 65 | * resource/time_static: Remove non-RFC3339 RFC and `unixdate` attributes 66 | 67 | # v0.3.0 68 | 69 | ENHANCEMENTS: 70 | 71 | * resource/time_offset: Add `keepers` argument 72 | * resource/time_rotating: Add `keepers` argument 73 | * resource/time_static: Add `keepers` argument 74 | 75 | BUG FIXES: 76 | 77 | * resource/time_offset: Ensure `base_rfc3339` is always set in Terraform state during creation, even if unconfigured 78 | 79 | # v0.2.0 80 | 81 | BREAKING CHANGES: 82 | 83 | * resource/time_static: The `expiration_` arguments have been moved to the new `time_rotating` resource as `rotation_` arguments. 84 | 85 | FEATURES: 86 | 87 | * **New Resource:** `time_offset` 88 | * **New Resource:** `time_rotating` 89 | 90 | # v0.1.0 91 | 92 | FEATURES: 93 | 94 | * **New Resource:** `time_static` 95 | -------------------------------------------------------------------------------- /.changes/0.9.2.md: -------------------------------------------------------------------------------- 1 | ## 0.9.2 (November 28, 2023) 2 | 3 | NOTES: 4 | 5 | * This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#263](https://github.com/hashicorp/terraform-provider-time/issues/263)) 6 | 7 | -------------------------------------------------------------------------------- /.changes/unreleased/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hashicorp/terraform-provider-time/7578737a1ae82b91dfa22bf450a10fc749181385/.changes/unreleased/.gitkeep -------------------------------------------------------------------------------- /.changie.yaml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | changesDir: .changes 4 | unreleasedDir: unreleased 5 | changelogPath: CHANGELOG.md 6 | versionExt: md 7 | versionFormat: '## {{.Version}} ({{.Time.Format "January 02, 2006"}})' 8 | kindFormat: '{{.Kind}}:' 9 | changeFormat: '* {{.Body}} ([#{{.Custom.Issue}}](https://github.com/hashicorp/terraform-provider-time/issues/{{.Custom.Issue}}))' 10 | custom: 11 | - key: Issue 12 | label: Issue/PR Number 13 | type: int 14 | minInt: 1 15 | kinds: 16 | - label: BREAKING CHANGES 17 | - label: NOTES 18 | - label: FEATURES 19 | - label: ENHANCEMENTS 20 | - label: BUG FIXES 21 | newlines: 22 | afterKind: 1 23 | beforeKind: 1 24 | endOfVersion: 2 25 | -------------------------------------------------------------------------------- /.copywrite.hcl: -------------------------------------------------------------------------------- 1 | schema_version = 1 2 | 3 | project { 4 | license = "MPL-2.0" 5 | copyright_year = 2020 6 | 7 | header_ignore = [ 8 | # internal catalog metadata (prose) 9 | "META.d/**/*.yaml", 10 | 11 | # changie tooling configuration and CHANGELOG entries (prose) 12 | ".changes/unreleased/*.yaml", 13 | ".changie.yaml", 14 | 15 | # examples used within documentation (prose) 16 | "examples/**", 17 | 18 | # GitHub issue template configuration 19 | ".github/ISSUE_TEMPLATE/*.yml", 20 | 21 | # GitHub Actions workflow-specific configurations 22 | ".github/labeler-*.yml", 23 | 24 | # golangci-lint tooling configuration 25 | ".golangci.yml", 26 | 27 | # Release Engineering tooling configuration 28 | ".release/*.hcl", 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @hashicorp/terraform-devex 2 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for investing your time and energy by contributing to our project: please ensure you are familiar 4 | with the [HashiCorp Code of Conduct](https://github.com/hashicorp/.github/blob/master/CODE_OF_CONDUCT.md). 5 | 6 | This provider is a HashiCorp **utility provider**, which means any bug fix and feature 7 | has to be considered in the context of the thousands/millions of configurations in which this provider is used. 8 | This is great as your contribution can have a big positive impact, but we have to assess potential negative impact too 9 | (e.g. breaking existing configurations). _Stability over features_. 10 | 11 | To provide some safety to the wider provider ecosystem, we strictly follow 12 | [semantic versioning](https://semver.org/) and HashiCorp's own 13 | [versioning specification](https://www.terraform.io/plugin/sdkv2/best-practices/versioning#versioning-specification). 14 | Any changes that could be considered as breaking will only be included as part of a major release. 15 | In case multiple breaking changes need to happen, we will group them in the next upcoming major release. 16 | 17 | ## Asking Questions 18 | 19 | For questions, curiosity, or if still unsure what you are dealing with, 20 | please see the HashiCorp [Terraform Providers Discuss](https://discuss.hashicorp.com/c/terraform-providers/31) 21 | forum. 22 | 23 | ## Reporting Vulnerabilities 24 | 25 | Please disclose security vulnerabilities responsibly by following the 26 | [HashiCorp Vulnerability Reporting guidelines](https://www.hashicorp.com/security#vulnerability-reporting). 27 | 28 | ## Understanding the design 29 | 30 | Before proceeding with raising issues or submitting pull requests, it will probably help to familiarise yourself with 31 | the [design principles](../DESIGN.md) of this provider. This will aid your proposals, and help understand 32 | why we took certain decisions during development. 33 | 34 | ## Raising Issues 35 | 36 | We welcome issues of all kinds including feature requests, bug reports or documentation suggestions. 37 | Below are guidelines for well-formed issues of each type. 38 | 39 | ### Bug Reports 40 | 41 | * [ ] **Test against latest release**: Make sure you test against the latest available version of Terraform and the provider. 42 | It is possible we may have already fixed the bug you're experiencing. 43 | * [ ] **Search for duplicates**: It's helpful to keep bug reports consolidated to one thread, so do a quick search 44 | on existing bug reports to check if anybody else has reported the same thing. 45 | You can scope searches by the label `bug` to help narrow things down. 46 | * [ ] **Include steps to reproduce**: Provide steps to reproduce the issue, along with code examples and/or real code, 47 | so we can try to reproduce it. Without this, it makes it much harder (sometimes impossible) to fix the issue. 48 | 49 | ### Feature Requests 50 | 51 | * [ ] **Search for possible duplicate requests**: It's helpful to keep requests consolidated to one thread, 52 | so do a quick search on existing requests to check if anybody else has reported the same thing. 53 | You can scope searches by the label `enhancement` to help narrow things down. 54 | * [ ] **Include a use case description**: In addition to describing the behavior of the feature you'd like to see added, 55 | it's helpful to also make a case for why the feature would be important and how it would benefit 56 | the provider and, potentially, the wider Terraform ecosystem. 57 | 58 | ## New Pull Request 59 | 60 | Thank you for contributing! 61 | 62 | We are happy to review pull requests without associated issues, 63 | but we **highly recommend** starting by describing and discussing 64 | your problem or feature and attaching use cases to an issue first 65 | before raising a pull request. 66 | 67 | * [ ] **Early validation of idea and implementation plan**: provider development is complicated enough that there 68 | are often several ways to implement something, each of which has different implications and tradeoffs. 69 | Working through a plan of attack with the team before you dive into implementation will help ensure that you're 70 | working in the right direction. 71 | * [ ] **Tests**: It may go without saying, but every new patch should be covered by tests wherever possible. 72 | For bug-fixes, tests to prove the fix is valid. For features, tests to exercise the new code paths. 73 | * [ ] **Go Modules**: We use [Go Modules](https://github.com/golang/go/wiki/Modules) to manage and version our dependencies. 74 | Please make sure that you reflect dependency changes in your pull requests appropriately 75 | (e.g. `go get`, `go mod tidy` or other commands). 76 | Refer to the [dependency updates](#dependency-updates) section for more information about how 77 | this project maintains existing dependencies. 78 | * [ ] **Changelog**: Refer to the [changelog](#changelog) section for more information about how to create changelog entries. 79 | * [ ] **License Headers**: All source code requires a license header at the top of the file, refer to [License Headers](#license-headers) for information on how to autogenerate these headers. 80 | 81 | ### Dependency Updates 82 | 83 | Dependency management is performed by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates). 84 | Where possible, dependency updates should occur through that system to ensure all Go module files are appropriately 85 | updated and to prevent duplicated effort of concurrent update submissions. 86 | Once available, updates are expected to be verified and merged to prevent latent technical debt. 87 | 88 | ### Changelog 89 | 90 | HashiCorp’s open-source projects have always maintained user-friendly, readable `CHANGELOG`s that allow 91 | practitioners and developers to tell at a glance whether a release should have any effect on them, 92 | and to gauge the risk of an upgrade. 93 | 94 | We follow Terraform Plugin 95 | [changelog specifications](https://www.terraform.io/plugin/sdkv2/best-practices/versioning#changelog-specification). 96 | 97 | #### Changie Automation Tool 98 | This provider uses the [Changie](https://changie.dev/) automation tool for changelog automation. 99 | To add a new entry to the `CHANGELOG` install Changie using the following [instructions](https://changie.dev/guide/installation/) 100 | and run 101 | ```bash 102 | changie new 103 | ``` 104 | then choose a `kind` of change corresponding to the Terraform Plugin [changelog categories](https://developer.hashicorp.com/terraform/plugin/sdkv2/best-practices/versioning#categorization) 105 | and then fill out the body following the entry format. Changie will then prompt for a Github issue or pull request number. 106 | Repeat this process for any additional changes. The `.yaml` files created in the `.changes/unreleased` folder 107 | should be pushed the repository along with any code changes. 108 | 109 | #### Entry format 110 | 111 | Entries that are specific to _resources_ or _data sources_, they should look like: 112 | 113 | ```markdown 114 | * resource/RESOURCE_NAME: ENTRY DESCRIPTION 115 | 116 | * data-source/DATA-SOURCE_NAME: ENTRY DESCRIPTION 117 | ``` 118 | 119 | #### Pull Request Types to `CHANGELOG` 120 | 121 | The `CHANGELOG` is intended to show developer-impacting changes to the codebase for a particular version. 122 | If every change or commit to the code resulted in an entry, the `CHANGELOG` would become less useful for developers. 123 | The lists below are general guidelines to decide whether a change should have an entry. 124 | 125 | ##### Changes that should not have a `CHANGELOG` entry 126 | 127 | * Documentation updates 128 | * Testing updates 129 | * Code refactoring 130 | 131 | ##### Changes that may have a `CHANGELOG` entry 132 | 133 | * Dependency updates: If the update contains relevant bug fixes or enhancements that affect developers, 134 | those should be called out. 135 | 136 | ##### Changes that should have a `CHANGELOG` entry 137 | 138 | * Major features 139 | * Bug fixes 140 | * Enhancements 141 | * Deprecations 142 | * Breaking changes and removals 143 | 144 | 145 | ### License Headers 146 | 147 | All source code files (excluding autogenerated files like `go.mod`, prose, and files excluded in [.copywrite.hcl](../.copywrite.hcl)) must have a license header at the top. 148 | 149 | This can be autogenerated by running `make generate` or running `go generate ./...` in the [/tools](../tools) directory. 150 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug_Report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Something is incorrect or not working as expected. 3 | labels: ["bug"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thank you for taking the time to fill out this bug report! Please note that this issue tracker is only used for bug reports and feature requests. Other issues will be closed. 9 | 10 | If you have a configuration, workflow, or other question, please go back to the issue chooser and select one of the question links. 11 | - type: textarea 12 | id: versions 13 | attributes: 14 | label: Terraform CLI and Provider Versions 15 | description: What versions of Terraform CLI and the provider? 16 | placeholder: Output of `terraform version` from configuration directory 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: terraform-configuration 21 | attributes: 22 | label: Terraform Configuration 23 | description: Please copy and paste any relevant Terraform configuration. This will be automatically formatted into code, so no need for backticks. 24 | render: terraform 25 | validations: 26 | required: true 27 | - type: textarea 28 | id: expected-behavior 29 | attributes: 30 | label: Expected Behavior 31 | description: What did you expect to happen? 32 | placeholder: Description of what should have happened. 33 | validations: 34 | required: true 35 | - type: textarea 36 | id: actual-behavior 37 | attributes: 38 | label: Actual Behavior 39 | description: What actually happened? 40 | placeholder: Description of what actually happened. 41 | validations: 42 | required: true 43 | - type: textarea 44 | id: reproduction-steps 45 | attributes: 46 | label: Steps to Reproduce 47 | description: List of steps to reproduce the issue. 48 | value: | 49 | 1. `terraform apply` 50 | validations: 51 | required: true 52 | - type: dropdown 53 | id: impact 54 | attributes: 55 | label: How much impact is this issue causing? 56 | description: High represents completely not able to use the provider or unexpected destruction of data/infrastructure. Medium represents unable to upgrade provider version or an issue with potential workaround. Low represents minor provider code, configuration, or documentation issues. 57 | options: 58 | - High 59 | - Medium 60 | - Low 61 | validations: 62 | required: true 63 | - type: input 64 | id: logs 65 | attributes: 66 | label: Logs 67 | description: Please provide a link to a [GitHub Gist](https://gist.github.com) containing TRACE log output. [Terraform Debugging Documentation](https://www.terraform.io/internals/debugging) 68 | placeholder: https://gist.github.com/example/12345678 69 | validations: 70 | required: false 71 | - type: textarea 72 | id: additional-information 73 | attributes: 74 | label: Additional Information 75 | description: Are there any additional details about your environment, workflow, or recent changes that might be relevant? Have you discovered a workaround? Are there links to other related issues? 76 | validations: 77 | required: false 78 | - type: checkboxes 79 | id: terms 80 | attributes: 81 | label: Code of Conduct 82 | description: By submitting this issue, you agree to follow our [Community Guidelines](https://www.hashicorp.com/community-guidelines). 83 | options: 84 | - label: I agree to follow this project's Code of Conduct 85 | required: true 86 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_Request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Something is missing or could be improved. 3 | labels: ["enhancement"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thank you for taking the time to fill out this feature request! Please note that this issue tracker is only used for bug reports and feature requests. Other issues will be closed. 9 | 10 | If you have a configuration, workflow, or other question, please go back to the issue chooser and select one of the question links. 11 | - type: textarea 12 | id: versions 13 | attributes: 14 | label: Terraform CLI and Provider Versions 15 | description: What versions of Terraform CLI and the provider? 16 | placeholder: Output of `terraform version` from configuration directory 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: use-case 21 | attributes: 22 | label: Use Cases or Problem Statement 23 | description: What use cases or problems are you trying to solve? 24 | placeholder: Description of use cases or problems. 25 | validations: 26 | required: true 27 | - type: textarea 28 | id: proposal 29 | attributes: 30 | label: Proposal 31 | description: What solutions would you prefer? 32 | placeholder: Description of proposed solutions. 33 | validations: 34 | required: true 35 | - type: dropdown 36 | id: impact 37 | attributes: 38 | label: How much impact is this issue causing? 39 | description: High represents completely not able to use the provider without this. Medium represents unable to solve a specific problem or understand something. Low represents minor provider code, configuration, or documentation issues. 40 | options: 41 | - High 42 | - Medium 43 | - Low 44 | validations: 45 | required: true 46 | - type: textarea 47 | id: additional-information 48 | attributes: 49 | label: Additional Information 50 | description: Are there any additional details about your environment, workflow, or recent changes that might be relevant? Have you discovered a workaround? Are there links to other related issues? 51 | validations: 52 | required: false 53 | - type: checkboxes 54 | id: terms 55 | attributes: 56 | label: Code of Conduct 57 | description: By submitting this issue, you agree to follow our [Community Guidelines](https://www.hashicorp.com/community-guidelines). 58 | options: 59 | - label: I agree to follow this project's Code of Conduct 60 | required: true 61 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Terraform Provider Questions 4 | url: https://discuss.hashicorp.com/c/terraform-providers/31 5 | about: GitHub issues in this repository are only intended for bug reports and feature requests. Other issues will be closed. Please ask and answer questions through the Terraform Provider section of HashiCorp Discuss. 6 | - name: Terraform Language or Workflow Questions 7 | url: https://discuss.hashicorp.com/c/terraform-core 8 | about: Please ask and answer language or workflow related questions through the Terraform Core section of HashiCorp Discuss. 9 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Related Issue 2 | 3 | Fixes # 4 | 5 | ## Description 6 | 7 | In plain English, describe your approach to addressing the issue linked above. For example, if you made a particular design decision, let us know why you chose this path instead of another solution. 8 | 9 | 10 | ## Rollback Plan 11 | 12 | - [ ] If a change needs to be reverted, we will roll out an update to the code within 7 days. 13 | 14 | ## Changes to Security Controls 15 | 16 | Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain. 17 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | * Project [README](../README.md) 4 | * Official [Documentation](https://registry.terraform.io/providers/hashicorp/time/latest/docs) 5 | * Providers [Discuss forums](https://discuss.hashicorp.com/c/terraform-providers/31) 6 | * Terraform [Community](https://www.terraform.io/community.html) page -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See GitHub's docs for more information on this file: 2 | # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates 3 | version: 2 4 | updates: 5 | # Maintain dependencies for Go modules 6 | - package-ecosystem: "gomod" 7 | directory: "/" 8 | schedule: 9 | # Check for updates to Go modules every weekday 10 | interval: "daily" 11 | - package-ecosystem: "gomod" 12 | directory: "/tools" 13 | schedule: 14 | interval: "daily" 15 | - package-ecosystem: "github-actions" 16 | directory: "/" 17 | schedule: 18 | interval: "daily" 19 | -------------------------------------------------------------------------------- /.github/labeler-issue-triage.yml: -------------------------------------------------------------------------------- 1 | bug: 2 | - 'panic:' 3 | crash: 4 | - 'panic:' 5 | -------------------------------------------------------------------------------- /.github/labeler-pull-request-triage.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - changed-files: 3 | - any-glob-to-any-file: .github/dependabot.yml 4 | - any-glob-to-any-file: go.mod 5 | - any-glob-to-any-file: go.sum 6 | documentation: 7 | - changed-files: 8 | - any-glob-to-any-file: website/**/* -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # This workflow builds the product for all supported platforms and uploads the resulting 2 | # binaries as Actions artifacts. The workflow also uploads a build metadata file 3 | # (metadata.json) -- and a Terraform Registry manifest file (terraform-registry-manifest.json). 4 | # 5 | # Reference: https://github.com/hashicorp/terraform-provider-crt-example/blob/main/.github/workflows/README.md 6 | 7 | name: build 8 | 9 | # We default to running this workflow on every push to every branch. 10 | # This provides fast feedback when build issues occur, so they can be 11 | # fixed prior to being merged to the main branch. 12 | # 13 | # If you want to opt out of this, and only run the build on certain branches 14 | # please refer to the documentation on branch filtering here: 15 | # 16 | # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushbranchestagsbranches-ignoretags-ignore 17 | # 18 | on: [workflow_dispatch, push] 19 | 20 | env: 21 | PKG_NAME: "terraform-provider-time" 22 | 23 | jobs: 24 | # Detects the Go toolchain version to use for product builds. 25 | # 26 | # The implementation is inspired by envconsul -- https://go.hashi.co/get-go-version-example 27 | get-go-version: 28 | name: "Detect Go toolchain version" 29 | runs-on: ubuntu-latest 30 | outputs: 31 | go-version: ${{ steps.get-go-version.outputs.go-version }} 32 | steps: 33 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 34 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 35 | with: 36 | go-version-file: 'go.mod' 37 | - name: Detect Go version 38 | id: get-go-version 39 | run: | 40 | version="$(go list -f {{.GoVersion}} -m)" 41 | echo "go-version=$version" >> "$GITHUB_OUTPUT" 42 | 43 | # Parses the version/VERSION file. Reference: https://github.com/hashicorp/actions-set-product-version/blob/main/README.md 44 | # 45 | # > This action should be implemented in product repo `build.yml` files. The action is intended to grab the version 46 | # > from the version file at the beginning of the build, then passes those versions (along with metadata, where 47 | # > necessary) to any workflow jobs that need version information. 48 | set-product-version: 49 | name: "Parse version file" 50 | runs-on: ubuntu-latest 51 | outputs: 52 | product-version: ${{ steps.set-product-version.outputs.product-version }} 53 | product-base-version: ${{ steps.set-product-version.outputs.base-product-version }} 54 | product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} 55 | product-minor-version: ${{ steps.set-product-version.outputs.minor-product-version }} 56 | steps: 57 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 58 | - name: Set variables 59 | id: set-product-version 60 | uses: hashicorp/actions-set-product-version@v2 61 | 62 | # Creates metadata.json file containing build metadata for consumption by CRT workflows. 63 | # 64 | # Reference: https://github.com/hashicorp/actions-generate-metadata/blob/main/README.md 65 | generate-metadata-file: 66 | needs: set-product-version 67 | runs-on: ubuntu-latest 68 | outputs: 69 | filepath: ${{ steps.generate-metadata-file.outputs.filepath }} 70 | steps: 71 | - name: "Checkout directory" 72 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 73 | - name: Generate metadata file 74 | id: generate-metadata-file 75 | uses: hashicorp/actions-generate-metadata@v1 76 | with: 77 | version: ${{ needs.set-product-version.outputs.product-version }} 78 | product: ${{ env.PKG_NAME }} 79 | repositoryOwner: "hashicorp" 80 | - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 81 | with: 82 | name: metadata.json 83 | path: ${{ steps.generate-metadata-file.outputs.filepath }} 84 | 85 | # Uploads an Actions artifact named terraform-registry-manifest.json.zip. 86 | # 87 | # The artifact contains a single file with a filename that Terraform Registry expects 88 | # (example: terraform-provider-crt-example_2.3.6-alpha1_manifest.json). The file contents 89 | # are identical to the terraform-registry-manifest.json file in the source repository. 90 | upload-terraform-registry-manifest-artifact: 91 | needs: set-product-version 92 | runs-on: ubuntu-latest 93 | steps: 94 | - name: "Checkout directory" 95 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 96 | with: 97 | path: ${{ env.PKG_NAME }} 98 | - name: "Copy manifest from checkout directory to a file with the desired name" 99 | id: terraform-registry-manifest 100 | run: | 101 | name="${{ env.PKG_NAME }}" 102 | version="${{ needs.set-product-version.outputs.product-version }}" 103 | 104 | source="${name}/terraform-registry-manifest.json" 105 | destination="${name}_${version}_manifest.json" 106 | 107 | cp "$source" "$destination" 108 | echo "filename=$destination" >> "$GITHUB_OUTPUT" 109 | - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 110 | with: 111 | name: terraform-registry-manifest.json 112 | path: ${{ steps.terraform-registry-manifest.outputs.filename }} 113 | if-no-files-found: error 114 | 115 | # Builds the product for all platforms except macOS. 116 | # 117 | # With `reproducible: report`, this job also reports whether the build is reproducible, 118 | # but does not enforce it. 119 | # 120 | # Reference: https://github.com/hashicorp/actions-go-build/blob/main/README.md 121 | build: 122 | needs: 123 | - get-go-version 124 | - set-product-version 125 | runs-on: ubuntu-latest 126 | strategy: 127 | fail-fast: true 128 | # Verify expected Artifacts list for a workflow run. 129 | matrix: 130 | goos: [freebsd, windows, linux, darwin] 131 | goarch: ["386", "amd64", "arm", "arm64"] 132 | exclude: 133 | - goos: freebsd 134 | goarch: arm64 135 | - goos: windows 136 | goarch: arm64 137 | - goos: windows 138 | goarch: arm 139 | - goos: darwin 140 | goarch: 386 141 | - goos: darwin 142 | goarch: arm 143 | 144 | name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 145 | steps: 146 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 147 | - uses: hashicorp/actions-go-build@v1 148 | env: 149 | CGO_ENABLED: 0 150 | BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} 151 | PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} 152 | METADATA_VERSION: ${{ env.METADATA }} 153 | with: 154 | bin_name: "${{ env.PKG_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_x5" 155 | product_name: ${{ env.PKG_NAME }} 156 | product_version: ${{ needs.set-product-version.outputs.product-version }} 157 | go_version: ${{ needs.get-go-version.outputs.go-version }} 158 | os: ${{ matrix.goos }} 159 | arch: ${{ matrix.goarch }} 160 | reproducible: report 161 | instructions: | 162 | go build \ 163 | -o "$BIN_PATH" \ 164 | -trimpath \ 165 | -buildvcs=false \ 166 | -ldflags "-s -w" 167 | cp LICENSE "$TARGET_DIR/LICENSE.txt" 168 | 169 | whats-next: 170 | needs: 171 | - build 172 | - generate-metadata-file 173 | - upload-terraform-registry-manifest-artifact 174 | runs-on: ubuntu-latest 175 | name: "What's next?" 176 | steps: 177 | - name: "Write a helpful summary" 178 | run: | 179 | github_dot_com="${{ github.server_url }}" 180 | owner_with_name="${{ github.repository }}" 181 | ref="${{ github.ref }}" 182 | 183 | echo "### What's next?" >> "$GITHUB_STEP_SUMMARY" 184 | echo "#### For a release branch (see \`.release/ci.hcl\`)" >> $GITHUB_STEP_SUMMARY 185 | echo "After this \`build\` workflow run completes succesfully, you can expect the CRT \`prepare\` workflow to begin momentarily." >> "$GITHUB_STEP_SUMMARY" 186 | echo "To find the \`prepare\` workflow run, [view the checks for this commit]($github_dot_com/$owner_with_name/commits/$ref)" >> "$GITHUB_STEP_SUMMARY" 187 | -------------------------------------------------------------------------------- /.github/workflows/ci-changie.yml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | 4 | # Continuous integration handling for changie 5 | name: ci-changie 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - .changes/unreleased/*.yaml 11 | - .changie.yaml 12 | - .github/workflows/ci-changie.yml 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | check: 19 | runs-on: ubuntu-latest 20 | steps: 21 | # Ensure terraform-devex-repos is updated on version changes. 22 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 23 | # Ensure terraform-devex-repos is updated on version changes. 24 | - uses: miniscruff/changie-action@6dcc2533cac0495148ed4046c438487e4dceaa23 # v2.0.0 25 | with: 26 | version: latest 27 | args: batch patch --dry-run 28 | -------------------------------------------------------------------------------- /.github/workflows/compliance.yml: -------------------------------------------------------------------------------- 1 | name: compliance 2 | 3 | on: 4 | pull_request: 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | # Reference: ENGSRV-059 11 | copywrite: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 15 | - uses: hashicorp/setup-copywrite@32638da2d4e81d56a0764aa1547882fc4d209636 # v1.1.3 16 | - run: copywrite headers --plan 17 | - run: copywrite license --plan 18 | -------------------------------------------------------------------------------- /.github/workflows/issue-comment-triage.yml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | name: Issue Comment Triage 4 | 5 | on: 6 | issue_comment: 7 | types: [created] 8 | 9 | jobs: 10 | issue_comment_triage: 11 | runs-on: ubuntu-latest 12 | env: 13 | # issue_comment events are triggered by comments on issues and pull requests. Checking the 14 | # value of github.event.issue.pull_request tells us whether the issue is an issue or is 15 | # actually a pull request, allowing us to dynamically set the gh subcommand: 16 | # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only 17 | COMMAND: ${{ github.event.issue.pull_request && 'pr' || 'issue' }} 18 | GH_TOKEN: ${{ github.token }} 19 | steps: 20 | - name: 'Remove waiting-response on comment' 21 | run: gh ${{ env.COMMAND }} edit ${{ github.event.issue.html_url }} --remove-label waiting-response 22 | -------------------------------------------------------------------------------- /.github/workflows/issue-opened.yml: -------------------------------------------------------------------------------- 1 | name: Issue Opened Triage 2 | 3 | on: 4 | issues: 5 | types: [opened] 6 | 7 | jobs: 8 | issue_triage: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 12 | - uses: github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 # v3.4 13 | with: 14 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 15 | configuration-path: .github/labeler-issue-triage.yml 16 | enable-versioned-regex: 0 17 | -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | name: 'Lock Threads' 4 | 5 | on: 6 | schedule: 7 | - cron: '52 4 * * *' 8 | 9 | jobs: 10 | lock: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # NOTE: When TSCCR updates the GitHub action version, update the template workflow file to avoid drift: 14 | # https://github.com/hashicorp/terraform-devex-repos/blob/main/modules/repo/workflows/lock.tftpl 15 | - uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 # v5.0.1 16 | with: 17 | github-token: ${{ github.token }} 18 | issue-inactive-days: '30' 19 | issue-lock-reason: resolved 20 | pr-inactive-days: '30' 21 | pr-lock-reason: resolved 22 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: "Pull Request Triage" 2 | 3 | on: [pull_request_target] 4 | 5 | permissions: 6 | # CodelyTV/pr-size-labeler uses issues URL for labeling 7 | issues: write 8 | pull-requests: write 9 | 10 | jobs: 11 | triage: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 15 | with: 16 | configuration-path: .github/labeler-pull-request-triage.yml 17 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 18 | - uses: CodelyTV/pr-size-labeler@4ec67706cd878fbc1c8db0a5dcd28b6bb412e85a # v1.10.3 19 | with: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | xs_label: 'size/XS' 22 | xs_max_size: '30' 23 | s_label: 'size/S' 24 | s_max_size: '60' 25 | m_label: 'size/M' 26 | m_max_size: '150' 27 | l_label: 'size/L' 28 | l_max_size: '300' 29 | xl_label: 'size/XL' 30 | message_if_xl: '' 31 | files_to_ignore: 'go.sum' 32 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | branches: [ main ] 6 | paths-ignore: 7 | - 'README.md' 8 | - 'CHANGELOG.md' 9 | - 'website/*' 10 | push: 11 | branches: [ main ] 12 | paths-ignore: 13 | - 'README.md' 14 | - 'CHANGELOG.md' 15 | - 'website/*' 16 | 17 | jobs: 18 | 19 | build: 20 | name: Build 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 5 23 | 24 | steps: 25 | 26 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 27 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 28 | with: 29 | go-version-file: 'go.mod' 30 | 31 | - name: Run linters 32 | uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 33 | with: 34 | version: latest 35 | 36 | # We need the latest version of Terraform for our documentation generation to use 37 | - name: Set up Terraform 38 | uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 39 | with: 40 | terraform_wrapper: false 41 | 42 | - name: Generate 43 | run: make generate 44 | 45 | - name: Confirm no diff 46 | run: | 47 | git diff --compact-summary --exit-code || \ 48 | (echo "*** Unexpected differences after code generation. Run 'make generate' and commit."; exit 1) 49 | 50 | - name: Build 51 | run: make build 52 | 53 | test: 54 | name: 'Acc. Tests (OS: ${{ matrix.os }} / TF: ${{ matrix.terraform }})' 55 | needs: build 56 | runs-on: ${{ matrix.os }} 57 | timeout-minutes: 15 58 | 59 | strategy: 60 | fail-fast: false 61 | matrix: 62 | os: 63 | - macos-latest 64 | - windows-latest 65 | - ubuntu-latest 66 | terraform: ${{ fromJSON(vars.TF_VERSIONS_PROTOCOL_V5) }} 67 | 68 | steps: 69 | 70 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 71 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 72 | with: 73 | go-version-file: 'go.mod' 74 | 75 | - name: Setup Terraform ${{ matrix.terraform }} 76 | uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2 77 | with: 78 | terraform_version: ${{ matrix.terraform }} 79 | terraform_wrapper: false 80 | 81 | - name: Run acceptance test 82 | run: make testacc 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.swp 3 | .idea 4 | .vscode 5 | dist/ 6 | terraform-provider-time 7 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | linters: 3 | default: none 4 | enable: 5 | - copyloopvar 6 | - durationcheck 7 | - errcheck 8 | - forcetypeassert 9 | - godot 10 | - govet 11 | - ineffassign 12 | - makezero 13 | - misspell 14 | - nilerr 15 | - predeclared 16 | - staticcheck 17 | - unconvert 18 | - unparam 19 | - unused 20 | - usetesting 21 | exclusions: 22 | generated: lax 23 | presets: 24 | - comments 25 | - common-false-positives 26 | - legacy 27 | - std-error-handling 28 | paths: 29 | - third_party$ 30 | - builtin$ 31 | - examples$ 32 | issues: 33 | max-issues-per-linter: 0 34 | max-same-issues: 0 35 | formatters: 36 | enable: 37 | - gofmt 38 | exclusions: 39 | generated: lax 40 | paths: 41 | - third_party$ 42 | - builtin$ 43 | - examples$ 44 | -------------------------------------------------------------------------------- /.release/ci.hcl: -------------------------------------------------------------------------------- 1 | # Reference: https://github.com/hashicorp/crt-core-helloworld/blob/main/.release/ci.hcl (private repository) 2 | 3 | schema = "2" 4 | 5 | project "terraform-provider-time" { 6 | // team is currently unused and has no meaning 7 | // but is required to be non-empty by CRT orchestator 8 | team = "_UNUSED_" 9 | 10 | slack { 11 | notification_channel = "C02BASDVCDT" // #feed-terraform-sdk 12 | } 13 | 14 | github { 15 | organization = "hashicorp" 16 | repository = "terraform-provider-time" 17 | release_branches = ["main", "release/**"] 18 | } 19 | } 20 | 21 | event "merge" { 22 | } 23 | 24 | event "build" { 25 | action "build" { 26 | depends = ["merge"] 27 | 28 | organization = "hashicorp" 29 | repository = "terraform-provider-time" 30 | workflow = "build" 31 | } 32 | } 33 | 34 | event "prepare" { 35 | # `prepare` is the Common Release Tooling (CRT) artifact processing workflow. 36 | # It prepares artifacts for potential promotion to staging and production. 37 | # For example, it scans and signs artifacts. 38 | 39 | depends = ["build"] 40 | 41 | action "prepare" { 42 | organization = "hashicorp" 43 | repository = "crt-workflows-common" 44 | workflow = "prepare" 45 | depends = ["build"] 46 | } 47 | 48 | notification { 49 | on = "fail" 50 | } 51 | } 52 | 53 | event "trigger-staging" { 54 | } 55 | 56 | event "promote-staging" { 57 | action "promote-staging" { 58 | organization = "hashicorp" 59 | repository = "crt-workflows-common" 60 | workflow = "promote-staging" 61 | depends = null 62 | config = "release-metadata.hcl" 63 | } 64 | 65 | depends = ["trigger-staging"] 66 | 67 | notification { 68 | on = "always" 69 | } 70 | } 71 | 72 | event "trigger-production" { 73 | } 74 | 75 | event "promote-production" { 76 | action "promote-production" { 77 | organization = "hashicorp" 78 | repository = "crt-workflows-common" 79 | workflow = "promote-production" 80 | depends = null 81 | config = "" 82 | } 83 | 84 | depends = ["trigger-production"] 85 | 86 | notification { 87 | on = "always" 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /.release/release-metadata.hcl: -------------------------------------------------------------------------------- 1 | url_source_repository = "https://github.com/hashicorp/terraform-provider-time" 2 | url_project_website = "https://registry.terraform.io/providers/hashicorp/time" 3 | url_license = "https://github.com/hashicorp/terraform-provider-time/blob/main/LICENSE" 4 | url_release_notes = "https://github.com/hashicorp/terraform-provider-time/blob/main/CHANGELOG.md" 5 | -------------------------------------------------------------------------------- /.release/security-scan.hcl: -------------------------------------------------------------------------------- 1 | # Reference: https://github.com/hashicorp/security-scanner/blob/main/CONFIG.md#binary (private repository) 2 | 3 | binary { 4 | secrets { 5 | all = true 6 | } 7 | go_modules = true 8 | osv = true 9 | oss_index = false 10 | nvd = false 11 | } 12 | -------------------------------------------------------------------------------- /.release/terraform-provider-time-artifacts.hcl: -------------------------------------------------------------------------------- 1 | schema = 1 2 | artifacts { 3 | zip = [ 4 | "terraform-provider-time_${version}_darwin_amd64.zip", 5 | "terraform-provider-time_${version}_darwin_arm64.zip", 6 | "terraform-provider-time_${version}_freebsd_386.zip", 7 | "terraform-provider-time_${version}_freebsd_amd64.zip", 8 | "terraform-provider-time_${version}_freebsd_arm.zip", 9 | "terraform-provider-time_${version}_linux_386.zip", 10 | "terraform-provider-time_${version}_linux_amd64.zip", 11 | "terraform-provider-time_${version}_linux_arm.zip", 12 | "terraform-provider-time_${version}_linux_arm64.zip", 13 | "terraform-provider-time_${version}_windows_386.zip", 14 | "terraform-provider-time_${version}_windows_amd64.zip", 15 | ] 16 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.13.1 (April 28, 2025) 2 | 3 | NOTES: 4 | 5 | * Update dependencies ([#410](https://github.com/hashicorp/terraform-provider-time/issues/410)) 6 | 7 | ## 0.13.1-alpha1 (April 22, 2025) 8 | 9 | NOTES: 10 | 11 | * all: This release is being used to test new build and release actions. ([#413](https://github.com/hashicorp/terraform-provider-time/issues/413)) 12 | 13 | ## 0.13.0 (March 04, 2025) 14 | 15 | FEATURES: 16 | 17 | * functions/duration_parse: Added a new `duration_parse` function that parses [Go duration strings](https://pkg.go.dev/time#ParseDuration). ([#350](https://github.com/hashicorp/terraform-provider-time/issues/350)) 18 | * functions/unix_timestamp_parse: Added a new `unix_timestamp_parse` function that parses a unix timestamp integer and returns an object representation. ([#385](https://github.com/hashicorp/terraform-provider-time/issues/385)) 19 | 20 | ## 0.12.1 (September 11, 2024) 21 | 22 | NOTES: 23 | 24 | * all: This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#351](https://github.com/hashicorp/terraform-provider-time/issues/351)) 25 | 26 | ## 0.12.0 (July 17, 2024) 27 | 28 | ENHANCEMENTS: 29 | 30 | * resource/time_static: If the `rfc3339` value is set in config and known at plan-time, all other attributes will also be known during plan. ([#255](https://github.com/hashicorp/terraform-provider-time/issues/255)) 31 | 32 | ## 0.11.2 (May 28, 2024) 33 | 34 | NOTES: 35 | 36 | * This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#327](https://github.com/hashicorp/terraform-provider-time/issues/327)) 37 | 38 | ## 0.11.1 (March 11, 2024) 39 | 40 | NOTES: 41 | 42 | * No functional changes from v0.11.0. Minor documentation fixes. ([#299](https://github.com/hashicorp/terraform-provider-time/issues/299)) 43 | 44 | ## 0.11.0 (March 11, 2024) 45 | 46 | FEATURES: 47 | 48 | * functions/rfc3339_parse: Added a new `rfc3339_parse` function that parses an RFC3339 timestamp string and returns an object representation. ([#280](https://github.com/hashicorp/terraform-provider-time/issues/280)) 49 | 50 | ## 0.10.0 (December 06, 2023) 51 | 52 | BUG FIXES: 53 | 54 | * resource/time_offset: Fix bug preventing multiple offset arguments from being set ([#189](https://github.com/hashicorp/terraform-provider-time/issues/189)) 55 | 56 | ## 0.9.2 (November 28, 2023) 57 | 58 | NOTES: 59 | 60 | * This release introduces no functional changes. It does however include dependency updates which address upstream CVEs. ([#263](https://github.com/hashicorp/terraform-provider-time/issues/263)) 61 | 62 | ## 0.9.1 (November 2, 2022) 63 | 64 | BUG FIXES: 65 | 66 | * resource/time_rotating: Correctly retrieve the Terraform state during update ([#132](https://github.com/hashicorp/terraform-provider-time/pull/132)) 67 | 68 | ## 0.9.0 (October 11, 2022) 69 | 70 | NOTES: 71 | 72 | * provider: Rewritten to use the new [`terraform-plugin-framework`](https://www.terraform.io/plugin/framework) ([#112](https://github.com/hashicorp/terraform-provider-time/pull/112)) 73 | 74 | ## 0.8.0 (August 10, 2022) 75 | 76 | BUG FIXES: 77 | 78 | * documentation: Changed wording from "Conflicts with other `offset_`/`rotation_` arguments." to "At least one of the `offset_`/`rotation_` arguments must be configured." to correctly reflect the use of `AtLeastOneOf` ([#105](https://github.com/hashicorp/terraform-provider-time/pull/105)) 79 | 80 | NOTES: 81 | 82 | * provider: Upgrade Go version to 1.18 ([#114](https://github.com/hashicorp/terraform-provider-time/pull/114)) 83 | * provider: Enable `golangci-lint` ([#105](https://github.com/hashicorp/terraform-provider-time/pull/105)) 84 | 85 | ## 0.7.2 (July 01, 2021) 86 | 87 | BUG FIXES: 88 | 89 | * resource/time_sleep: Prevent `context deadline exceeded` error when timeout duration is configured above 20 minutes ([#45](https://github.com/hashicorp/terraform-provider-time/issues/45)) 90 | 91 | ## 0.7.1 (May 04, 2021) 92 | 93 | BUG FIXES: 94 | 95 | * provider: Ensure `darwin/arm64` platform is included in releases 96 | 97 | ## 0.7.0 (February 19, 2021) 98 | 99 | Binary releases of this provider now include the darwin-arm64 platform. This version contains no further changes. 100 | 101 | ## 0.6.0 (October 04, 2020) 102 | 103 | BREAKING CHANGES: 104 | 105 | * Dropped support for Terraform 0.11 and lower ([#16](https://github.com/hashicorp/terraform-provider-time/issues/16)) 106 | 107 | ENHANCEMENTS 108 | 109 | * Made `time_sleep` context aware, allowing easier early cancellation ([#16](https://github.com/hashicorp/terraform-provider-time/issues/16)) 110 | 111 | ## 0.5.0 (May 13, 2020) 112 | 113 | FEATURES 114 | 115 | * **New Resource:** `time_sleep` ([#12](https://github.com/hashicorp/terraform-provider-time/issues/12)) 116 | 117 | # 0.4.0 (April 21, 2020) 118 | 119 | BREAKING CHANGES: 120 | 121 | * resource/time_offset: `keepers` argument renamed to `triggers` 122 | * resource/time_offset: Remove non-RFC3339 RFC and `unixdate` attribute 123 | * resource/time_rotating: `keepers` argument renamed to `triggers` 124 | * resource/time_rotating: Remove non-RFC3339 RFC and `unixdate` attributes 125 | * resource/time_static: `keepers` argument renamed to `triggers` 126 | * resource/time_static: Remove non-RFC3339 RFC and `unixdate` attributes 127 | 128 | # v0.3.0 129 | 130 | ENHANCEMENTS: 131 | 132 | * resource/time_offset: Add `keepers` argument 133 | * resource/time_rotating: Add `keepers` argument 134 | * resource/time_static: Add `keepers` argument 135 | 136 | BUG FIXES: 137 | 138 | * resource/time_offset: Ensure `base_rfc3339` is always set in Terraform state during creation, even if unconfigured 139 | 140 | # v0.2.0 141 | 142 | BREAKING CHANGES: 143 | 144 | * resource/time_static: The `expiration_` arguments have been moved to the new `time_rotating` resource as `rotation_` arguments. 145 | 146 | FEATURES: 147 | 148 | * **New Resource:** `time_offset` 149 | * **New Resource:** `time_rotating` 150 | 151 | # v0.1.0 152 | 153 | FEATURES: 154 | 155 | * **New Resource:** `time_static` 156 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | default: build 2 | 3 | build: 4 | go build -v ./... 5 | 6 | install: build 7 | go install -v ./... 8 | 9 | # See https://golangci-lint.run/ 10 | lint: 11 | golangci-lint run 12 | 13 | # Generate docs and copywrite headers 14 | generate: 15 | cd tools; go generate ./... 16 | 17 | fmt: 18 | gofmt -s -w -e . 19 | 20 | test: 21 | go test -v -cover -timeout=120s -parallel=4 ./... 22 | 23 | testacc: 24 | TF_ACC=1 go test -v -cover -timeout 120m ./... 25 | 26 | .PHONY: build install lint generate fmt test testacc 27 | -------------------------------------------------------------------------------- /META.d/_summary.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | schema: 1.1 3 | 4 | partition: tf-ecosystem 5 | 6 | summary: 7 | owner: team-tf-core-plugins 8 | description: | 9 | Utility provider that provides Time-Based Resources 10 | visibility: public 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform Provider: Time 2 | 3 | Terraform Provider for time-based resources. 4 | 5 | Please note: Issues on this repository are intended to be related to bugs or feature requests with this particular provider codebase. See [Terraform Community](https://www.terraform.io/community.html) for a list of resources to ask questions about Terraform or this provider and its usage. 6 | 7 | ## Requirements 8 | 9 | * [Terraform](https://www.terraform.io/downloads) 10 | * [Go](https://go.dev/doc/install) (1.23) 11 | * [GNU Make](https://www.gnu.org/software/make/) 12 | * [golangci-lint](https://golangci-lint.run/usage/install/#local-installation) (optional) 13 | 14 | ## Using the Provider 15 | 16 | This Terraform Provider is available to install automatically via `terraform init`. It is recommended to setup the following Terraform configuration to pin the major version: 17 | 18 | ```hcl 19 | # Terraform 0.13 and later 20 | terraform { 21 | required_providers { 22 | time = { 23 | source = "hashicorp/time" 24 | version = "~> X.Y" # where X.Y is the current major version and minor version 25 | } 26 | } 27 | } 28 | 29 | # Terraform 0.12 30 | terraform { 31 | required_providers { 32 | time = "~> X.Y" # where X.Y is the current major version and minor version 33 | } 34 | } 35 | ``` 36 | 37 | ## Documentation, questions and discussions 38 | Official documentation on how to use this provider can be found on the 39 | [Terraform Registry](https://registry.terraform.io/providers/hashicorp/time/latest/docs). 40 | In case of specific questions or discussions, please use the 41 | HashiCorp [Terraform Providers Discuss forums](https://discuss.hashicorp.com/c/terraform-providers/31), 42 | in accordance with HashiCorp [Community Guidelines](https://www.hashicorp.com/community-guidelines). 43 | 44 | We also provide: 45 | 46 | * [Support](.github/SUPPORT.md) page for help when using the provider 47 | * [Contributing](.github/CONTRIBUTING.md) guidelines in case you want to help this project 48 | 49 | ## Compatibility 50 | 51 | Compatibility table between this provider, the [Terraform Plugin Protocol](https://www.terraform.io/plugin/how-terraform-works#terraform-plugin-protocol) 52 | version it implements, and Terraform: 53 | 54 | | Time Provider | Terraform Plugin Protocol | Terraform | 55 | |:-------------:|:----------------------------------:|:---------:| 56 | | `>= 0.8.x` | `5` | `>= 0.12` | 57 | | `>= 0.7.x` | `5` | `>= 0.12` | 58 | | `>= 0.6.x` | `5` | `>= 0.12` | 59 | | `>= 0.5.x` | `4` and `5` | `<= 0.12` | 60 | | `>= 0.4.x` | `4` and `5` | `<= 0.12` | 61 | 62 | Details can be found querying the [Registry API](https://www.terraform.io/internals/provider-registry-protocol#list-available-versions) 63 | that return all the details about which version are currently available for a particular provider. 64 | [Here](https://registry.terraform.io/v1/providers/hashicorp/time/versions) are the details for Time (JSON response). 65 | 66 | ## Development 67 | 68 | ### Building 69 | 70 | 1. `git clone` this repository and `cd` into its directory 71 | 2. `make` will trigger the Golang build 72 | 73 | The provided `GNUmakefile` defines additional commands generally useful during development, 74 | like for running tests, generating documentation, code formatting and linting. 75 | Taking a look at it's content is recommended. 76 | 77 | ### Testing 78 | 79 | In order to test the provider, you can run 80 | 81 | * `make test` to run provider tests 82 | * `make testacc` to run provider acceptance tests 83 | 84 | It's important to note that acceptance tests (`testacc`) will actually spawn 85 | `terraform` and the provider. Read more about they work on the 86 | [official page](https://www.terraform.io/plugin/sdkv2/testing/acceptance-tests). 87 | 88 | ### Generating documentation 89 | 90 | This provider uses [terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs/) 91 | to generate documentation and store it in the `docs/` directory. 92 | Once a release is cut, the Terraform Registry will download the documentation from `docs/` 93 | and associate it with the release version. Read more about how this works on the 94 | [official page](https://www.terraform.io/registry/providers/docs). 95 | 96 | Use `make generate` to ensure the documentation is regenerated with any changes. 97 | 98 | ### Using a development build 99 | 100 | If [running tests and acceptance tests](#testing) isn't enough, it's possible to set up a local terraform configuration 101 | to use a development builds of the provider. This can be achieved by leveraging the Terraform CLI 102 | [configuration file development overrides](https://www.terraform.io/cli/config/config-file#development-overrides-for-provider-developers). 103 | 104 | First, use `make install` to place a fresh development build of the provider in your 105 | [`${GOBIN}`](https://pkg.go.dev/cmd/go#hdr-Compile_and_install_packages_and_dependencies) 106 | (defaults to `${GOPATH}/bin` or `${HOME}/go/bin` if `${GOPATH}` is not set). Repeat 107 | this every time you make changes to the provider locally. 108 | 109 | Then, setup your environment following [these instructions](https://www.terraform.io/plugin/debugging#terraform-cli-development-overrides) 110 | to make your local terraform use your local build. 111 | 112 | ### Testing GitHub Actions 113 | 114 | This project uses [GitHub Actions](https://docs.github.com/en/actions/automating-builds-and-tests) to realize its CI. 115 | 116 | Sometimes it might be helpful to locally reproduce the behaviour of those actions, 117 | and for this we use [act](https://github.com/nektos/act). Once installed, you can _simulate_ the actions executed 118 | when opening a PR with: 119 | 120 | ```shell 121 | # List of workflows for the 'pull_request' action 122 | $ act -l pull_request 123 | 124 | # Execute the workflows associated with the `pull_request' action 125 | $ act pull_request 126 | ``` 127 | 128 | ## Releasing 129 | 130 | The releasable builds are generated from the [build GH workflow](./.github/workflows/build.yml) and the release/promotion process 131 | is completed via internal HashiCorp deployment tooling. Prior to release, the changelog should be updated in `main` with 132 | the changie tool, example: 133 | 134 | ```sh 135 | changie batch 3.7.2 && changie merge 136 | ``` 137 | 138 | ## License 139 | 140 | [Mozilla Public License v2.0](./LICENSE) 141 | -------------------------------------------------------------------------------- /docs/cdktf/python/functions/duration_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "duration_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse a Go duration string https://pkg.go.dev/time#ParseDuration into an object 6 | --- 7 | 8 | 9 | 10 | # function: duration_parse 11 | 12 | Given a [Go duration string](https://pkg.go.dev/time#ParseDuration), will parse and return an object representation of that duration. 13 | 14 | ## Example Usage 15 | 16 | ```terraform 17 | # Configuration using provider functions must include required_providers configuration. 18 | terraform { 19 | required_providers { 20 | time = { 21 | source = "hashicorp/time" 22 | # Setting the provider version is a strongly recommended practice 23 | # version = "..." 24 | } 25 | } 26 | # Provider functions require Terraform 1.8 and later. 27 | required_version = ">= 1.8.0" 28 | } 29 | 30 | output "example_output" { 31 | value = provider::time::duration_parse("1h") 32 | } 33 | ``` 34 | 35 | ## Signature 36 | 37 | 38 | ```text 39 | duration_parse(duration string) object 40 | ``` 41 | 42 | ## Arguments 43 | 44 | 45 | 1. `duration` (String) Go time package duration string to parse 46 | 47 | 48 | ## Return Type 49 | 50 | The `object` returned from `duration_parse` has the following attributes: 51 | - `hours` (Number) The duration as a floating point number of hours. 52 | - `minutes` (Number) The duration as a floating point number of minutes. 53 | - `seconds` (Number) The duration as a floating point number of seconds. 54 | - `milliseconds` (Number) The duration as an integer number of milliseconds. 55 | - `microseconds` (Number) The duration as an integer number of microseconds. 56 | - `nanoseconds` (Number) The duration as an integer number of nanoseconds. 57 | 58 | -------------------------------------------------------------------------------- /docs/cdktf/python/functions/rfc3339_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "rfc3339_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse an RFC3339 timestamp string into an object 6 | --- 7 | 8 | 9 | 10 | # function: rfc3339_parse 11 | 12 | Given an RFC3339 timestamp string, will parse and return an object representation of that date and time. 13 | 14 | ## Example Usage 15 | 16 | ```terraform 17 | # Configuration using provider functions must include required_providers configuration. 18 | terraform { 19 | required_providers { 20 | time = { 21 | source = "hashicorp/time" 22 | # Setting the provider version is a strongly recommended practice 23 | # version = "..." 24 | } 25 | } 26 | # Provider functions require Terraform 1.8 and later. 27 | required_version = ">= 1.8.0" 28 | } 29 | 30 | output "example_output" { 31 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z") 32 | } 33 | ``` 34 | 35 | ## Signature 36 | 37 | 38 | ```text 39 | rfc3339_parse(timestamp string) object 40 | ``` 41 | 42 | ## Arguments 43 | 44 | 45 | 1. `timestamp` (String) RFC3339 timestamp string to parse 46 | 47 | 48 | ## Return Type 49 | 50 | The `object` returned from `rfc3339_parse` has the following attributes: 51 | - `year` (Number) The year for the timestamp. 52 | - `year_day` (Number) The day of the year for the timestamp, in the range [1, 365] for non-leap years, and [1, 366] in leap years. 53 | - `day` (Number) The day of the month for the timestamp. 54 | - `month` (Number) The month of the year for the timestamp. 55 | - `month_name` (String) The name of the month for the timestamp (ex. "January"). 56 | - `weekday` (Number) The day of the week for the timestamp. 57 | - `weekday_name` (String) The name of the day for the timestamp (ex. "Sunday"). 58 | - `hour` (Number) The hour within the day for the timestamp, in the range [0, 23]. 59 | - `minute` (Number) The minute offset within the hour for the timestamp, in the range [0, 59]. 60 | - `second` (Number) The second offset within the minute for the timestamp, in the range [0, 59]. 61 | - `unix` (Number) The number of seconds elapsed since January 1, 1970 UTC. 62 | - `iso_year` (Number) The ISO 8601 year number. 63 | - `iso_week` (Number) The ISO 8601 week number. 64 | 65 | -------------------------------------------------------------------------------- /docs/cdktf/python/functions/unix_timestamp_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | 4 | # generated by https://github.com/hashicorp/terraform-plugin-docs 5 | page_title: "unix_timestamp_parse function - terraform-provider-time" 6 | subcategory: "" 7 | description: |- 8 | Parse a unix timestamp integer into an object 9 | --- 10 | 11 | # function: unix_timestamp_parse 12 | 13 | Given a unix timestamp integer, will parse and return an object representation of that date and time. A unix timestamp is the number of seconds elapsed since January 1, 1970 UTC. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | output "test" { 19 | value = provider::time::unix_timestamp_parse(1606105443) 20 | } 21 | ``` 22 | 23 | ## Signature 24 | 25 | 26 | ```text 27 | unix_timestamp_parse(unix_timestamp number) object 28 | ``` 29 | 30 | ## Arguments 31 | 32 | 33 | 1. `unix_timestamp` (Number) Unix Timestamp integer to parse 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/cdktf/python/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: Time" 3 | description: |- 4 | The time provider is used to interact with time-based resources. 5 | --- 6 | 7 | 8 | 9 | # Time Provider 10 | 11 | The time provider is used to interact with time-based resources. The provider itself has no configuration options. 12 | 13 | Use the navigation to the left to read about the available resources. 14 | 15 | ## Resource "Triggers" 16 | 17 | Certain time resources, only perform actions during specific lifecycle actions: 18 | 19 | - `time_offset`: Saves base timestamp into Terraform state only when created. 20 | - `time_sleep`: Sleeps when created and/or destroyed. 21 | - `time_static`: Saves base timestamp into Terraform state only when created. 22 | 23 | These resources provide an optional map argument called `triggers` that can be populated with arbitrary key/value pairs. When the keys or values of this argument are updated, Terraform will re-perform the desired action, such as updating the base timestamp or sleeping again. 24 | 25 | For example: 26 | 27 | ```python 28 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 29 | from constructs import Construct 30 | from cdktf import Token, Fn, TerraformStack 31 | # 32 | # Provider bindings are generated by running `cdktf get`. 33 | # See https://cdk.tf/provider-generation for more details. 34 | # 35 | from imports.aws.instance import Instance 36 | from imports.time.static_resource import StaticResource 37 | class MyConvertedCode(TerraformStack): 38 | def __init__(self, scope, name): 39 | super().__init__(scope, name) 40 | ami_update = StaticResource(self, "ami_update", 41 | triggers={ 42 | "ami_id": Token.as_string(example.id) 43 | } 44 | ) 45 | Instance(self, "server", 46 | ami=Token.as_string(Fn.lookup_nested(ami_update, ["triggers", "ami_id"])), 47 | tags={ 48 | "AmiUpdateTime": ami_update.rfc3339 49 | } 50 | ) 51 | ``` 52 | 53 | `triggers` are *not* treated as sensitive attributes; a value used for `triggers` will be displayed in Terraform UI output as plaintext. 54 | 55 | To force a these actions to reoccur without updating `triggers`, the [`terraform taint` command](https://www.terraform.io/docs/commands/taint.html) can be used to produce the action on the next run. 56 | 57 | -------------------------------------------------------------------------------- /docs/cdktf/python/resources/offset.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_offset Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | 9 | 10 | # time_offset (Resource) 11 | 12 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```python 21 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | from constructs import Construct 23 | from cdktf import TerraformOutput, TerraformStack 24 | # 25 | # Provider bindings are generated by running `cdktf get`. 26 | # See https://cdk.tf/provider-generation for more details. 27 | # 28 | from imports.time.offset import Offset 29 | class MyConvertedCode(TerraformStack): 30 | def __init__(self, scope, name): 31 | super().__init__(scope, name) 32 | example = Offset(self, "example", 33 | offset_days=7 34 | ) 35 | TerraformOutput(self, "one_week_from_now", 36 | value=example.rfc3339 37 | ) 38 | ``` 39 | 40 | ### Multiple Offsets Usage 41 | 42 | ```python 43 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 44 | from constructs import Construct 45 | from cdktf import TerraformOutput, TerraformStack 46 | # 47 | # Provider bindings are generated by running `cdktf get`. 48 | # See https://cdk.tf/provider-generation for more details. 49 | # 50 | from imports.time.offset import Offset 51 | class MyConvertedCode(TerraformStack): 52 | def __init__(self, scope, name): 53 | super().__init__(scope, name) 54 | example = Offset(self, "example", 55 | offset_months=1, 56 | offset_years=1 57 | ) 58 | TerraformOutput(self, "one_year_and_month_from_now", 59 | value=example.rfc3339 60 | ) 61 | ``` 62 | 63 | ### Triggers Usage 64 | 65 | ```python 66 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 67 | from constructs import Construct 68 | from cdktf import Token, Fn, TerraformStack 69 | # 70 | # Provider bindings are generated by running `cdktf get`. 71 | # See https://cdk.tf/provider-generation for more details. 72 | # 73 | from imports.aws.instance import Instance 74 | from imports.time.offset import Offset 75 | class MyConvertedCode(TerraformStack): 76 | def __init__(self, scope, name): 77 | super().__init__(scope, name) 78 | ami_update = Offset(self, "ami_update", 79 | offset_days=7, 80 | triggers={ 81 | "ami_id": Token.as_string(example.id) 82 | } 83 | ) 84 | Instance(self, "server", 85 | ami=Token.as_string(Fn.lookup_nested(ami_update, ["triggers", "ami_id"])), 86 | tags={ 87 | "ExpirationTime": ami_update.rfc3339 88 | } 89 | ) 90 | ``` 91 | 92 | 93 | ## Schema 94 | 95 | ### Optional 96 | 97 | - `base_rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 98 | - `offset_days` (Number) Number of days to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 99 | - `offset_hours` (Number) Number of hours to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 100 | - `offset_minutes` (Number) Number of minutes to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 101 | - `offset_months` (Number) Number of months to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 102 | - `offset_seconds` (Number) Number of seconds to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 103 | - `offset_years` (Number) Number of years to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 104 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 105 | 106 | ### Read-Only 107 | 108 | - `day` (Number) Number day of offset timestamp. 109 | - `hour` (Number) Number hour of offset timestamp. 110 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 111 | - `minute` (Number) Number minute of offset timestamp. 112 | - `month` (Number) Number month of offset timestamp. 113 | - `rfc3339` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 114 | - `second` (Number) Number second of offset timestamp. 115 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 116 | - `year` (Number) Number year of offset timestamp. 117 | 118 | ## Import 119 | 120 | This resource can be imported using the base UTC RFC3339 timestamp and offset years, months, days, hours, minutes, and seconds, separated by commas (`,`), e.g. 121 | 122 | ```shell 123 | terraform import time_offset.example 2020-02-12T06:36:13Z,0,0,7,0,0,0 124 | ``` 125 | 126 | The `triggers` argument cannot be imported. 127 | -------------------------------------------------------------------------------- /docs/cdktf/python/resources/rotating.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_rotating Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html by only forcing a new value on the set cadence. 6 | --- 7 | 8 | 9 | 10 | # time_rotating (Resource) 11 | 12 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html) by only forcing a new value on the set cadence. 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```python 21 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | from constructs import Construct 23 | from cdktf import TerraformStack 24 | # 25 | # Provider bindings are generated by running `cdktf get`. 26 | # See https://cdk.tf/provider-generation for more details. 27 | # 28 | from imports.time.rotating import Rotating 29 | class MyConvertedCode(TerraformStack): 30 | def __init__(self, scope, name): 31 | super().__init__(scope, name) 32 | Rotating(self, "example", 33 | rotation_days=30 34 | ) 35 | ``` 36 | 37 | 38 | ## Schema 39 | 40 | ### Optional 41 | 42 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 43 | - `rotation_days` (Number) Number of days to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 44 | - `rotation_hours` (Number) Number of hours to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 45 | - `rotation_minutes` (Number) Number of minutes to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 46 | - `rotation_months` (Number) Number of months to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 47 | - `rotation_rfc3339` (String) Configure the rotation timestamp with an [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format of the offset timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 48 | - `rotation_years` (Number) Number of years to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 49 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. These conditions recreate the resource in addition to other rotation arguments. See [the main provider documentation](../index.md) for more information. 50 | 51 | ### Read-Only 52 | 53 | - `day` (Number) Number day of timestamp. 54 | - `hour` (Number) Number hour of timestamp. 55 | - `id` (String) RFC3339 format of the timestamp, e.g. `2020-02-12T06:36:13Z`. 56 | - `minute` (Number) Number minute of timestamp. 57 | - `month` (Number) Number month of timestamp. 58 | - `second` (Number) Number second of timestamp. 59 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 60 | - `year` (Number) Number year of timestamp. 61 | 62 | ## Import 63 | 64 | This resource can be imported using the base UTC RFC3339 value and rotation years, months, days, hours, and minutes, separated by commas (`,`), e.g. for 30 days 65 | 66 | ```shell 67 | terraform import time_rotating.example 2020-02-12T06:36:13Z,0,0,30,0,0 68 | ``` 69 | 70 | Otherwise, to import with the rotation RFC3339 value, the base UTC RFC3339 value and rotation UTC RFC3339 value, separated by commas (`,`), e.g. 71 | 72 | ```shell 73 | terraform import time_rotating.example 2020-02-12T06:36:13Z,2020-02-13T06:36:13Z 74 | ``` 75 | 76 | The `triggers` argument cannot be imported. 77 | 78 | -------------------------------------------------------------------------------- /docs/cdktf/python/resources/sleep.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_sleep Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the local-exec provisioner https://www.terraform.io/docs/provisioners/local-exec.html. 6 | --- 7 | 8 | 9 | 10 | # time_sleep (Resource) 11 | 12 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the [`local-exec` provisioner](https://www.terraform.io/docs/provisioners/local-exec.html). 13 | 14 | -> In many cases, this resource should be considered a workaround for issues that should be reported and handled in downstream Terraform Provider logic. Downstream resources can usually introduce or adjust retries in their code to handle time delay issues for all Terraform configurations or upstream resources can be improved to better wait for a resource to be fully ready and available. 15 | 16 | ## Example Usage 17 | 18 | ### Delay Create Usage 19 | 20 | ```python 21 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | from constructs import Construct 23 | from cdktf import TerraformStack 24 | # 25 | # Provider bindings are generated by running `cdktf get`. 26 | # See https://cdk.tf/provider-generation for more details. 27 | # 28 | from imports.null.resource import Resource 29 | from imports.time.sleep import Sleep 30 | class MyConvertedCode(TerraformStack): 31 | def __init__(self, scope, name): 32 | super().__init__(scope, name) 33 | null_resource_previous = Resource(self, "previous") 34 | wait30_seconds = Sleep(self, "wait_30_seconds", 35 | create_duration="30s", 36 | depends_on=[null_resource_previous] 37 | ) 38 | Resource(self, "next", 39 | depends_on=[wait30_seconds] 40 | ) 41 | ``` 42 | 43 | ### Delay Destroy Usage 44 | 45 | ```python 46 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 47 | from constructs import Construct 48 | from cdktf import TerraformStack 49 | # 50 | # Provider bindings are generated by running `cdktf get`. 51 | # See https://cdk.tf/provider-generation for more details. 52 | # 53 | from imports.null.resource import Resource 54 | from imports.time.sleep import Sleep 55 | class MyConvertedCode(TerraformStack): 56 | def __init__(self, scope, name): 57 | super().__init__(scope, name) 58 | null_resource_previous = Resource(self, "previous") 59 | wait30_seconds = Sleep(self, "wait_30_seconds", 60 | depends_on=[null_resource_previous], 61 | destroy_duration="30s" 62 | ) 63 | Resource(self, "next", 64 | depends_on=[wait30_seconds] 65 | ) 66 | ``` 67 | 68 | ### Triggers Usage 69 | 70 | ```python 71 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 72 | from constructs import Construct 73 | from cdktf import Token, Fn, TerraformStack 74 | # 75 | # Provider bindings are generated by running `cdktf get`. 76 | # See https://cdk.tf/provider-generation for more details. 77 | # 78 | from imports.aws.db_subnet_group import DbSubnetGroup 79 | from imports.aws.ram_resource_association import RamResourceAssociation 80 | from imports.time.sleep import Sleep 81 | class MyConvertedCode(TerraformStack): 82 | def __init__(self, scope, name): 83 | super().__init__(scope, name) 84 | example = RamResourceAssociation(self, "example", 85 | resource_arn=Token.as_string(aws_subnet_example.arn), 86 | resource_share_arn=Token.as_string(aws_ram_resource_share_example.arn) 87 | ) 88 | ram_resource_propagation = Sleep(self, "ram_resource_propagation", 89 | create_duration="60s", 90 | triggers={ 91 | "subnet_arn": example.resource_arn, 92 | "subnet_id": Token.as_string(aws_subnet_example.id) 93 | } 94 | ) 95 | aws_db_subnet_group_example = DbSubnetGroup(self, "example_2", 96 | name="example", 97 | subnet_ids=[ 98 | Token.as_string( 99 | Fn.lookup_nested(ram_resource_propagation.triggers, ["\"subnet_id\""])) 100 | ] 101 | ) 102 | # This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match. 103 | aws_db_subnet_group_example.override_logical_id("example") 104 | ``` 105 | 106 | 107 | ## Schema 108 | 109 | ### Optional 110 | 111 | - `create_duration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource creation. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. 112 | - `destroy_duration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource destroy. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. This value or any updates to it must be successfully applied into the Terraform state before destroying this resource to take effect. 113 | - `triggers` (Map of String) (Optional) Arbitrary map of values that, when changed, will run any creation or destroy delays again. See [the main provider documentation](../index.md) for more information. 114 | 115 | ### Read-Only 116 | 117 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 118 | 119 | ## Import 120 | 121 | This resource can be imported with the `create_duration` and `destroy_duration`, separated by a comma (`,`). 122 | 123 | e.g. For 30 seconds create duration with no destroy duration: 124 | 125 | ```shell 126 | terraform import time_sleep.example 30s, 127 | ``` 128 | 129 | e.g. For 30 seconds destroy duration with no create duration: 130 | 131 | ```shell 132 | terraform import time_sleep.example ,30s 133 | ``` 134 | 135 | The `triggers` argument cannot be imported. 136 | -------------------------------------------------------------------------------- /docs/cdktf/python/resources/static.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_static Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | 9 | 10 | # time_static (Resource) 11 | 12 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```python 21 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | from constructs import Construct 23 | from cdktf import TerraformOutput, TerraformStack 24 | # 25 | # Provider bindings are generated by running `cdktf get`. 26 | # See https://cdk.tf/provider-generation for more details. 27 | # 28 | from imports.time.static_resource import StaticResource 29 | class MyConvertedCode(TerraformStack): 30 | def __init__(self, scope, name): 31 | super().__init__(scope, name) 32 | example = StaticResource(self, "example") 33 | TerraformOutput(self, "current_time", 34 | value=example.rfc3339 35 | ) 36 | ``` 37 | 38 | ### Triggers Usage 39 | 40 | ```python 41 | # DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 42 | from constructs import Construct 43 | from cdktf import Token, Fn, TerraformStack 44 | # 45 | # Provider bindings are generated by running `cdktf get`. 46 | # See https://cdk.tf/provider-generation for more details. 47 | # 48 | from imports.aws.instance import Instance 49 | from imports.time.static_resource import StaticResource 50 | class MyConvertedCode(TerraformStack): 51 | def __init__(self, scope, name): 52 | super().__init__(scope, name) 53 | ami_update = StaticResource(self, "ami_update", 54 | triggers={ 55 | "ami_id": Token.as_string(example.id) 56 | } 57 | ) 58 | Instance(self, "server", 59 | ami=Token.as_string(Fn.lookup_nested(ami_update, ["triggers", "ami_id"])), 60 | tags={ 61 | "AmiUpdateTime": ami_update.rfc3339 62 | } 63 | ) 64 | ``` 65 | 66 | 67 | ## Schema 68 | 69 | ### Optional 70 | 71 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 72 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 73 | 74 | ### Read-Only 75 | 76 | - `day` (Number) Number day of timestamp. 77 | - `hour` (Number) Number hour of timestamp. 78 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 79 | - `minute` (Number) Number minute of timestamp. 80 | - `month` (Number) Number month of timestamp. 81 | - `second` (Number) Number second of timestamp. 82 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 83 | - `year` (Number) Number year of timestamp. 84 | 85 | 86 | ## Import 87 | 88 | This resource can be imported using the UTC RFC3339 value, e.g. 89 | 90 | ```shell 91 | terraform import time_static.example 2020-02-12T06:36:13Z 92 | ``` 93 | 94 | The `triggers` argument cannot be imported. 95 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/functions/duration_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "duration_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse a Go duration string https://pkg.go.dev/time#ParseDuration into an object 6 | --- 7 | 8 | 9 | 10 | # function: duration_parse 11 | 12 | Given a [Go duration string](https://pkg.go.dev/time#ParseDuration), will parse and return an object representation of that duration. 13 | 14 | ## Example Usage 15 | 16 | ```terraform 17 | # Configuration using provider functions must include required_providers configuration. 18 | terraform { 19 | required_providers { 20 | time = { 21 | source = "hashicorp/time" 22 | # Setting the provider version is a strongly recommended practice 23 | # version = "..." 24 | } 25 | } 26 | # Provider functions require Terraform 1.8 and later. 27 | required_version = ">= 1.8.0" 28 | } 29 | 30 | output "example_output" { 31 | value = provider::time::duration_parse("1h") 32 | } 33 | ``` 34 | 35 | ## Signature 36 | 37 | 38 | ```text 39 | duration_parse(duration string) object 40 | ``` 41 | 42 | ## Arguments 43 | 44 | 45 | 1. `duration` (String) Go time package duration string to parse 46 | 47 | 48 | ## Return Type 49 | 50 | The `object` returned from `duration_parse` has the following attributes: 51 | - `hours` (Number) The duration as a floating point number of hours. 52 | - `minutes` (Number) The duration as a floating point number of minutes. 53 | - `seconds` (Number) The duration as a floating point number of seconds. 54 | - `milliseconds` (Number) The duration as an integer number of milliseconds. 55 | - `microseconds` (Number) The duration as an integer number of microseconds. 56 | - `nanoseconds` (Number) The duration as an integer number of nanoseconds. 57 | 58 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/functions/rfc3339_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "rfc3339_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse an RFC3339 timestamp string into an object 6 | --- 7 | 8 | 9 | 10 | # function: rfc3339_parse 11 | 12 | Given an RFC3339 timestamp string, will parse and return an object representation of that date and time. 13 | 14 | ## Example Usage 15 | 16 | ```terraform 17 | # Configuration using provider functions must include required_providers configuration. 18 | terraform { 19 | required_providers { 20 | time = { 21 | source = "hashicorp/time" 22 | # Setting the provider version is a strongly recommended practice 23 | # version = "..." 24 | } 25 | } 26 | # Provider functions require Terraform 1.8 and later. 27 | required_version = ">= 1.8.0" 28 | } 29 | 30 | output "example_output" { 31 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z") 32 | } 33 | ``` 34 | 35 | ## Signature 36 | 37 | 38 | ```text 39 | rfc3339_parse(timestamp string) object 40 | ``` 41 | 42 | ## Arguments 43 | 44 | 45 | 1. `timestamp` (String) RFC3339 timestamp string to parse 46 | 47 | 48 | ## Return Type 49 | 50 | The `object` returned from `rfc3339_parse` has the following attributes: 51 | - `year` (Number) The year for the timestamp. 52 | - `year_day` (Number) The day of the year for the timestamp, in the range [1, 365] for non-leap years, and [1, 366] in leap years. 53 | - `day` (Number) The day of the month for the timestamp. 54 | - `month` (Number) The month of the year for the timestamp. 55 | - `month_name` (String) The name of the month for the timestamp (ex. "January"). 56 | - `weekday` (Number) The day of the week for the timestamp. 57 | - `weekday_name` (String) The name of the day for the timestamp (ex. "Sunday"). 58 | - `hour` (Number) The hour within the day for the timestamp, in the range [0, 23]. 59 | - `minute` (Number) The minute offset within the hour for the timestamp, in the range [0, 59]. 60 | - `second` (Number) The second offset within the minute for the timestamp, in the range [0, 59]. 61 | - `unix` (Number) The number of seconds elapsed since January 1, 1970 UTC. 62 | - `iso_year` (Number) The ISO 8601 year number. 63 | - `iso_week` (Number) The ISO 8601 week number. 64 | 65 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/functions/unix_timestamp_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | 4 | # generated by https://github.com/hashicorp/terraform-plugin-docs 5 | page_title: "unix_timestamp_parse function - terraform-provider-time" 6 | subcategory: "" 7 | description: |- 8 | Parse a unix timestamp integer into an object 9 | --- 10 | 11 | # function: unix_timestamp_parse 12 | 13 | Given a unix timestamp integer, will parse and return an object representation of that date and time. A unix timestamp is the number of seconds elapsed since January 1, 1970 UTC. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | output "test" { 19 | value = provider::time::unix_timestamp_parse(1606105443) 20 | } 21 | ``` 22 | 23 | ## Signature 24 | 25 | 26 | ```text 27 | unix_timestamp_parse(unix_timestamp number) object 28 | ``` 29 | 30 | ## Arguments 31 | 32 | 33 | 1. `unix_timestamp` (Number) Unix Timestamp integer to parse 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: Time" 3 | description: |- 4 | The time provider is used to interact with time-based resources. 5 | --- 6 | 7 | 8 | 9 | # Time Provider 10 | 11 | The time provider is used to interact with time-based resources. The provider itself has no configuration options. 12 | 13 | Use the navigation to the left to read about the available resources. 14 | 15 | ## Resource "Triggers" 16 | 17 | Certain time resources, only perform actions during specific lifecycle actions: 18 | 19 | - `time_offset`: Saves base timestamp into Terraform state only when created. 20 | - `time_sleep`: Sleeps when created and/or destroyed. 21 | - `time_static`: Saves base timestamp into Terraform state only when created. 22 | 23 | These resources provide an optional map argument called `triggers` that can be populated with arbitrary key/value pairs. When the keys or values of this argument are updated, Terraform will re-perform the desired action, such as updating the base timestamp or sleeping again. 24 | 25 | For example: 26 | 27 | ```typescript 28 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 29 | import { Construct } from "constructs"; 30 | import { Token, Fn, TerraformStack } from "cdktf"; 31 | /* 32 | * Provider bindings are generated by running `cdktf get`. 33 | * See https://cdk.tf/provider-generation for more details. 34 | */ 35 | import { Instance } from "./.gen/providers/aws/instance"; 36 | import { StaticResource } from "./.gen/providers/time/static-resource"; 37 | class MyConvertedCode extends TerraformStack { 38 | constructor(scope: Construct, name: string) { 39 | super(scope, name); 40 | const amiUpdate = new StaticResource(this, "ami_update", { 41 | triggers: { 42 | ami_id: Token.asString(example.id), 43 | }, 44 | }); 45 | new Instance(this, "server", { 46 | ami: Token.asString(Fn.lookupNested(amiUpdate, ["triggers", "ami_id"])), 47 | tags: { 48 | AmiUpdateTime: amiUpdate.rfc3339, 49 | }, 50 | }); 51 | } 52 | } 53 | 54 | ``` 55 | 56 | `triggers` are *not* treated as sensitive attributes; a value used for `triggers` will be displayed in Terraform UI output as plaintext. 57 | 58 | To force a these actions to reoccur without updating `triggers`, the [`terraform taint` command](https://www.terraform.io/docs/commands/taint.html) can be used to produce the action on the next run. 59 | 60 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/resources/offset.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_offset Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | 9 | 10 | # time_offset (Resource) 11 | 12 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```typescript 21 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | import { Construct } from "constructs"; 23 | import { TerraformOutput, TerraformStack } from "cdktf"; 24 | /* 25 | * Provider bindings are generated by running `cdktf get`. 26 | * See https://cdk.tf/provider-generation for more details. 27 | */ 28 | import { Offset } from "./.gen/providers/time/offset"; 29 | class MyConvertedCode extends TerraformStack { 30 | constructor(scope: Construct, name: string) { 31 | super(scope, name); 32 | const example = new Offset(this, "example", { 33 | offsetDays: 7, 34 | }); 35 | new TerraformOutput(this, "one_week_from_now", { 36 | value: example.rfc3339, 37 | }); 38 | } 39 | } 40 | 41 | ``` 42 | 43 | ### Multiple Offsets Usage 44 | 45 | ```typescript 46 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 47 | import { Construct } from "constructs"; 48 | import { TerraformOutput, TerraformStack } from "cdktf"; 49 | /* 50 | * Provider bindings are generated by running `cdktf get`. 51 | * See https://cdk.tf/provider-generation for more details. 52 | */ 53 | import { Offset } from "./.gen/providers/time/offset"; 54 | class MyConvertedCode extends TerraformStack { 55 | constructor(scope: Construct, name: string) { 56 | super(scope, name); 57 | const example = new Offset(this, "example", { 58 | offsetMonths: 1, 59 | offsetYears: 1, 60 | }); 61 | new TerraformOutput(this, "one_year_and_month_from_now", { 62 | value: example.rfc3339, 63 | }); 64 | } 65 | } 66 | 67 | ``` 68 | 69 | ### Triggers Usage 70 | 71 | ```typescript 72 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 73 | import { Construct } from "constructs"; 74 | import { Token, Fn, TerraformStack } from "cdktf"; 75 | /* 76 | * Provider bindings are generated by running `cdktf get`. 77 | * See https://cdk.tf/provider-generation for more details. 78 | */ 79 | import { Instance } from "./.gen/providers/aws/instance"; 80 | import { Offset } from "./.gen/providers/time/offset"; 81 | class MyConvertedCode extends TerraformStack { 82 | constructor(scope: Construct, name: string) { 83 | super(scope, name); 84 | const amiUpdate = new Offset(this, "ami_update", { 85 | offsetDays: 7, 86 | triggers: { 87 | ami_id: Token.asString(example.id), 88 | }, 89 | }); 90 | new Instance(this, "server", { 91 | ami: Token.asString(Fn.lookupNested(amiUpdate, ["triggers", "ami_id"])), 92 | tags: { 93 | ExpirationTime: amiUpdate.rfc3339, 94 | }, 95 | }); 96 | } 97 | } 98 | 99 | ``` 100 | 101 | 102 | ## Schema 103 | 104 | ### Optional 105 | 106 | - `baseRfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 107 | - `offsetDays` (Number) Number of days to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 108 | - `offsetHours` (Number) Number of hours to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 109 | - `offsetMinutes` (Number) Number of minutes to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 110 | - `offsetMonths` (Number) Number of months to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 111 | - `offsetSeconds` (Number) Number of seconds to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 112 | - `offsetYears` (Number) Number of years to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 113 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 114 | 115 | ### Read-Only 116 | 117 | - `day` (Number) Number day of offset timestamp. 118 | - `hour` (Number) Number hour of offset timestamp. 119 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 120 | - `minute` (Number) Number minute of offset timestamp. 121 | - `month` (Number) Number month of offset timestamp. 122 | - `rfc3339` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 123 | - `second` (Number) Number second of offset timestamp. 124 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 125 | - `year` (Number) Number year of offset timestamp. 126 | 127 | ## Import 128 | 129 | This resource can be imported using the base UTC RFC3339 timestamp and offset years, months, days, hours, minutes, and seconds, separated by commas (`,`), e.g. 130 | 131 | ```shell 132 | terraform import time_offset.example 2020-02-12T06:36:13Z,0,0,7,0,0,0 133 | ``` 134 | 135 | The `triggers` argument cannot be imported. 136 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/resources/rotating.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_rotating Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html by only forcing a new value on the set cadence. 6 | --- 7 | 8 | 9 | 10 | # time_rotating (Resource) 11 | 12 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html) by only forcing a new value on the set cadence. 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```typescript 21 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | import { Construct } from "constructs"; 23 | import { TerraformStack } from "cdktf"; 24 | /* 25 | * Provider bindings are generated by running `cdktf get`. 26 | * See https://cdk.tf/provider-generation for more details. 27 | */ 28 | import { Rotating } from "./.gen/providers/time/rotating"; 29 | class MyConvertedCode extends TerraformStack { 30 | constructor(scope: Construct, name: string) { 31 | super(scope, name); 32 | new Rotating(this, "example", { 33 | rotationDays: 30, 34 | }); 35 | } 36 | } 37 | 38 | ``` 39 | 40 | 41 | ## Schema 42 | 43 | ### Optional 44 | 45 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 46 | - `rotationDays` (Number) Number of days to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 47 | - `rotationHours` (Number) Number of hours to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 48 | - `rotationMinutes` (Number) Number of minutes to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 49 | - `rotationMonths` (Number) Number of months to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 50 | - `rotationRfc3339` (String) Configure the rotation timestamp with an [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format of the offset timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 51 | - `rotationYears` (Number) Number of years to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 52 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. These conditions recreate the resource in addition to other rotation arguments. See [the main provider documentation](../index.md) for more information. 53 | 54 | ### Read-Only 55 | 56 | - `day` (Number) Number day of timestamp. 57 | - `hour` (Number) Number hour of timestamp. 58 | - `id` (String) RFC3339 format of the timestamp, e.g. `2020-02-12T06:36:13Z`. 59 | - `minute` (Number) Number minute of timestamp. 60 | - `month` (Number) Number month of timestamp. 61 | - `second` (Number) Number second of timestamp. 62 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 63 | - `year` (Number) Number year of timestamp. 64 | 65 | ## Import 66 | 67 | This resource can be imported using the base UTC RFC3339 value and rotation years, months, days, hours, and minutes, separated by commas (`,`), e.g. for 30 days 68 | 69 | ```shell 70 | terraform import time_rotating.example 2020-02-12T06:36:13Z,0,0,30,0,0 71 | ``` 72 | 73 | Otherwise, to import with the rotation RFC3339 value, the base UTC RFC3339 value and rotation UTC RFC3339 value, separated by commas (`,`), e.g. 74 | 75 | ```shell 76 | terraform import time_rotating.example 2020-02-12T06:36:13Z,2020-02-13T06:36:13Z 77 | ``` 78 | 79 | The `triggers` argument cannot be imported. 80 | 81 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/resources/sleep.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_sleep Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the local-exec provisioner https://www.terraform.io/docs/provisioners/local-exec.html. 6 | --- 7 | 8 | 9 | 10 | # time_sleep (Resource) 11 | 12 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the [`local-exec` provisioner](https://www.terraform.io/docs/provisioners/local-exec.html). 13 | 14 | -> In many cases, this resource should be considered a workaround for issues that should be reported and handled in downstream Terraform Provider logic. Downstream resources can usually introduce or adjust retries in their code to handle time delay issues for all Terraform configurations or upstream resources can be improved to better wait for a resource to be fully ready and available. 15 | 16 | ## Example Usage 17 | 18 | ### Delay Create Usage 19 | 20 | ```typescript 21 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | import { Construct } from "constructs"; 23 | import { TerraformStack } from "cdktf"; 24 | /* 25 | * Provider bindings are generated by running `cdktf get`. 26 | * See https://cdk.tf/provider-generation for more details. 27 | */ 28 | import { Resource } from "./.gen/providers/null/resource"; 29 | import { Sleep } from "./.gen/providers/time/sleep"; 30 | class MyConvertedCode extends TerraformStack { 31 | constructor(scope: Construct, name: string) { 32 | super(scope, name); 33 | const nullResourcePrevious = new Resource(this, "previous", {}); 34 | const wait30Seconds = new Sleep(this, "wait_30_seconds", { 35 | createDuration: "30s", 36 | dependsOn: [nullResourcePrevious], 37 | }); 38 | new Resource(this, "next", { 39 | dependsOn: [wait30Seconds], 40 | }); 41 | } 42 | } 43 | 44 | ``` 45 | 46 | ### Delay Destroy Usage 47 | 48 | ```typescript 49 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 50 | import { Construct } from "constructs"; 51 | import { TerraformStack } from "cdktf"; 52 | /* 53 | * Provider bindings are generated by running `cdktf get`. 54 | * See https://cdk.tf/provider-generation for more details. 55 | */ 56 | import { Resource } from "./.gen/providers/null/resource"; 57 | import { Sleep } from "./.gen/providers/time/sleep"; 58 | class MyConvertedCode extends TerraformStack { 59 | constructor(scope: Construct, name: string) { 60 | super(scope, name); 61 | const nullResourcePrevious = new Resource(this, "previous", {}); 62 | const wait30Seconds = new Sleep(this, "wait_30_seconds", { 63 | dependsOn: [nullResourcePrevious], 64 | destroyDuration: "30s", 65 | }); 66 | new Resource(this, "next", { 67 | dependsOn: [wait30Seconds], 68 | }); 69 | } 70 | } 71 | 72 | ``` 73 | 74 | ### Triggers Usage 75 | 76 | ```typescript 77 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 78 | import { Construct } from "constructs"; 79 | import { Token, Fn, TerraformStack } from "cdktf"; 80 | /* 81 | * Provider bindings are generated by running `cdktf get`. 82 | * See https://cdk.tf/provider-generation for more details. 83 | */ 84 | import { DbSubnetGroup } from "./.gen/providers/aws/db-subnet-group"; 85 | import { RamResourceAssociation } from "./.gen/providers/aws/ram-resource-association"; 86 | import { Sleep } from "./.gen/providers/time/sleep"; 87 | class MyConvertedCode extends TerraformStack { 88 | constructor(scope: Construct, name: string) { 89 | super(scope, name); 90 | const example = new RamResourceAssociation(this, "example", { 91 | resourceArn: Token.asString(awsSubnetExample.arn), 92 | resourceShareArn: Token.asString(awsRamResourceShareExample.arn), 93 | }); 94 | const ramResourcePropagation = new Sleep(this, "ram_resource_propagation", { 95 | createDuration: "60s", 96 | triggers: { 97 | subnet_arn: example.resourceArn, 98 | subnet_id: Token.asString(awsSubnetExample.id), 99 | }, 100 | }); 101 | const awsDbSubnetGroupExample = new DbSubnetGroup(this, "example_2", { 102 | name: "example", 103 | subnetIds: [ 104 | Token.asString( 105 | Fn.lookupNested(ramResourcePropagation.triggers, ['"subnet_id"']) 106 | ), 107 | ], 108 | }); 109 | /*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/ 110 | awsDbSubnetGroupExample.overrideLogicalId("example"); 111 | } 112 | } 113 | 114 | ``` 115 | 116 | 117 | ## Schema 118 | 119 | ### Optional 120 | 121 | - `createDuration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource creation. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. 122 | - `destroyDuration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource destroy. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. This value or any updates to it must be successfully applied into the Terraform state before destroying this resource to take effect. 123 | - `triggers` (Map of String) (Optional) Arbitrary map of values that, when changed, will run any creation or destroy delays again. See [the main provider documentation](../index.md) for more information. 124 | 125 | ### Read-Only 126 | 127 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 128 | 129 | ## Import 130 | 131 | This resource can be imported with the `createDuration` and `destroyDuration`, separated by a comma (`,`). 132 | 133 | e.g. For 30 seconds create duration with no destroy duration: 134 | 135 | ```shell 136 | terraform import time_sleep.example 30s, 137 | ``` 138 | 139 | e.g. For 30 seconds destroy duration with no create duration: 140 | 141 | ```shell 142 | terraform import time_sleep.example ,30s 143 | ``` 144 | 145 | The `triggers` argument cannot be imported. 146 | -------------------------------------------------------------------------------- /docs/cdktf/typescript/resources/static.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_static Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | 9 | 10 | # time_static (Resource) 11 | 12 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 13 | 14 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 15 | 16 | ## Example Usage 17 | 18 | ### Basic Usage 19 | 20 | ```typescript 21 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 22 | import { Construct } from "constructs"; 23 | import { TerraformOutput, TerraformStack } from "cdktf"; 24 | /* 25 | * Provider bindings are generated by running `cdktf get`. 26 | * See https://cdk.tf/provider-generation for more details. 27 | */ 28 | import { StaticResource } from "./.gen/providers/time/static-resource"; 29 | class MyConvertedCode extends TerraformStack { 30 | constructor(scope: Construct, name: string) { 31 | super(scope, name); 32 | const example = new StaticResource(this, "example", {}); 33 | new TerraformOutput(this, "current_time", { 34 | value: example.rfc3339, 35 | }); 36 | } 37 | } 38 | 39 | ``` 40 | 41 | ### Triggers Usage 42 | 43 | ```typescript 44 | // DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug 45 | import { Construct } from "constructs"; 46 | import { Token, Fn, TerraformStack } from "cdktf"; 47 | /* 48 | * Provider bindings are generated by running `cdktf get`. 49 | * See https://cdk.tf/provider-generation for more details. 50 | */ 51 | import { Instance } from "./.gen/providers/aws/instance"; 52 | import { StaticResource } from "./.gen/providers/time/static-resource"; 53 | class MyConvertedCode extends TerraformStack { 54 | constructor(scope: Construct, name: string) { 55 | super(scope, name); 56 | const amiUpdate = new StaticResource(this, "ami_update", { 57 | triggers: { 58 | ami_id: Token.asString(example.id), 59 | }, 60 | }); 61 | new Instance(this, "server", { 62 | ami: Token.asString(Fn.lookupNested(amiUpdate, ["triggers", "ami_id"])), 63 | tags: { 64 | AmiUpdateTime: amiUpdate.rfc3339, 65 | }, 66 | }); 67 | } 68 | } 69 | 70 | ``` 71 | 72 | 73 | ## Schema 74 | 75 | ### Optional 76 | 77 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 78 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 79 | 80 | ### Read-Only 81 | 82 | - `day` (Number) Number day of timestamp. 83 | - `hour` (Number) Number hour of timestamp. 84 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 85 | - `minute` (Number) Number minute of timestamp. 86 | - `month` (Number) Number month of timestamp. 87 | - `second` (Number) Number second of timestamp. 88 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 89 | - `year` (Number) Number year of timestamp. 90 | 91 | 92 | ## Import 93 | 94 | This resource can be imported using the UTC RFC3339 value, e.g. 95 | 96 | ```shell 97 | terraform import time_static.example 2020-02-12T06:36:13Z 98 | ``` 99 | 100 | The `triggers` argument cannot be imported. 101 | -------------------------------------------------------------------------------- /docs/functions/duration_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "duration_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse a Go duration string https://pkg.go.dev/time#ParseDuration into an object 6 | --- 7 | 8 | # function: duration_parse 9 | 10 | Given a [Go duration string](https://pkg.go.dev/time#ParseDuration), will parse and return an object representation of that duration. 11 | 12 | ## Example Usage 13 | 14 | ```terraform 15 | # Configuration using provider functions must include required_providers configuration. 16 | terraform { 17 | required_providers { 18 | time = { 19 | source = "hashicorp/time" 20 | # Setting the provider version is a strongly recommended practice 21 | # version = "..." 22 | } 23 | } 24 | # Provider functions require Terraform 1.8 and later. 25 | required_version = ">= 1.8.0" 26 | } 27 | 28 | output "example_output" { 29 | value = provider::time::duration_parse("1h") 30 | } 31 | ``` 32 | 33 | ## Signature 34 | 35 | 36 | ```text 37 | duration_parse(duration string) object 38 | ``` 39 | 40 | ## Arguments 41 | 42 | 43 | 1. `duration` (String) Go time package duration string to parse 44 | 45 | 46 | ## Return Type 47 | 48 | The `object` returned from `duration_parse` has the following attributes: 49 | - `hours` (Number) The duration as a floating point number of hours. 50 | - `minutes` (Number) The duration as a floating point number of minutes. 51 | - `seconds` (Number) The duration as a floating point number of seconds. 52 | - `milliseconds` (Number) The duration as an integer number of milliseconds. 53 | - `microseconds` (Number) The duration as an integer number of microseconds. 54 | - `nanoseconds` (Number) The duration as an integer number of nanoseconds. 55 | -------------------------------------------------------------------------------- /docs/functions/rfc3339_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "rfc3339_parse function - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Parse an RFC3339 timestamp string into an object 6 | --- 7 | 8 | # function: rfc3339_parse 9 | 10 | Given an RFC3339 timestamp string, will parse and return an object representation of that date and time. 11 | 12 | ## Example Usage 13 | 14 | ```terraform 15 | # Configuration using provider functions must include required_providers configuration. 16 | terraform { 17 | required_providers { 18 | time = { 19 | source = "hashicorp/time" 20 | # Setting the provider version is a strongly recommended practice 21 | # version = "..." 22 | } 23 | } 24 | # Provider functions require Terraform 1.8 and later. 25 | required_version = ">= 1.8.0" 26 | } 27 | 28 | output "example_output" { 29 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z") 30 | } 31 | ``` 32 | 33 | ## Signature 34 | 35 | 36 | ```text 37 | rfc3339_parse(timestamp string) object 38 | ``` 39 | 40 | ## Arguments 41 | 42 | 43 | 1. `timestamp` (String) RFC3339 timestamp string to parse 44 | 45 | 46 | ## Return Type 47 | 48 | The `object` returned from `rfc3339_parse` has the following attributes: 49 | - `year` (Number) The year for the timestamp. 50 | - `year_day` (Number) The day of the year for the timestamp, in the range [1, 365] for non-leap years, and [1, 366] in leap years. 51 | - `day` (Number) The day of the month for the timestamp. 52 | - `month` (Number) The month of the year for the timestamp. 53 | - `month_name` (String) The name of the month for the timestamp (ex. "January"). 54 | - `weekday` (Number) The day of the week for the timestamp. 55 | - `weekday_name` (String) The name of the day for the timestamp (ex. "Sunday"). 56 | - `hour` (Number) The hour within the day for the timestamp, in the range [0, 23]. 57 | - `minute` (Number) The minute offset within the hour for the timestamp, in the range [0, 59]. 58 | - `second` (Number) The second offset within the minute for the timestamp, in the range [0, 59]. 59 | - `unix` (Number) The number of seconds elapsed since January 1, 1970 UTC. 60 | - `iso_year` (Number) The ISO 8601 year number. 61 | - `iso_week` (Number) The ISO 8601 week number. 62 | -------------------------------------------------------------------------------- /docs/functions/unix_timestamp_parse.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "unix_timestamp_parse function - terraform-provider-time" 4 | subcategory: "" 5 | description: |- 6 | Parse a unix timestamp integer into an object 7 | --- 8 | 9 | # function: unix_timestamp_parse 10 | 11 | Given a unix timestamp integer, will parse and return an object representation of that date and time. A unix timestamp is the number of seconds elapsed since January 1, 1970 UTC. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | output "test" { 17 | value = provider::time::unix_timestamp_parse(1606105443) 18 | } 19 | ``` 20 | 21 | ## Signature 22 | 23 | 24 | ```text 25 | unix_timestamp_parse(unix_timestamp number) object 26 | ``` 27 | 28 | ## Arguments 29 | 30 | 31 | 1. `unix_timestamp` (Number) Unix Timestamp integer to parse 32 | 33 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: Time" 3 | description: |- 4 | The time provider is used to interact with time-based resources. 5 | --- 6 | 7 | # Time Provider 8 | 9 | The time provider is used to interact with time-based resources. The provider itself has no configuration options. 10 | 11 | Use the navigation to the left to read about the available resources. 12 | 13 | ## Resource "Triggers" 14 | 15 | Certain time resources, only perform actions during specific lifecycle actions: 16 | 17 | - `time_offset`: Saves base timestamp into Terraform state only when created. 18 | - `time_sleep`: Sleeps when created and/or destroyed. 19 | - `time_static`: Saves base timestamp into Terraform state only when created. 20 | 21 | These resources provide an optional map argument called `triggers` that can be populated with arbitrary key/value pairs. When the keys or values of this argument are updated, Terraform will re-perform the desired action, such as updating the base timestamp or sleeping again. 22 | 23 | For example: 24 | 25 | ```terraform 26 | resource "time_static" "ami_update" { 27 | triggers = { 28 | # Save the time each switch of an AMI id 29 | ami_id = data.aws_ami.example.id 30 | } 31 | } 32 | 33 | resource "aws_instance" "server" { 34 | # Read the AMI id "through" the time_static resource to ensure that 35 | # both will change together. 36 | ami = time_static.ami_update.triggers.ami_id 37 | 38 | tags = { 39 | AmiUpdateTime = time_static.ami_update.rfc3339 40 | } 41 | 42 | # ... (other aws_instance arguments) ... 43 | } 44 | ``` 45 | 46 | `triggers` are *not* treated as sensitive attributes; a value used for `triggers` will be displayed in Terraform UI output as plaintext. 47 | 48 | To force a these actions to reoccur without updating `triggers`, the [`terraform taint` command](https://www.terraform.io/docs/commands/taint.html) can be used to produce the action on the next run. 49 | -------------------------------------------------------------------------------- /docs/resources/offset.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_offset Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | # time_offset (Resource) 9 | 10 | Manages an offset time resource, which keeps an UTC timestamp stored in the Terraform state that is offset from a locally sourced base timestamp. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | ```terraform 19 | resource "time_offset" "example" { 20 | offset_days = 7 21 | } 22 | 23 | output "one_week_from_now" { 24 | value = time_offset.example.rfc3339 25 | } 26 | ``` 27 | 28 | ### Multiple Offsets Usage 29 | 30 | ```terraform 31 | resource "time_offset" "example" { 32 | offset_years = 1 33 | offset_months = 1 34 | } 35 | 36 | output "one_year_and_month_from_now" { 37 | value = time_offset.example.rfc3339 38 | } 39 | ``` 40 | 41 | ### Triggers Usage 42 | 43 | ```terraform 44 | resource "time_offset" "ami_update" { 45 | triggers = { 46 | # Save the time each switch of an AMI id 47 | ami_id = data.aws_ami.example.id 48 | } 49 | 50 | offset_days = 7 51 | } 52 | 53 | resource "aws_instance" "server" { 54 | # Read the AMI id "through" the time_offset resource to ensure that 55 | # both will change together. 56 | ami = time_offset.ami_update.triggers.ami_id 57 | 58 | tags = { 59 | ExpirationTime = time_offset.ami_update.rfc3339 60 | } 61 | 62 | # ... (other aws_instance arguments) ... 63 | } 64 | ``` 65 | 66 | 67 | ## Schema 68 | 69 | ### Optional 70 | 71 | - `base_rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 72 | - `offset_days` (Number) Number of days to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 73 | - `offset_hours` (Number) Number of hours to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 74 | - `offset_minutes` (Number) Number of minutes to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 75 | - `offset_months` (Number) Number of months to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 76 | - `offset_seconds` (Number) Number of seconds to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 77 | - `offset_years` (Number) Number of years to offset the base timestamp. At least one of the 'offset_' arguments must be configured. 78 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 79 | 80 | ### Read-Only 81 | 82 | - `day` (Number) Number day of offset timestamp. 83 | - `hour` (Number) Number hour of offset timestamp. 84 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 85 | - `minute` (Number) Number minute of offset timestamp. 86 | - `month` (Number) Number month of offset timestamp. 87 | - `rfc3339` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 88 | - `second` (Number) Number second of offset timestamp. 89 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 90 | - `year` (Number) Number year of offset timestamp. 91 | 92 | ## Import 93 | 94 | This resource can be imported using the base UTC RFC3339 timestamp and offset years, months, days, hours, minutes, and seconds, separated by commas (`,`), e.g. 95 | 96 | ```shell 97 | terraform import time_offset.example 2020-02-12T06:36:13Z,0,0,7,0,0,0 98 | ``` 99 | 100 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /docs/resources/rotating.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_rotating Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html by only forcing a new value on the set cadence. 6 | --- 7 | 8 | # time_rotating (Resource) 9 | 10 | Manages a rotating time resource, which keeps a rotating UTC timestamp stored in the Terraform state and proposes resource recreation when the locally sourced current time is beyond the rotation time. This rotation only occurs when Terraform is executed, meaning there will be drift between the rotation timestamp and actual rotation. The new rotation timestamp offset includes this drift. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html) by only forcing a new value on the set cadence. 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | ```terraform 19 | resource "time_rotating" "example" { 20 | rotation_days = 30 21 | } 22 | ``` 23 | 24 | 25 | ## Schema 26 | 27 | ### Optional 28 | 29 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 30 | - `rotation_days` (Number) Number of days to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 31 | - `rotation_hours` (Number) Number of hours to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 32 | - `rotation_minutes` (Number) Number of minutes to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 33 | - `rotation_months` (Number) Number of months to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 34 | - `rotation_rfc3339` (String) Configure the rotation timestamp with an [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format of the offset timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 35 | - `rotation_years` (Number) Number of years to add to the base timestamp to configure the rotation timestamp. When the current time has passed the rotation timestamp, the resource will trigger recreation. At least one of the 'rotation_' arguments must be configured. 36 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. These conditions recreate the resource in addition to other rotation arguments. See [the main provider documentation](../index.md) for more information. 37 | 38 | ### Read-Only 39 | 40 | - `day` (Number) Number day of timestamp. 41 | - `hour` (Number) Number hour of timestamp. 42 | - `id` (String) RFC3339 format of the timestamp, e.g. `2020-02-12T06:36:13Z`. 43 | - `minute` (Number) Number minute of timestamp. 44 | - `month` (Number) Number month of timestamp. 45 | - `second` (Number) Number second of timestamp. 46 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 47 | - `year` (Number) Number year of timestamp. 48 | 49 | ## Import 50 | 51 | This resource can be imported using the base UTC RFC3339 value and rotation years, months, days, hours, and minutes, separated by commas (`,`), e.g. for 30 days 52 | 53 | ```shell 54 | terraform import time_rotating.example 2020-02-12T06:36:13Z,0,0,30,0,0 55 | ``` 56 | 57 | Otherwise, to import with the rotation RFC3339 value, the base UTC RFC3339 value and rotation UTC RFC3339 value, separated by commas (`,`), e.g. 58 | 59 | ```shell 60 | terraform import time_rotating.example 2020-02-12T06:36:13Z,2020-02-13T06:36:13Z 61 | ``` 62 | 63 | The `triggers` argument cannot be imported. 64 | -------------------------------------------------------------------------------- /docs/resources/sleep.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_sleep Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the local-exec provisioner https://www.terraform.io/docs/provisioners/local-exec.html. 6 | --- 7 | 8 | # time_sleep (Resource) 9 | 10 | Manages a resource that delays creation and/or destruction, typically for further resources. This prevents cross-platform compatibility and destroy-time issues with using the [`local-exec` provisioner](https://www.terraform.io/docs/provisioners/local-exec.html). 11 | 12 | -> In many cases, this resource should be considered a workaround for issues that should be reported and handled in downstream Terraform Provider logic. Downstream resources can usually introduce or adjust retries in their code to handle time delay issues for all Terraform configurations or upstream resources can be improved to better wait for a resource to be fully ready and available. 13 | 14 | ## Example Usage 15 | 16 | ### Delay Create Usage 17 | 18 | ```terraform 19 | # This resource will destroy (potentially immediately) after null_resource.next 20 | resource "null_resource" "previous" {} 21 | 22 | resource "time_sleep" "wait_30_seconds" { 23 | depends_on = [null_resource.previous] 24 | 25 | create_duration = "30s" 26 | } 27 | 28 | # This resource will create (at least) 30 seconds after null_resource.previous 29 | resource "null_resource" "next" { 30 | depends_on = [time_sleep.wait_30_seconds] 31 | } 32 | ``` 33 | 34 | ### Delay Destroy Usage 35 | 36 | ```terraform 37 | # This resource will destroy (at least) 30 seconds after null_resource.next 38 | resource "null_resource" "previous" {} 39 | 40 | resource "time_sleep" "wait_30_seconds" { 41 | depends_on = [null_resource.previous] 42 | 43 | destroy_duration = "30s" 44 | } 45 | 46 | # This resource will create (potentially immediately) after null_resource.previous 47 | resource "null_resource" "next" { 48 | depends_on = [time_sleep.wait_30_seconds] 49 | } 50 | ``` 51 | 52 | ### Triggers Usage 53 | 54 | ```terraform 55 | resource "aws_ram_resource_association" "example" { 56 | resource_arn = aws_subnet.example.arn 57 | resource_share_arn = aws_ram_resource_share.example.arn 58 | } 59 | 60 | # AWS resources shared via Resource Access Manager can take a few seconds to 61 | # propagate across AWS accounts after RAM returns a successful association. 62 | resource "time_sleep" "ram_resource_propagation" { 63 | create_duration = "60s" 64 | 65 | triggers = { 66 | # This sets up a proper dependency on the RAM association 67 | subnet_arn = aws_ram_resource_association.example.resource_arn 68 | subnet_id = aws_subnet.example.id 69 | } 70 | } 71 | 72 | resource "aws_db_subnet_group" "example" { 73 | name = "example" 74 | 75 | # Read the Subnet identifier "through" the time_sleep resource to ensure a 76 | # proper dependency and that both will change together. 77 | subnet_ids = [time_sleep.ram_resource_propagation.triggers["subnet_id"]] 78 | } 79 | ``` 80 | 81 | 82 | ## Schema 83 | 84 | ### Optional 85 | 86 | - `create_duration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource creation. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. 87 | - `destroy_duration` (String) [Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource destroy. For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. This value or any updates to it must be successfully applied into the Terraform state before destroying this resource to take effect. 88 | - `triggers` (Map of String) (Optional) Arbitrary map of values that, when changed, will run any creation or destroy delays again. See [the main provider documentation](../index.md) for more information. 89 | 90 | ### Read-Only 91 | 92 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 93 | 94 | ## Import 95 | 96 | This resource can be imported with the `create_duration` and `destroy_duration`, separated by a comma (`,`). 97 | 98 | e.g. For 30 seconds create duration with no destroy duration: 99 | 100 | ```shell 101 | terraform import time_sleep.example 30s, 102 | ``` 103 | 104 | e.g. For 30 seconds destroy duration with no create duration: 105 | 106 | ```shell 107 | terraform import time_sleep.example ,30s 108 | ``` 109 | 110 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /docs/resources/static.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "time_static Resource - terraform-provider-time" 3 | subcategory: "" 4 | description: |- 5 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the timestamp() function https://www.terraform.io/docs/configuration/functions/timestamp.html. 6 | --- 7 | 8 | # time_static (Resource) 9 | 10 | Manages a static time resource, which keeps a locally sourced UTC timestamp stored in the Terraform state. This prevents perpetual differences caused by using the [`timestamp()` function](https://www.terraform.io/docs/configuration/functions/timestamp.html). 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | ```terraform 19 | resource "time_static" "example" {} 20 | 21 | output "current_time" { 22 | value = time_static.example.rfc3339 23 | } 24 | ``` 25 | 26 | ### Triggers Usage 27 | 28 | ```terraform 29 | resource "time_static" "ami_update" { 30 | triggers = { 31 | # Save the time each switch of an AMI id 32 | ami_id = data.aws_ami.example.id 33 | } 34 | } 35 | 36 | resource "aws_instance" "server" { 37 | # Read the AMI id "through" the time_static resource to ensure that 38 | # both will change together. 39 | ami = time_static.ami_update.triggers.ami_id 40 | 41 | tags = { 42 | AmiUpdateTime = time_static.ami_update.rfc3339 43 | } 44 | 45 | # ... (other aws_instance arguments) ... 46 | } 47 | ``` 48 | 49 | 50 | ## Schema 51 | 52 | ### Optional 53 | 54 | - `rfc3339` (String) Base timestamp in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.8) format (see [RFC3339 time string](https://tools.ietf.org/html/rfc3339#section-5.8) e.g., `YYYY-MM-DDTHH:MM:SSZ`). Defaults to the current time. 55 | - `triggers` (Map of String) Arbitrary map of values that, when changed, will trigger a new base timestamp value to be saved. See [the main provider documentation](../index.md) for more information. 56 | 57 | ### Read-Only 58 | 59 | - `day` (Number) Number day of timestamp. 60 | - `hour` (Number) Number hour of timestamp. 61 | - `id` (String) RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`. 62 | - `minute` (Number) Number minute of timestamp. 63 | - `month` (Number) Number month of timestamp. 64 | - `second` (Number) Number second of timestamp. 65 | - `unix` (Number) Number of seconds since epoch time, e.g. `1581489373`. 66 | - `year` (Number) Number year of timestamp. 67 | 68 | 69 | ## Import 70 | 71 | This resource can be imported using the UTC RFC3339 value, e.g. 72 | 73 | ```shell 74 | terraform import time_static.example 2020-02-12T06:36:13Z 75 | ``` 76 | 77 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /examples/functions/duration_parse/function.tf: -------------------------------------------------------------------------------- 1 | # Configuration using provider functions must include required_providers configuration. 2 | terraform { 3 | required_providers { 4 | time = { 5 | source = "hashicorp/time" 6 | # Setting the provider version is a strongly recommended practice 7 | # version = "..." 8 | } 9 | } 10 | # Provider functions require Terraform 1.8 and later. 11 | required_version = ">= 1.8.0" 12 | } 13 | 14 | output "example_output" { 15 | value = provider::time::duration_parse("1h") 16 | } 17 | -------------------------------------------------------------------------------- /examples/functions/rfc3339_parse/function.tf: -------------------------------------------------------------------------------- 1 | # Configuration using provider functions must include required_providers configuration. 2 | terraform { 3 | required_providers { 4 | time = { 5 | source = "hashicorp/time" 6 | # Setting the provider version is a strongly recommended practice 7 | # version = "..." 8 | } 9 | } 10 | # Provider functions require Terraform 1.8 and later. 11 | required_version = ">= 1.8.0" 12 | } 13 | 14 | output "example_output" { 15 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z") 16 | } 17 | -------------------------------------------------------------------------------- /examples/functions/unix_timestamp_parse/function.tf: -------------------------------------------------------------------------------- 1 | output "test" { 2 | value = provider::time::unix_timestamp_parse(1606105443) 3 | } 4 | -------------------------------------------------------------------------------- /examples/resources/resource_triggers.tf: -------------------------------------------------------------------------------- 1 | resource "time_static" "ami_update" { 2 | triggers = { 3 | # Save the time each switch of an AMI id 4 | ami_id = data.aws_ami.example.id 5 | } 6 | } 7 | 8 | resource "aws_instance" "server" { 9 | # Read the AMI id "through" the time_static resource to ensure that 10 | # both will change together. 11 | ami = time_static.ami_update.triggers.ami_id 12 | 13 | tags = { 14 | AmiUpdateTime = time_static.ami_update.rfc3339 15 | } 16 | 17 | # ... (other aws_instance arguments) ... 18 | } -------------------------------------------------------------------------------- /examples/resources/time_offset/import.sh: -------------------------------------------------------------------------------- 1 | terraform import time_offset.example 2020-02-12T06:36:13Z,0,0,7,0,0,0 -------------------------------------------------------------------------------- /examples/resources/time_offset/resource.tf: -------------------------------------------------------------------------------- 1 | resource "time_offset" "example" { 2 | offset_days = 7 3 | } 4 | 5 | output "one_week_from_now" { 6 | value = time_offset.example.rfc3339 7 | } -------------------------------------------------------------------------------- /examples/resources/time_offset/resource_multiple_offset.tf: -------------------------------------------------------------------------------- 1 | resource "time_offset" "example" { 2 | offset_years = 1 3 | offset_months = 1 4 | } 5 | 6 | output "one_year_and_month_from_now" { 7 | value = time_offset.example.rfc3339 8 | } -------------------------------------------------------------------------------- /examples/resources/time_offset/resource_triggers.tf: -------------------------------------------------------------------------------- 1 | resource "time_offset" "ami_update" { 2 | triggers = { 3 | # Save the time each switch of an AMI id 4 | ami_id = data.aws_ami.example.id 5 | } 6 | 7 | offset_days = 7 8 | } 9 | 10 | resource "aws_instance" "server" { 11 | # Read the AMI id "through" the time_offset resource to ensure that 12 | # both will change together. 13 | ami = time_offset.ami_update.triggers.ami_id 14 | 15 | tags = { 16 | ExpirationTime = time_offset.ami_update.rfc3339 17 | } 18 | 19 | # ... (other aws_instance arguments) ... 20 | } -------------------------------------------------------------------------------- /examples/resources/time_rotating/import_base_value.sh: -------------------------------------------------------------------------------- 1 | terraform import time_rotating.example 2020-02-12T06:36:13Z,0,0,30,0,0 2 | -------------------------------------------------------------------------------- /examples/resources/time_rotating/import_rotation_value.sh: -------------------------------------------------------------------------------- 1 | terraform import time_rotating.example 2020-02-12T06:36:13Z,2020-02-13T06:36:13Z 2 | -------------------------------------------------------------------------------- /examples/resources/time_rotating/resource.tf: -------------------------------------------------------------------------------- 1 | resource "time_rotating" "example" { 2 | rotation_days = 30 3 | } -------------------------------------------------------------------------------- /examples/resources/time_sleep/import_create.sh: -------------------------------------------------------------------------------- 1 | terraform import time_sleep.example 30s, -------------------------------------------------------------------------------- /examples/resources/time_sleep/import_destroy.sh: -------------------------------------------------------------------------------- 1 | terraform import time_sleep.example ,30s -------------------------------------------------------------------------------- /examples/resources/time_sleep/resource_delay_create.tf: -------------------------------------------------------------------------------- 1 | # This resource will destroy (potentially immediately) after null_resource.next 2 | resource "null_resource" "previous" {} 3 | 4 | resource "time_sleep" "wait_30_seconds" { 5 | depends_on = [null_resource.previous] 6 | 7 | create_duration = "30s" 8 | } 9 | 10 | # This resource will create (at least) 30 seconds after null_resource.previous 11 | resource "null_resource" "next" { 12 | depends_on = [time_sleep.wait_30_seconds] 13 | } -------------------------------------------------------------------------------- /examples/resources/time_sleep/resource_delay_destroy.tf: -------------------------------------------------------------------------------- 1 | # This resource will destroy (at least) 30 seconds after null_resource.next 2 | resource "null_resource" "previous" {} 3 | 4 | resource "time_sleep" "wait_30_seconds" { 5 | depends_on = [null_resource.previous] 6 | 7 | destroy_duration = "30s" 8 | } 9 | 10 | # This resource will create (potentially immediately) after null_resource.previous 11 | resource "null_resource" "next" { 12 | depends_on = [time_sleep.wait_30_seconds] 13 | } -------------------------------------------------------------------------------- /examples/resources/time_sleep/resource_triggers.tf: -------------------------------------------------------------------------------- 1 | resource "aws_ram_resource_association" "example" { 2 | resource_arn = aws_subnet.example.arn 3 | resource_share_arn = aws_ram_resource_share.example.arn 4 | } 5 | 6 | # AWS resources shared via Resource Access Manager can take a few seconds to 7 | # propagate across AWS accounts after RAM returns a successful association. 8 | resource "time_sleep" "ram_resource_propagation" { 9 | create_duration = "60s" 10 | 11 | triggers = { 12 | # This sets up a proper dependency on the RAM association 13 | subnet_arn = aws_ram_resource_association.example.resource_arn 14 | subnet_id = aws_subnet.example.id 15 | } 16 | } 17 | 18 | resource "aws_db_subnet_group" "example" { 19 | name = "example" 20 | 21 | # Read the Subnet identifier "through" the time_sleep resource to ensure a 22 | # proper dependency and that both will change together. 23 | subnet_ids = [time_sleep.ram_resource_propagation.triggers["subnet_id"]] 24 | } -------------------------------------------------------------------------------- /examples/resources/time_static/import.sh: -------------------------------------------------------------------------------- 1 | terraform import time_static.example 2020-02-12T06:36:13Z -------------------------------------------------------------------------------- /examples/resources/time_static/resource.tf: -------------------------------------------------------------------------------- 1 | resource "time_static" "example" {} 2 | 3 | output "current_time" { 4 | value = time_static.example.rfc3339 5 | } -------------------------------------------------------------------------------- /examples/resources/time_static/resource_triggers.tf: -------------------------------------------------------------------------------- 1 | resource "time_static" "ami_update" { 2 | triggers = { 3 | # Save the time each switch of an AMI id 4 | ami_id = data.aws_ami.example.id 5 | } 6 | } 7 | 8 | resource "aws_instance" "server" { 9 | # Read the AMI id "through" the time_static resource to ensure that 10 | # both will change together. 11 | ami = time_static.ami_update.triggers.ami_id 12 | 13 | tags = { 14 | AmiUpdateTime = time_static.ami_update.rfc3339 15 | } 16 | 17 | # ... (other aws_instance arguments) ... 18 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hashicorp/terraform-provider-time 2 | 3 | go 1.23.7 4 | 5 | require ( 6 | github.com/google/go-cmp v0.7.0 7 | github.com/hashicorp/terraform-plugin-framework v1.15.0 8 | github.com/hashicorp/terraform-plugin-framework-timetypes v0.5.0 9 | github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 10 | github.com/hashicorp/terraform-plugin-go v0.28.0 11 | github.com/hashicorp/terraform-plugin-log v0.9.0 12 | github.com/hashicorp/terraform-plugin-testing v1.13.1 13 | ) 14 | 15 | require ( 16 | github.com/ProtonMail/go-crypto v1.1.6 // indirect 17 | github.com/agext/levenshtein v1.2.2 // indirect 18 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 19 | github.com/cloudflare/circl v1.6.0 // indirect 20 | github.com/fatih/color v1.16.0 // indirect 21 | github.com/golang/protobuf v1.5.4 // indirect 22 | github.com/hashicorp/errwrap v1.1.0 // indirect 23 | github.com/hashicorp/go-checkpoint v0.5.0 // indirect 24 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 25 | github.com/hashicorp/go-cty v1.5.0 // indirect 26 | github.com/hashicorp/go-hclog v1.6.3 // indirect 27 | github.com/hashicorp/go-multierror v1.1.1 // indirect 28 | github.com/hashicorp/go-plugin v1.6.3 // indirect 29 | github.com/hashicorp/go-retryablehttp v0.7.7 // indirect 30 | github.com/hashicorp/go-uuid v1.0.3 // indirect 31 | github.com/hashicorp/go-version v1.7.0 // indirect 32 | github.com/hashicorp/hc-install v0.9.2 // indirect 33 | github.com/hashicorp/hcl/v2 v2.23.0 // indirect 34 | github.com/hashicorp/logutils v1.0.0 // indirect 35 | github.com/hashicorp/terraform-exec v0.23.0 // indirect 36 | github.com/hashicorp/terraform-json v0.25.0 // indirect 37 | github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 // indirect 38 | github.com/hashicorp/terraform-registry-address v0.2.5 // indirect 39 | github.com/hashicorp/terraform-svchost v0.1.1 // indirect 40 | github.com/hashicorp/yamux v0.1.1 // indirect 41 | github.com/kr/pretty v0.3.0 // indirect 42 | github.com/mattn/go-colorable v0.1.13 // indirect 43 | github.com/mattn/go-isatty v0.0.20 // indirect 44 | github.com/mitchellh/copystructure v1.2.0 // indirect 45 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 46 | github.com/mitchellh/go-wordwrap v1.0.0 // indirect 47 | github.com/mitchellh/mapstructure v1.5.0 // indirect 48 | github.com/mitchellh/reflectwalk v1.0.2 // indirect 49 | github.com/oklog/run v1.0.0 // indirect 50 | github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect 51 | github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect 52 | github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect 53 | github.com/zclconf/go-cty v1.16.2 // indirect 54 | golang.org/x/crypto v0.38.0 // indirect 55 | golang.org/x/mod v0.24.0 // indirect 56 | golang.org/x/net v0.39.0 // indirect 57 | golang.org/x/sync v0.14.0 // indirect 58 | golang.org/x/sys v0.33.0 // indirect 59 | golang.org/x/text v0.25.0 // indirect 60 | golang.org/x/tools v0.22.0 // indirect 61 | google.golang.org/appengine v1.6.8 // indirect 62 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect 63 | google.golang.org/grpc v1.72.1 // indirect 64 | google.golang.org/protobuf v1.36.6 // indirect 65 | ) 66 | -------------------------------------------------------------------------------- /internal/clock/clock.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package clock 5 | 6 | import ( 7 | "time" 8 | ) 9 | 10 | type Clock interface { 11 | Now() time.Time 12 | } 13 | 14 | type realClock struct{} 15 | 16 | func NewClock() Clock { 17 | return &realClock{} 18 | } 19 | 20 | func (clock *realClock) Now() time.Time { 21 | return time.Now() 22 | } 23 | -------------------------------------------------------------------------------- /internal/modifiers/timemodifier/replace_if_outdated.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package timemodifier 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" 12 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" 13 | ) 14 | 15 | func ReplaceIfOutdated(ctx context.Context, req planmodifier.StringRequest, resp *stringplanmodifier.RequiresReplaceIfFuncResponse) { 16 | if req.State.Raw.IsNull() { 17 | // if we're creating the resource, no need to delete and 18 | // recreate it 19 | return 20 | } 21 | 22 | if req.Plan.Raw.IsNull() { 23 | // if we're deleting the resource, no need to delete and 24 | // recreate it 25 | return 26 | } 27 | 28 | rotationTimestamp, err := time.Parse(time.RFC3339, req.StateValue.ValueString()) 29 | if err != nil { 30 | resp.Diagnostics.AddError( 31 | "replaceIfOutdated plan modifier error", 32 | "The rotation rfc3339 timestamp that was supplied could not be parsed as RFC3339.\n\n+"+ 33 | fmt.Sprintf("Original Error: %s", err), 34 | ) 35 | return 36 | } 37 | 38 | now := time.Now().UTC() 39 | 40 | resp.RequiresReplace = now.After(rotationTimestamp) 41 | } 42 | -------------------------------------------------------------------------------- /internal/provider/function_duration_parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-framework/attr" 12 | "github.com/hashicorp/terraform-plugin-framework/function" 13 | "github.com/hashicorp/terraform-plugin-framework/types" 14 | "github.com/hashicorp/terraform-plugin-log/tflog" 15 | ) 16 | 17 | var durationParseReturnAttrTypes = map[string]attr.Type{ 18 | "hours": types.Float64Type, 19 | "minutes": types.Float64Type, 20 | "seconds": types.Float64Type, 21 | "milliseconds": types.Int64Type, 22 | "microseconds": types.Int64Type, 23 | "nanoseconds": types.Int64Type, 24 | } 25 | 26 | var _ function.Function = &DurationParseFunction{} 27 | 28 | type DurationParseFunction struct{} 29 | 30 | func NewDurationParseFunction() function.Function { 31 | return &DurationParseFunction{} 32 | } 33 | 34 | func (f *DurationParseFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 35 | resp.Name = "duration_parse" 36 | } 37 | 38 | func (f *DurationParseFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 39 | resp.Definition = function.Definition{ 40 | Summary: "Parse a [Go duration string](https://pkg.go.dev/time#ParseDuration) into an object", 41 | Description: "Given a [Go duration string](https://pkg.go.dev/time#ParseDuration), will parse and return an object representation of that duration.", 42 | 43 | Parameters: []function.Parameter{ 44 | function.StringParameter{ 45 | Name: "duration", 46 | Description: "Go time package duration string to parse", 47 | }, 48 | }, 49 | Return: function.ObjectReturn{ 50 | AttributeTypes: durationParseReturnAttrTypes, 51 | }, 52 | } 53 | } 54 | 55 | func (f *DurationParseFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 56 | var input string 57 | 58 | resp.Error = req.Arguments.Get(ctx, &input) 59 | if resp.Error != nil { 60 | return 61 | } 62 | 63 | duration, err := time.ParseDuration(input) 64 | if err != nil { 65 | // Intentionally not including the Go parse error in the return diagnostic, as the message is based on a Go-specific 66 | // reference time that may be unfamiliar to practitioners 67 | tflog.Error(ctx, fmt.Sprintf("failed to parse duration string, underlying time.Duration error: %s", err.Error())) 68 | 69 | resp.Error = function.NewArgumentFuncError(0, fmt.Sprintf("Error parsing duration string: %q is not a valid duration string", input)) 70 | return 71 | } 72 | 73 | durationObj, diags := types.ObjectValue( 74 | durationParseReturnAttrTypes, 75 | map[string]attr.Value{ 76 | "hours": types.Float64Value(duration.Hours()), 77 | "minutes": types.Float64Value(duration.Minutes()), 78 | "seconds": types.Float64Value(duration.Seconds()), 79 | "milliseconds": types.Int64Value(duration.Milliseconds()), 80 | "microseconds": types.Int64Value(duration.Microseconds()), 81 | "nanoseconds": types.Int64Value(duration.Nanoseconds()), 82 | }, 83 | ) 84 | 85 | resp.Error = function.FuncErrorFromDiags(ctx, diags) 86 | if resp.Error != nil { 87 | return 88 | } 89 | 90 | resp.Error = resp.Result.Set(ctx, &durationObj) 91 | } 92 | -------------------------------------------------------------------------------- /internal/provider/function_duration_parse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func TestDurationParse_valid(t *testing.T) { 17 | resource.UnitTest(t, resource.TestCase{ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_8_0), 20 | }, 21 | ProtoV5ProviderFactories: protoV5ProviderFactories(), 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: ` 25 | output "test" { 26 | value = provider::time::duration_parse("1h") 27 | } 28 | `, 29 | ConfigPlanChecks: resource.ConfigPlanChecks{ 30 | PreApply: []plancheck.PlanCheck{ 31 | plancheck.ExpectKnownOutputValue("test", knownvalue.ObjectExact( 32 | map[string]knownvalue.Check{ 33 | "hours": knownvalue.Float64Exact(1), 34 | "minutes": knownvalue.Float64Exact(60), 35 | "seconds": knownvalue.Float64Exact(3600), 36 | "milliseconds": knownvalue.Int64Exact(3600000), 37 | "microseconds": knownvalue.Int64Exact(3600000000), 38 | "nanoseconds": knownvalue.Int64Exact(3600000000000), 39 | }, 40 | )), 41 | }, 42 | }, 43 | }, 44 | { 45 | Config: ` 46 | output "test" { 47 | value = provider::time::duration_parse("60m") 48 | } 49 | `, 50 | ConfigPlanChecks: resource.ConfigPlanChecks{ 51 | PreApply: []plancheck.PlanCheck{ 52 | plancheck.ExpectEmptyPlan(), 53 | }, 54 | }, 55 | }, 56 | { 57 | Config: ` 58 | output "test" { 59 | value = provider::time::duration_parse("3600s") 60 | } 61 | `, 62 | ConfigPlanChecks: resource.ConfigPlanChecks{ 63 | PreApply: []plancheck.PlanCheck{ 64 | plancheck.ExpectEmptyPlan(), 65 | }, 66 | }, 67 | }, 68 | { 69 | Config: ` 70 | output "test" { 71 | value = provider::time::duration_parse("3600000ms") 72 | } 73 | `, 74 | ConfigPlanChecks: resource.ConfigPlanChecks{ 75 | PreApply: []plancheck.PlanCheck{ 76 | plancheck.ExpectEmptyPlan(), 77 | }, 78 | }, 79 | }, 80 | { 81 | Config: ` 82 | output "test" { 83 | value = provider::time::duration_parse("3600000000us") 84 | } 85 | `, 86 | ConfigPlanChecks: resource.ConfigPlanChecks{ 87 | PreApply: []plancheck.PlanCheck{ 88 | plancheck.ExpectEmptyPlan(), 89 | }, 90 | }, 91 | }, 92 | { 93 | Config: ` 94 | output "test" { 95 | value = provider::time::duration_parse("3600000000000ns") 96 | } 97 | `, 98 | ConfigPlanChecks: resource.ConfigPlanChecks{ 99 | PreApply: []plancheck.PlanCheck{ 100 | plancheck.ExpectEmptyPlan(), 101 | }, 102 | }, 103 | }, 104 | }, 105 | }) 106 | } 107 | 108 | func TestDurationParse_invalid(t *testing.T) { 109 | resource.UnitTest(t, resource.TestCase{ 110 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 111 | tfversion.SkipBelow(tfversion.Version1_8_0), 112 | }, 113 | ProtoV5ProviderFactories: protoV5ProviderFactories(), 114 | Steps: []resource.TestStep{ 115 | { 116 | Config: ` 117 | output "test" { 118 | value = provider::time::duration_parse("abcdef") 119 | } 120 | `, 121 | ExpectError: regexp.MustCompile(`"abcdef" is not a valid duration string.`), 122 | }, 123 | }, 124 | }) 125 | } 126 | -------------------------------------------------------------------------------- /internal/provider/function_rfc3339_parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-framework/attr" 12 | "github.com/hashicorp/terraform-plugin-framework/function" 13 | "github.com/hashicorp/terraform-plugin-framework/types" 14 | "github.com/hashicorp/terraform-plugin-log/tflog" 15 | ) 16 | 17 | var rfc3339ReturnAttrTypes = map[string]attr.Type{ 18 | "year": types.Int64Type, 19 | "year_day": types.Int64Type, 20 | "day": types.Int64Type, 21 | "month": types.Int64Type, 22 | "month_name": types.StringType, 23 | "weekday": types.Int64Type, 24 | "weekday_name": types.StringType, 25 | "hour": types.Int64Type, 26 | "minute": types.Int64Type, 27 | "second": types.Int64Type, 28 | "unix": types.Int64Type, 29 | "iso_year": types.Int64Type, 30 | "iso_week": types.Int64Type, 31 | } 32 | 33 | var _ function.Function = &RFC3339ParseFunction{} 34 | 35 | type RFC3339ParseFunction struct{} 36 | 37 | func NewRFC3339ParseFunction() function.Function { 38 | return &RFC3339ParseFunction{} 39 | } 40 | 41 | func (f *RFC3339ParseFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 42 | resp.Name = "rfc3339_parse" 43 | } 44 | 45 | func (f *RFC3339ParseFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 46 | resp.Definition = function.Definition{ 47 | Summary: "Parse an RFC3339 timestamp string into an object", 48 | Description: "Given an RFC3339 timestamp string, will parse and return an object representation of that date and time.", 49 | 50 | Parameters: []function.Parameter{ 51 | function.StringParameter{ 52 | Name: "timestamp", 53 | Description: "RFC3339 timestamp string to parse", 54 | }, 55 | }, 56 | Return: function.ObjectReturn{ 57 | AttributeTypes: rfc3339ReturnAttrTypes, 58 | }, 59 | } 60 | } 61 | 62 | func (f *RFC3339ParseFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 63 | var timestamp string 64 | 65 | resp.Error = req.Arguments.Get(ctx, ×tamp) 66 | if resp.Error != nil { 67 | return 68 | } 69 | 70 | rfc3339, err := time.Parse(time.RFC3339, timestamp) 71 | if err != nil { 72 | // Intentionally not including the Go parse error in the return diagnostic, as the message is based on a Go-specific 73 | // reference time that may be unfamiliar to practitioners 74 | tflog.Error(ctx, fmt.Sprintf("failed to parse RFC3339 timestamp, underlying time.Time error: %s", err.Error())) 75 | 76 | resp.Error = function.NewArgumentFuncError(0, fmt.Sprintf("Error parsing RFC3339 timestamp: %q is not a valid RFC3339 timestamp", timestamp)) 77 | return 78 | } 79 | 80 | isoYear, isoWeek := rfc3339.ISOWeek() 81 | 82 | rfc3339Obj, diags := types.ObjectValue( 83 | rfc3339ReturnAttrTypes, 84 | map[string]attr.Value{ 85 | "year": types.Int64Value(int64(rfc3339.Year())), 86 | "year_day": types.Int64Value(int64(rfc3339.YearDay())), 87 | "day": types.Int64Value(int64(rfc3339.Day())), 88 | "month": types.Int64Value(int64(rfc3339.Month())), 89 | "month_name": types.StringValue(rfc3339.Month().String()), 90 | "weekday": types.Int64Value(int64(rfc3339.Weekday())), 91 | "weekday_name": types.StringValue(rfc3339.Weekday().String()), 92 | "hour": types.Int64Value(int64(rfc3339.Hour())), 93 | "minute": types.Int64Value(int64(rfc3339.Minute())), 94 | "second": types.Int64Value(int64(rfc3339.Second())), 95 | "unix": types.Int64Value(rfc3339.Unix()), 96 | "iso_year": types.Int64Value(int64(isoYear)), 97 | "iso_week": types.Int64Value(int64(isoWeek)), 98 | }, 99 | ) 100 | 101 | resp.Error = function.FuncErrorFromDiags(ctx, diags) 102 | if resp.Error != nil { 103 | return 104 | } 105 | 106 | resp.Error = resp.Result.Set(ctx, &rfc3339Obj) 107 | } 108 | -------------------------------------------------------------------------------- /internal/provider/function_rfc3339_parse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func TestRFC3339Parse_UTC(t *testing.T) { 17 | resource.UnitTest(t, resource.TestCase{ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_8_0), 20 | }, 21 | ProtoV5ProviderFactories: protoV5ProviderFactories(), 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: ` 25 | output "test" { 26 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16Z") 27 | } 28 | `, 29 | ConfigPlanChecks: resource.ConfigPlanChecks{ 30 | PreApply: []plancheck.PlanCheck{ 31 | plancheck.ExpectKnownOutputValue("test", knownvalue.ObjectExact( 32 | map[string]knownvalue.Check{ 33 | "day": knownvalue.Int64Exact(25), 34 | "hour": knownvalue.Int64Exact(23), 35 | "iso_week": knownvalue.Int64Exact(30), 36 | "iso_year": knownvalue.Int64Exact(2023), 37 | "minute": knownvalue.Int64Exact(43), 38 | "month": knownvalue.Int64Exact(7), 39 | "month_name": knownvalue.StringExact("July"), 40 | "second": knownvalue.Int64Exact(16), 41 | "unix": knownvalue.Int64Exact(1690328596), 42 | "weekday": knownvalue.Int64Exact(2), 43 | "weekday_name": knownvalue.StringExact("Tuesday"), 44 | "year": knownvalue.Int64Exact(2023), 45 | "year_day": knownvalue.Int64Exact(206), 46 | }, 47 | )), 48 | }, 49 | }, 50 | }, 51 | { 52 | Config: ` 53 | output "test" { 54 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16-00:00") 55 | } 56 | `, 57 | ConfigPlanChecks: resource.ConfigPlanChecks{ 58 | PreApply: []plancheck.PlanCheck{ 59 | plancheck.ExpectEmptyPlan(), 60 | }, 61 | }, 62 | }, 63 | { 64 | Config: ` 65 | output "test" { 66 | value = provider::time::rfc3339_parse("2023-07-25T23:43:16+00:00") 67 | } 68 | `, 69 | ConfigPlanChecks: resource.ConfigPlanChecks{ 70 | PreApply: []plancheck.PlanCheck{ 71 | plancheck.ExpectEmptyPlan(), 72 | }, 73 | }, 74 | }, 75 | }, 76 | }) 77 | } 78 | 79 | func TestRFC3339Parse_offset(t *testing.T) { 80 | resource.UnitTest(t, resource.TestCase{ 81 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 82 | tfversion.SkipBelow(tfversion.Version1_8_0), 83 | }, 84 | ProtoV5ProviderFactories: protoV5ProviderFactories(), 85 | Steps: []resource.TestStep{ 86 | { 87 | Config: ` 88 | output "test" { 89 | value = provider::time::rfc3339_parse("1996-12-19T16:39:57-08:00") 90 | } 91 | `, 92 | ConfigPlanChecks: resource.ConfigPlanChecks{ 93 | PreApply: []plancheck.PlanCheck{ 94 | plancheck.ExpectKnownOutputValue("test", knownvalue.ObjectExact( 95 | map[string]knownvalue.Check{ 96 | "day": knownvalue.Int64Exact(19), 97 | "hour": knownvalue.Int64Exact(16), 98 | "iso_week": knownvalue.Int64Exact(51), 99 | "iso_year": knownvalue.Int64Exact(1996), 100 | "minute": knownvalue.Int64Exact(39), 101 | "month": knownvalue.Int64Exact(12), 102 | "month_name": knownvalue.StringExact("December"), 103 | "second": knownvalue.Int64Exact(57), 104 | "unix": knownvalue.Int64Exact(851042397), 105 | "weekday": knownvalue.Int64Exact(4), 106 | "weekday_name": knownvalue.StringExact("Thursday"), 107 | "year": knownvalue.Int64Exact(1996), 108 | "year_day": knownvalue.Int64Exact(354), 109 | }, 110 | )), 111 | }, 112 | }, 113 | }, 114 | }, 115 | }) 116 | } 117 | 118 | func TestRFC3339Parse_invalid(t *testing.T) { 119 | resource.UnitTest(t, resource.TestCase{ 120 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 121 | tfversion.SkipBelow(tfversion.Version1_8_0), 122 | }, 123 | ProtoV5ProviderFactories: protoV5ProviderFactories(), 124 | Steps: []resource.TestStep{ 125 | { 126 | Config: ` 127 | output "test" { 128 | value = provider::time::rfc3339_parse("abcdef") 129 | } 130 | `, 131 | ExpectError: regexp.MustCompile(`"abcdef" is not a valid RFC3339 timestamp.`), 132 | }, 133 | }, 134 | }) 135 | } 136 | -------------------------------------------------------------------------------- /internal/provider/function_unix_timestamp_parse.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | "time" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/attr" 11 | "github.com/hashicorp/terraform-plugin-framework/function" 12 | "github.com/hashicorp/terraform-plugin-framework/types" 13 | ) 14 | 15 | var unixReturnAttrTypes = map[string]attr.Type{ 16 | "year": types.Int64Type, 17 | "year_day": types.Int64Type, 18 | "day": types.Int64Type, 19 | "month": types.Int64Type, 20 | "month_name": types.StringType, 21 | "weekday": types.Int64Type, 22 | "weekday_name": types.StringType, 23 | "hour": types.Int64Type, 24 | "minute": types.Int64Type, 25 | "rfc3339": types.StringType, 26 | "second": types.Int64Type, 27 | "iso_year": types.Int64Type, 28 | "iso_week": types.Int64Type, 29 | } 30 | 31 | var _ function.Function = &UnixTimestampParseFunction{} 32 | 33 | type UnixTimestampParseFunction struct{} 34 | 35 | func (f *UnixTimestampParseFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 36 | resp.Name = "unix_timestamp_parse" 37 | } 38 | 39 | func (f *UnixTimestampParseFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 40 | resp.Definition = function.Definition{ 41 | Summary: "Parse a unix timestamp integer into an object", 42 | MarkdownDescription: "Given a unix timestamp integer, will parse and return an object representation of that date and time. A unix timestamp is the number of seconds elapsed since January 1, 1970 UTC.", 43 | 44 | Parameters: []function.Parameter{ 45 | function.Int64Parameter{ 46 | Name: "unix_timestamp", 47 | MarkdownDescription: "Unix Timestamp integer to parse", 48 | }, 49 | }, 50 | Return: function.ObjectReturn{ 51 | AttributeTypes: unixReturnAttrTypes, 52 | }, 53 | } 54 | } 55 | 56 | func (f *UnixTimestampParseFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 57 | var timestamp int64 58 | 59 | resp.Error = req.Arguments.Get(ctx, ×tamp) 60 | if resp.Error != nil { 61 | return 62 | } 63 | 64 | unixTime := time.Unix(timestamp, 0).UTC() 65 | 66 | isoYear, isoWeek := unixTime.ISOWeek() 67 | 68 | unixTimestampObject, diags := types.ObjectValue( 69 | unixReturnAttrTypes, 70 | map[string]attr.Value{ 71 | "year": types.Int64Value(int64(unixTime.Year())), 72 | "year_day": types.Int64Value(int64(unixTime.YearDay())), 73 | "day": types.Int64Value(int64(unixTime.Day())), 74 | "month": types.Int64Value(int64(unixTime.Month())), 75 | "month_name": types.StringValue(unixTime.Month().String()), 76 | "weekday": types.Int64Value(int64(unixTime.Weekday())), 77 | "weekday_name": types.StringValue(unixTime.Weekday().String()), 78 | "hour": types.Int64Value(int64(unixTime.Hour())), 79 | "minute": types.Int64Value(int64(unixTime.Minute())), 80 | "rfc3339": types.StringValue(unixTime.Format(time.RFC3339)), 81 | "second": types.Int64Value(int64(unixTime.Second())), 82 | "iso_year": types.Int64Value(int64(isoYear)), 83 | "iso_week": types.Int64Value(int64(isoWeek)), 84 | }, 85 | ) 86 | 87 | resp.Error = function.FuncErrorFromDiags(ctx, diags) 88 | if resp.Error != nil { 89 | return 90 | } 91 | 92 | resp.Error = resp.Result.Set(ctx, &unixTimestampObject) 93 | 94 | } 95 | 96 | func NewUnixTimestampParseFunction() function.Function { 97 | return &UnixTimestampParseFunction{} 98 | } 99 | -------------------------------------------------------------------------------- /internal/provider/function_unix_timestamp_parse_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "fmt" 8 | "regexp" 9 | "testing" 10 | 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 13 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 14 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 15 | ) 16 | 17 | func TestUnixTimestampParseFunction_Valid(t *testing.T) { 18 | t.Parallel() 19 | // Testing logic with known values 20 | knownUnixTime := 1690328596 21 | expectedKnownRFC3339 := "2023-07-25T23:43:16Z" 22 | 23 | resource.UnitTest(t, resource.TestCase{ 24 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 25 | tfversion.SkipBelow(tfversion.Version1_8_0), 26 | }, 27 | ProtoV6ProviderFactories: protoV6ProviderFactories(), 28 | Steps: []resource.TestStep{ 29 | { 30 | Config: fmt.Sprintf(` 31 | output "test" { 32 | value = provider::time::unix_timestamp_parse(%d) 33 | } 34 | `, knownUnixTime), 35 | ConfigPlanChecks: resource.ConfigPlanChecks{ 36 | PreApply: []plancheck.PlanCheck{ 37 | plancheck.ExpectKnownOutputValue("test", knownvalue.ObjectExact( 38 | map[string]knownvalue.Check{ 39 | "day": knownvalue.Int64Exact(25), 40 | "hour": knownvalue.Int64Exact(23), 41 | "iso_week": knownvalue.Int64Exact(30), 42 | "iso_year": knownvalue.Int64Exact(2023), 43 | "minute": knownvalue.Int64Exact(43), 44 | "month": knownvalue.Int64Exact(7), 45 | "month_name": knownvalue.StringExact("July"), 46 | "rfc3339": knownvalue.StringExact(expectedKnownRFC3339), 47 | "second": knownvalue.Int64Exact(16), 48 | "weekday": knownvalue.Int64Exact(2), 49 | "weekday_name": knownvalue.StringExact("Tuesday"), 50 | "year": knownvalue.Int64Exact(2023), 51 | "year_day": knownvalue.Int64Exact(206), 52 | }, 53 | )), 54 | }, 55 | }, 56 | }, 57 | }, 58 | }) 59 | } 60 | 61 | func TestUnixTimestampParseFunction_Null(t *testing.T) { 62 | t.Parallel() 63 | 64 | resource.UnitTest(t, resource.TestCase{ 65 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 66 | tfversion.SkipBelow(tfversion.Version1_8_0), 67 | }, 68 | ProtoV6ProviderFactories: protoV6ProviderFactories(), 69 | Steps: []resource.TestStep{ 70 | { 71 | Config: ` 72 | output "test" { 73 | value = provider::time::unix_timestamp_parse(null) 74 | } 75 | `, 76 | ExpectError: regexp.MustCompile(`Invalid value for "unix_timestamp" parameter: argument must not be null`), 77 | }, 78 | }, 79 | }) 80 | } 81 | -------------------------------------------------------------------------------- /internal/provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/datasource" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/provider" 12 | "github.com/hashicorp/terraform-plugin-framework/resource" 13 | 14 | "github.com/hashicorp/terraform-provider-time/internal/clock" 15 | ) 16 | 17 | func New() provider.Provider { 18 | return &timeProvider{ 19 | clock.NewClock(), 20 | } 21 | } 22 | 23 | func NewTestProvider(clock clock.Clock) provider.Provider { 24 | return &timeProvider{ 25 | clock: clock, 26 | } 27 | } 28 | 29 | var ( 30 | _ provider.ProviderWithFunctions = (*timeProvider)(nil) 31 | ) 32 | 33 | type timeProvider struct { 34 | clock clock.Clock 35 | } 36 | 37 | func (p *timeProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { 38 | resp.TypeName = "time" 39 | } 40 | 41 | func (p *timeProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { 42 | resp.ResourceData = p.clock 43 | } 44 | 45 | func (p *timeProvider) DataSources(ctx context.Context) []func() datasource.DataSource { 46 | return nil 47 | } 48 | 49 | func (p *timeProvider) Resources(ctx context.Context) []func() resource.Resource { 50 | return []func() resource.Resource{ 51 | NewTimeOffsetResource, 52 | NewTimeRotatingResource, 53 | NewTimeSleepResource, 54 | NewTimeStaticResource, 55 | } 56 | } 57 | 58 | func (p *timeProvider) Schema(context.Context, provider.SchemaRequest, *provider.SchemaResponse) { 59 | } 60 | 61 | func (p *timeProvider) Functions(ctx context.Context) []func() function.Function { 62 | return []func() function.Function{ 63 | NewDurationParseFunction, 64 | NewRFC3339ParseFunction, 65 | NewUnixTimestampParseFunction, 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /internal/provider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 8 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | 11 | testingresource "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | 13 | "github.com/hashicorp/terraform-provider-time/internal/clock" 14 | ) 15 | 16 | func protoV5ProviderFactories() map[string]func() (tfprotov5.ProviderServer, error) { 17 | return map[string]func() (tfprotov5.ProviderServer, error){ 18 | "time": providerserver.NewProtocol5WithError(New()), 19 | } 20 | } 21 | 22 | func protoV6ProviderFactories() map[string]func() (tfprotov6.ProviderServer, error) { 23 | return map[string]func() (tfprotov6.ProviderServer, error){ 24 | "time": providerserver.NewProtocol6WithError(New()), 25 | } 26 | } 27 | 28 | func protoV5ProviderFactoriesTestProvider(testClock clock.Clock) map[string]func() (tfprotov5.ProviderServer, error) { 29 | return map[string]func() (tfprotov5.ProviderServer, error){ 30 | "time": providerserver.NewProtocol5WithError(NewTestProvider(testClock)), 31 | } 32 | } 33 | 34 | func providerVersion080() map[string]testingresource.ExternalProvider { 35 | return map[string]testingresource.ExternalProvider{ 36 | "time": { 37 | VersionConstraint: "0.8.0", 38 | Source: "hashicorp/time", 39 | }, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /internal/provider/resource_time_sleep.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "regexp" 10 | "strings" 11 | "time" 12 | 13 | "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" 14 | "github.com/hashicorp/terraform-plugin-framework/attr" 15 | "github.com/hashicorp/terraform-plugin-framework/path" 16 | "github.com/hashicorp/terraform-plugin-framework/resource" 17 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 18 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier" 19 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" 20 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" 21 | "github.com/hashicorp/terraform-plugin-framework/schema/validator" 22 | "github.com/hashicorp/terraform-plugin-framework/types" 23 | 24 | "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" 25 | 26 | "github.com/hashicorp/terraform-provider-time/internal/clock" 27 | ) 28 | 29 | var ( 30 | _ resource.Resource = (*timeSleepResource)(nil) 31 | _ resource.ResourceWithImportState = (*timeSleepResource)(nil) 32 | _ resource.ResourceWithConfigure = (*timeSleepResource)(nil) 33 | ) 34 | 35 | func NewTimeSleepResource() resource.Resource { 36 | return &timeSleepResource{} 37 | } 38 | 39 | type timeSleepResource struct { 40 | clock clock.Clock 41 | } 42 | 43 | func (t *timeSleepResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { 44 | // Always perform a nil check when handling ProviderData because Terraform 45 | // sets that data after it calls the ConfigureProvider RPC. 46 | if req.ProviderData == nil { 47 | return 48 | } 49 | 50 | pClock, ok := req.ProviderData.(clock.Clock) 51 | 52 | if !ok { 53 | resp.Diagnostics.AddError( 54 | "Unexpected Resource Configure Type", 55 | fmt.Sprintf("Expected clock.Clock, got: %T. Please report this issue to the provider developers.", req.ProviderData), 56 | ) 57 | 58 | return 59 | } 60 | 61 | t.clock = pClock 62 | } 63 | 64 | func (t *timeSleepResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 65 | resp.TypeName = req.ProviderTypeName + "_sleep" 66 | } 67 | 68 | func (t *timeSleepResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { 69 | resp.Schema = schema.Schema{ 70 | Description: "Manages a resource that delays creation and/or destruction, typically for further resources. " + 71 | "This prevents cross-platform compatibility and destroy-time issues with using " + 72 | "the [`local-exec` provisioner](https://www.terraform.io/docs/provisioners/local-exec.html).", 73 | Attributes: map[string]schema.Attribute{ 74 | "create_duration": schema.StringAttribute{ 75 | Description: "[Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource creation. " + 76 | "For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay.", 77 | Optional: true, 78 | Validators: []validator.String{ 79 | stringvalidator.AtLeastOneOf(path.MatchRoot("destroy_duration")), 80 | stringvalidator.RegexMatches(regexp.MustCompile(`^[0-9]+(\.[0-9]+)?(ms|s|m|h)$`), 81 | "must be a number immediately followed by ms (milliseconds), s (seconds), m (minutes), or h (hours). For example, \"30s\" for 30 seconds."), 82 | }, 83 | }, 84 | "destroy_duration": schema.StringAttribute{ 85 | Description: "[Time duration](https://golang.org/pkg/time/#ParseDuration) to delay resource destroy. " + 86 | "For example, `30s` for 30 seconds or `5m` for 5 minutes. Updating this value by itself will not trigger a delay. " + 87 | "This value or any updates to it must be successfully applied into the Terraform state before destroying this resource to take effect.", 88 | Optional: true, 89 | Validators: []validator.String{ 90 | stringvalidator.AtLeastOneOf(path.MatchRoot("create_duration")), 91 | stringvalidator.RegexMatches(regexp.MustCompile(`^[0-9]+(\.[0-9]+)?(ms|s|m|h)$`), 92 | "must be a number immediately followed by ms (milliseconds), s (seconds), m (minutes), or h (hours). For example, \"30s\" for 30 seconds."), 93 | }, 94 | }, 95 | "triggers": schema.MapAttribute{ 96 | Description: "(Optional) Arbitrary map of values that, when changed, will run any creation or destroy delays again. " + 97 | "See [the main provider documentation](../index.md) for more information.", 98 | ElementType: types.StringType, 99 | Optional: true, 100 | PlanModifiers: []planmodifier.Map{ 101 | mapplanmodifier.RequiresReplace(), 102 | }, 103 | }, 104 | "id": schema.StringAttribute{ 105 | CustomType: timetypes.RFC3339Type{}, 106 | Description: "RFC3339 format of the offset timestamp, e.g. `2020-02-12T06:36:13Z`.", 107 | Computed: true, 108 | PlanModifiers: []planmodifier.String{ 109 | stringplanmodifier.UseStateForUnknown(), 110 | }, 111 | }, 112 | }, 113 | } 114 | } 115 | 116 | func (t *timeSleepResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { 117 | id := req.ID 118 | 119 | idParts := strings.Split(id, ",") 120 | 121 | if len(idParts) != 2 || (idParts[0] == "" && idParts[1] == "") { 122 | resp.Diagnostics.AddError( 123 | "Unexpected Format of ID", 124 | fmt.Sprintf("Unexpected format of ID (%q), expected CREATEDURATION,DESTROYDURATION where at least one value is non-empty", id)) 125 | 126 | return 127 | } 128 | 129 | state := timeSleepModelV0{ 130 | CreateDuration: types.StringNull(), 131 | DestroyDuration: types.StringNull(), 132 | ID: timetypes.NewRFC3339TimeValue(t.clock.Now().UTC()), 133 | } 134 | 135 | if idParts[0] != "" { 136 | _, err := time.ParseDuration(idParts[0]) 137 | if err != nil { 138 | resp.Diagnostics.AddError( 139 | "Import time sleep error", 140 | "The create_duration cannot be parsed\n\n+"+ 141 | fmt.Sprintf("Original Error: %s", err), 142 | ) 143 | return 144 | } 145 | state.CreateDuration = types.StringValue(idParts[0]) 146 | } 147 | 148 | if idParts[1] != "" { 149 | _, err := time.ParseDuration(idParts[1]) 150 | if err != nil { 151 | resp.Diagnostics.AddError( 152 | "Import time sleep error", 153 | "The create_duration cannot be parsed\n\n+"+ 154 | fmt.Sprintf("Original Error: %s", err), 155 | ) 156 | return 157 | } 158 | state.DestroyDuration = types.StringValue(idParts[1]) 159 | } 160 | 161 | state.Triggers = types.MapValueMust(types.StringType, map[string]attr.Value{}) 162 | 163 | diags := resp.State.Set(ctx, state) 164 | resp.Diagnostics.Append(diags...) 165 | } 166 | 167 | func (t *timeSleepResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 168 | var plan timeSleepModelV0 169 | 170 | diags := req.Plan.Get(ctx, &plan) 171 | resp.Diagnostics.Append(diags...) 172 | if resp.Diagnostics.HasError() { 173 | return 174 | } 175 | 176 | if plan.CreateDuration.ValueString() != "" { 177 | duration, err := time.ParseDuration(plan.CreateDuration.ValueString()) 178 | if err != nil { 179 | resp.Diagnostics.AddError( 180 | "Create time sleep error", 181 | "The create_duration cannot be parsed\n\n+"+ 182 | fmt.Sprintf("Original Error: %s", err), 183 | ) 184 | return 185 | } 186 | 187 | select { 188 | case <-ctx.Done(): 189 | resp.Diagnostics.AddError( 190 | "Create time sleep error", 191 | fmt.Sprintf("Original Error: %s", ctx.Err()), 192 | ) 193 | return 194 | case <-time.After(duration): 195 | } 196 | } 197 | 198 | state := timeSleepModelV0{ 199 | CreateDuration: plan.CreateDuration, 200 | DestroyDuration: plan.DestroyDuration, 201 | Triggers: plan.Triggers, 202 | ID: timetypes.NewRFC3339TimeValue(t.clock.Now().UTC()), 203 | } 204 | diags = resp.State.Set(ctx, state) 205 | resp.Diagnostics.Append(diags...) 206 | } 207 | 208 | func (t *timeSleepResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 209 | 210 | } 211 | 212 | func (t *timeSleepResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 213 | var data timeSleepModelV0 214 | 215 | // Read Terraform plan data into the model 216 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 217 | 218 | // Save updated data into Terraform state 219 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 220 | } 221 | 222 | func (t *timeSleepResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 223 | var state timeSleepModelV0 224 | 225 | diags := req.State.Get(ctx, &state) 226 | resp.Diagnostics.Append(diags...) 227 | if resp.Diagnostics.HasError() { 228 | return 229 | } 230 | 231 | if state.DestroyDuration.ValueString() != "" { 232 | duration, err := time.ParseDuration(state.DestroyDuration.ValueString()) 233 | if err != nil { 234 | resp.Diagnostics.AddError( 235 | "Delete time sleep error", 236 | "The create_duration cannot be parsed\n\n+"+ 237 | fmt.Sprintf("Original Error: %s", err), 238 | ) 239 | return 240 | } 241 | 242 | select { 243 | case <-ctx.Done(): 244 | resp.Diagnostics.AddError( 245 | "Delete time sleep error", 246 | fmt.Sprintf("Original Error: %s", ctx.Err()), 247 | ) 248 | return 249 | case <-time.After(duration): 250 | } 251 | } 252 | } 253 | 254 | type timeSleepModelV0 struct { 255 | CreateDuration types.String `tfsdk:"create_duration"` 256 | DestroyDuration types.String `tfsdk:"destroy_duration"` 257 | Triggers types.Map `tfsdk:"triggers"` 258 | ID timetypes.RFC3339 `tfsdk:"id"` 259 | } 260 | -------------------------------------------------------------------------------- /internal/provider/testdata/TestAccTimeRotating_LifecycleReplaceTriggeredBy/test.tf: -------------------------------------------------------------------------------- 1 | # Copyright (c) HashiCorp, Inc. 2 | # SPDX-License-Identifier: MPL-2.0 3 | 4 | # The "time_rotating" resource predates the `replace_triggered_by` 5 | # lifestyle argument introduced in Terraform v1.2.0. The `replace_triggered_by` argument looks 6 | # for an update or replacement of the supplied resource instance. Because the "time_rotating" rotation 7 | # checking logic is run during ReadResource() and the resource is removed from state, 8 | # a rotation is considered to be a creation of a new resource rather than an update or replacement. 9 | # Ref: https://github.com/hashicorp/terraform-provider-time/issues/118 10 | resource "time_rotating" "computed_rotation" { 11 | rotation_minutes = 1 12 | } 13 | 14 | resource "time_static" "static_time" { 15 | 16 | } 17 | 18 | resource "time_offset" "offset_time" { 19 | offset_minutes = 1 20 | } 21 | 22 | resource "time_rotating" "configured_rfc3339" { 23 | rfc3339 = time_static.static_time.rfc3339 24 | rotation_minutes = 1 25 | } 26 | 27 | resource "time_rotating" "configured_rotationrfc3339" { 28 | rotation_rfc3339 = time_offset.offset_time.rfc3339 29 | rotation_minutes = 1 30 | } 31 | 32 | 33 | resource "terraform_data" "test_computed_rotation" { 34 | lifecycle { 35 | replace_triggered_by = [ 36 | time_rotating.computed_rotation 37 | ] 38 | } 39 | } 40 | 41 | resource "terraform_data" "test_configured_rfc3339" { 42 | lifecycle { 43 | replace_triggered_by = [ 44 | time_rotating.configured_rfc3339 45 | ] 46 | } 47 | } 48 | 49 | resource "terraform_data" "test_configured_rotationrfc3339" { 50 | lifecycle { 51 | replace_triggered_by = [ 52 | time_rotating.configured_rotationrfc3339 53 | ] 54 | } 55 | } -------------------------------------------------------------------------------- /internal/timetesting/fake_clock.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package timetesting 5 | 6 | import ( 7 | "time" 8 | ) 9 | 10 | type FakeClock struct { 11 | now time.Time 12 | } 13 | 14 | func NewFakeClock(now time.Time) *FakeClock { 15 | return &FakeClock{ 16 | now: now, 17 | } 18 | } 19 | 20 | func (clock *FakeClock) Now() time.Time { 21 | return clock.now 22 | } 23 | 24 | func (clock *FakeClock) Since(t time.Time) time.Duration { 25 | return clock.Now().Sub(t) 26 | } 27 | 28 | func (clock *FakeClock) Increment(duration time.Duration) { 29 | now := clock.now.Add(duration) 30 | clock.now = now 31 | } 32 | 33 | func (clock *FakeClock) IncrementDate(years int, months int, days int) { 34 | now := clock.now.AddDate(years, months, days) 35 | clock.now = now 36 | } 37 | -------------------------------------------------------------------------------- /internal/timetesting/int64_between_knownvalue.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package timetesting 5 | 6 | import ( 7 | "encoding/json" 8 | "fmt" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 11 | ) 12 | 13 | var _ knownvalue.Check = int64Between{} 14 | 15 | type int64Between struct { 16 | min int64 17 | max int64 18 | } 19 | 20 | // CheckValue determines whether the passed value is of type json.Number, converts that to an int64, and then 21 | // checks if the value is between the min and max int64 values (inclusive). 22 | func (v int64Between) CheckValue(other any) error { 23 | jsonNum, ok := other.(json.Number) 24 | 25 | if !ok { 26 | return fmt.Errorf("expected json.Number value for Int64Between check, got: %T", other) 27 | } 28 | 29 | otherVal, err := jsonNum.Int64() 30 | 31 | if err != nil { 32 | return fmt.Errorf("expected json.Number to be parseable as int64 value for Int64Between check: %s", err) 33 | } 34 | 35 | if otherVal < v.min { 36 | return fmt.Errorf("received value: %d, which is less than the minimum value: %d", otherVal, v.min) 37 | } 38 | 39 | if otherVal > v.max { 40 | return fmt.Errorf("received value: %d, which is greater than the maximum value: %d", otherVal, v.max) 41 | } 42 | 43 | return nil 44 | } 45 | 46 | // String returns the string representation of the value. 47 | func (v int64Between) String() string { 48 | return fmt.Sprintf("%d ≤ x ≤ %d", v.min, v.max) 49 | } 50 | 51 | // Int64Between returns a Check for asserting that a value is between the supplied min and max int64 values (inclusive). 52 | func Int64Between(minVal, maxVal int64) int64Between { 53 | return int64Between{ 54 | min: minVal, 55 | max: maxVal, 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /internal/timetesting/int64_between_knownvalue_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package timetesting_test 5 | 6 | import ( 7 | "encoding/json" 8 | "fmt" 9 | "testing" 10 | 11 | "github.com/google/go-cmp/cmp" 12 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 13 | "github.com/hashicorp/terraform-provider-time/internal/timetesting" 14 | ) 15 | 16 | func TestInt64Between_CheckValue(t *testing.T) { 17 | t.Parallel() 18 | 19 | testCases := map[string]struct { 20 | self knownvalue.Check 21 | other any 22 | expectedError error 23 | }{ 24 | "zero-other": { 25 | self: timetesting.Int64Between(0, 0), 26 | other: json.Number("0"), // checking against the underlying value field zero-value 27 | }, 28 | "nil": { 29 | self: timetesting.Int64Between(0, 100), 30 | expectedError: fmt.Errorf("expected json.Number value for Int64Between check, got: "), 31 | }, 32 | "wrong-type": { 33 | self: timetesting.Int64Between(0, 100), 34 | other: json.Number("str"), 35 | expectedError: fmt.Errorf("expected json.Number to be parseable as int64 value for Int64Between check: strconv.ParseInt: parsing \"str\": invalid syntax"), 36 | }, 37 | "less-than-min": { 38 | self: timetesting.Int64Between(1, 50), 39 | other: json.Number("0"), 40 | expectedError: fmt.Errorf("received value: 0, which is less than the minimum value: 1"), 41 | }, 42 | "greater-than-max": { 43 | self: timetesting.Int64Between(1, 50), 44 | other: json.Number("51"), 45 | expectedError: fmt.Errorf("received value: 51, which is greater than the maximum value: 50"), 46 | }, 47 | "between": { 48 | self: timetesting.Int64Between(1, 50), 49 | other: json.Number("35"), 50 | }, 51 | "between-equal-to-min": { 52 | self: timetesting.Int64Between(1, 50), 53 | other: json.Number("1"), 54 | }, 55 | "between-equal-to-max": { 56 | self: timetesting.Int64Between(1, 50), 57 | other: json.Number("50"), 58 | }, 59 | } 60 | 61 | for name, testCase := range testCases { 62 | 63 | t.Run(name, func(t *testing.T) { 64 | t.Parallel() 65 | 66 | got := testCase.self.CheckValue(testCase.other) 67 | 68 | if diff := cmp.Diff(got, testCase.expectedError, equateErrorMessage); diff != "" { 69 | t.Errorf("unexpected difference: %s", diff) 70 | } 71 | }) 72 | } 73 | } 74 | 75 | func TestInt64Between_String(t *testing.T) { 76 | t.Parallel() 77 | 78 | got := timetesting.Int64Between(0, 100).String() 79 | 80 | if diff := cmp.Diff(got, `0 ≤ x ≤ 100`); diff != "" { 81 | t.Errorf("unexpected difference: %s", diff) 82 | } 83 | } 84 | 85 | // equateErrorMessage reports errors to be equal if both are nil 86 | // or both have the same message. 87 | var equateErrorMessage = cmp.Comparer(func(x, y error) bool { 88 | if x == nil || y == nil { 89 | return x == nil && y == nil 90 | } 91 | return x.Error() == y.Error() 92 | }) 93 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package main 5 | 6 | import ( 7 | "context" 8 | "flag" 9 | "log" 10 | 11 | "github.com/hashicorp/terraform-provider-time/internal/provider" 12 | 13 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 14 | ) 15 | 16 | func main() { 17 | var debug bool 18 | 19 | flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") 20 | flag.Parse() 21 | 22 | err := providerserver.Serve(context.Background(), provider.New, providerserver.ServeOpts{ 23 | Address: "registry.terraform.io/hashicorp/time", 24 | Debug: debug, 25 | ProtocolVersion: 5, 26 | }) 27 | if err != nil { 28 | log.Fatal(err) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /templates/functions/duration_parse.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Type}}: {{.Name}} 9 | 10 | {{ .Description | trimspace }} 11 | 12 | {{ if .HasExample -}} 13 | ## Example Usage 14 | 15 | {{tffile .ExampleFile }} 16 | {{- end }} 17 | 18 | ## Signature 19 | 20 | {{ .FunctionSignatureMarkdown }} 21 | 22 | ## Arguments 23 | 24 | {{ .FunctionArgumentsMarkdown }} 25 | {{ if .HasVariadic -}} 26 | {{ .FunctionVariadicArgumentMarkdown }} 27 | {{- end }} 28 | 29 | ## Return Type 30 | 31 | The `object` returned from `duration_parse` has the following attributes: 32 | - `hours` (Number) The duration as a floating point number of hours. 33 | - `minutes` (Number) The duration as a floating point number of minutes. 34 | - `seconds` (Number) The duration as a floating point number of seconds. 35 | - `milliseconds` (Number) The duration as an integer number of milliseconds. 36 | - `microseconds` (Number) The duration as an integer number of microseconds. 37 | - `nanoseconds` (Number) The duration as an integer number of nanoseconds. 38 | -------------------------------------------------------------------------------- /templates/functions/rfc3339_parse.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Type}}: {{.Name}} 9 | 10 | {{ .Description | trimspace }} 11 | 12 | {{ if .HasExample -}} 13 | ## Example Usage 14 | 15 | {{tffile .ExampleFile }} 16 | {{- end }} 17 | 18 | ## Signature 19 | 20 | {{ .FunctionSignatureMarkdown }} 21 | 22 | ## Arguments 23 | 24 | {{ .FunctionArgumentsMarkdown }} 25 | {{ if .HasVariadic -}} 26 | {{ .FunctionVariadicArgumentMarkdown }} 27 | {{- end }} 28 | 29 | ## Return Type 30 | 31 | The `object` returned from `rfc3339_parse` has the following attributes: 32 | - `year` (Number) The year for the timestamp. 33 | - `year_day` (Number) The day of the year for the timestamp, in the range [1, 365] for non-leap years, and [1, 366] in leap years. 34 | - `day` (Number) The day of the month for the timestamp. 35 | - `month` (Number) The month of the year for the timestamp. 36 | - `month_name` (String) The name of the month for the timestamp (ex. "January"). 37 | - `weekday` (Number) The day of the week for the timestamp. 38 | - `weekday_name` (String) The name of the day for the timestamp (ex. "Sunday"). 39 | - `hour` (Number) The hour within the day for the timestamp, in the range [0, 23]. 40 | - `minute` (Number) The minute offset within the hour for the timestamp, in the range [0, 59]. 41 | - `second` (Number) The second offset within the minute for the timestamp, in the range [0, 59]. 42 | - `unix` (Number) The number of seconds elapsed since January 1, 1970 UTC. 43 | - `iso_year` (Number) The ISO 8601 year number. 44 | - `iso_week` (Number) The ISO 8601 week number. 45 | -------------------------------------------------------------------------------- /templates/index.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: Time" 3 | description: |- 4 | The time provider is used to interact with time-based resources. 5 | --- 6 | 7 | # Time Provider 8 | 9 | The time provider is used to interact with time-based resources. The provider itself has no configuration options. 10 | 11 | Use the navigation to the left to read about the available resources. 12 | 13 | ## Resource "Triggers" 14 | 15 | Certain time resources, only perform actions during specific lifecycle actions: 16 | 17 | - `time_offset`: Saves base timestamp into Terraform state only when created. 18 | - `time_sleep`: Sleeps when created and/or destroyed. 19 | - `time_static`: Saves base timestamp into Terraform state only when created. 20 | 21 | These resources provide an optional map argument called `triggers` that can be populated with arbitrary key/value pairs. When the keys or values of this argument are updated, Terraform will re-perform the desired action, such as updating the base timestamp or sleeping again. 22 | 23 | For example: 24 | 25 | {{ tffile "examples/resources/resource_triggers.tf" }} 26 | 27 | `triggers` are *not* treated as sensitive attributes; a value used for `triggers` will be displayed in Terraform UI output as plaintext. 28 | 29 | To force a these actions to reoccur without updating `triggers`, the [`terraform taint` command](https://www.terraform.io/docs/commands/taint.html) can be used to produce the action on the next run. 30 | -------------------------------------------------------------------------------- /templates/resources/offset.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | {{ tffile "examples/resources/time_offset/resource.tf" }} 19 | 20 | ### Multiple Offsets Usage 21 | 22 | {{ tffile "examples/resources/time_offset/resource_multiple_offset.tf" }} 23 | 24 | ### Triggers Usage 25 | 26 | {{ tffile "examples/resources/time_offset/resource_triggers.tf" }} 27 | 28 | {{ .SchemaMarkdown | trimspace }} 29 | 30 | ## Import 31 | 32 | This resource can be imported using the base UTC RFC3339 timestamp and offset years, months, days, hours, minutes, and seconds, separated by commas (`,`), e.g. 33 | 34 | {{codefile "shell" .ImportFile }} 35 | 36 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /templates/resources/rotating.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | {{ tffile "examples/resources/time_rotating/resource.tf" }} 19 | 20 | {{ .SchemaMarkdown | trimspace }} 21 | 22 | ## Import 23 | 24 | This resource can be imported using the base UTC RFC3339 value and rotation years, months, days, hours, and minutes, separated by commas (`,`), e.g. for 30 days 25 | 26 | {{codefile "shell" "examples/resources/time_rotating/import_base_value.sh"}} 27 | 28 | Otherwise, to import with the rotation RFC3339 value, the base UTC RFC3339 value and rotation UTC RFC3339 value, separated by commas (`,`), e.g. 29 | 30 | {{codefile "shell" "examples/resources/time_rotating/import_rotation_value.sh"}} 31 | 32 | The `triggers` argument cannot be imported. 33 | -------------------------------------------------------------------------------- /templates/resources/sleep.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | -> In many cases, this resource should be considered a workaround for issues that should be reported and handled in downstream Terraform Provider logic. Downstream resources can usually introduce or adjust retries in their code to handle time delay issues for all Terraform configurations or upstream resources can be improved to better wait for a resource to be fully ready and available. 13 | 14 | ## Example Usage 15 | 16 | ### Delay Create Usage 17 | 18 | {{ tffile "examples/resources/time_sleep/resource_delay_create.tf" }} 19 | 20 | ### Delay Destroy Usage 21 | 22 | {{ tffile "examples/resources/time_sleep/resource_delay_destroy.tf" }} 23 | 24 | ### Triggers Usage 25 | 26 | {{ tffile "examples/resources/time_sleep/resource_triggers.tf" }} 27 | 28 | {{ .SchemaMarkdown | trimspace }} 29 | 30 | ## Import 31 | 32 | This resource can be imported with the `create_duration` and `destroy_duration`, separated by a comma (`,`). 33 | 34 | e.g. For 30 seconds create duration with no destroy duration: 35 | 36 | {{codefile "shell" "examples/resources/time_sleep/import_create.sh"}} 37 | 38 | e.g. For 30 seconds destroy duration with no create duration: 39 | 40 | {{codefile "shell" "examples/resources/time_sleep/import_destroy.sh"}} 41 | 42 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /templates/resources/static.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | -> Further manipulation of incoming or outgoing values can be accomplished with the [`formatdate()` function](https://www.terraform.io/docs/configuration/functions/formatdate.html) and the [`timeadd()` function](https://www.terraform.io/docs/configuration/functions/timeadd.html). 13 | 14 | ## Example Usage 15 | 16 | ### Basic Usage 17 | 18 | {{ tffile "examples/resources/time_static/resource.tf" }} 19 | 20 | ### Triggers Usage 21 | 22 | {{ tffile "examples/resources/time_static/resource_triggers.tf" }} 23 | 24 | {{ .SchemaMarkdown | trimspace }} 25 | 26 | 27 | ## Import 28 | 29 | This resource can be imported using the UTC RFC3339 value, e.g. 30 | 31 | {{codefile "shell" .ImportFile }} 32 | 33 | The `triggers` argument cannot be imported. -------------------------------------------------------------------------------- /terraform-registry-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "metadata": { 4 | "protocol_versions": ["5.0"] 5 | } 6 | } -------------------------------------------------------------------------------- /tools/go.mod: -------------------------------------------------------------------------------- 1 | module tools 2 | 3 | go 1.23.7 4 | 5 | require ( 6 | github.com/hashicorp/copywrite v0.22.0 7 | github.com/hashicorp/terraform-plugin-docs v0.21.0 8 | ) 9 | 10 | require ( 11 | github.com/AlecAivazis/survey/v2 v2.3.7 // indirect 12 | github.com/BurntSushi/toml v1.2.1 // indirect 13 | github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect 14 | github.com/Masterminds/goutils v1.1.1 // indirect 15 | github.com/Masterminds/semver/v3 v3.2.0 // indirect 16 | github.com/Masterminds/sprig/v3 v3.2.3 // indirect 17 | github.com/ProtonMail/go-crypto v1.1.3 // indirect 18 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 19 | github.com/armon/go-radix v1.0.0 // indirect 20 | github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect 21 | github.com/bgentry/speakeasy v0.1.0 // indirect 22 | github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect 23 | github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect 24 | github.com/cli/go-gh/v2 v2.11.2 // indirect 25 | github.com/cli/safeexec v1.0.0 // indirect 26 | github.com/cloudflare/circl v1.3.7 // indirect 27 | github.com/fatih/color v1.16.0 // indirect 28 | github.com/fsnotify/fsnotify v1.5.4 // indirect 29 | github.com/go-openapi/errors v0.20.2 // indirect 30 | github.com/go-openapi/strfmt v0.21.3 // indirect 31 | github.com/golang-jwt/jwt/v4 v4.5.2 // indirect 32 | github.com/golang/protobuf v1.5.2 // indirect 33 | github.com/google/go-github/v45 v45.2.0 // indirect 34 | github.com/google/go-github/v53 v53.0.0 // indirect 35 | github.com/google/go-querystring v1.1.0 // indirect 36 | github.com/google/uuid v1.3.0 // indirect 37 | github.com/hashicorp/cli v1.1.7 // indirect 38 | github.com/hashicorp/errwrap v1.1.0 // indirect 39 | github.com/hashicorp/go-checkpoint v0.5.0 // indirect 40 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 41 | github.com/hashicorp/go-hclog v1.6.3 // indirect 42 | github.com/hashicorp/go-multierror v1.1.1 // indirect 43 | github.com/hashicorp/go-retryablehttp v0.7.7 // indirect 44 | github.com/hashicorp/go-uuid v1.0.3 // indirect 45 | github.com/hashicorp/go-version v1.7.0 // indirect 46 | github.com/hashicorp/hc-install v0.9.1 // indirect 47 | github.com/hashicorp/hcl v1.0.0 // indirect 48 | github.com/hashicorp/terraform-exec v0.22.0 // indirect 49 | github.com/hashicorp/terraform-json v0.24.0 // indirect 50 | github.com/huandu/xstrings v1.3.3 // indirect 51 | github.com/imdario/mergo v0.3.15 // indirect 52 | github.com/inconshreveable/mousetrap v1.0.1 // indirect 53 | github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect 54 | github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect 55 | github.com/joho/godotenv v1.3.0 // indirect 56 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect 57 | github.com/knadh/koanf v1.5.0 // indirect 58 | github.com/mattn/go-colorable v0.1.14 // indirect 59 | github.com/mattn/go-isatty v0.0.20 // indirect 60 | github.com/mattn/go-runewidth v0.0.15 // indirect 61 | github.com/mergestat/timediff v0.0.3 // indirect 62 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect 63 | github.com/mitchellh/copystructure v1.2.0 // indirect 64 | github.com/mitchellh/go-homedir v1.1.0 // indirect 65 | github.com/mitchellh/mapstructure v1.5.0 // indirect 66 | github.com/mitchellh/reflectwalk v1.0.2 // indirect 67 | github.com/oklog/ulid v1.3.1 // indirect 68 | github.com/posener/complete v1.2.3 // indirect 69 | github.com/rivo/uniseg v0.4.7 // indirect 70 | github.com/samber/lo v1.37.0 // indirect 71 | github.com/shopspring/decimal v1.3.1 // indirect 72 | github.com/spf13/cast v1.5.0 // indirect 73 | github.com/spf13/cobra v1.6.1 // indirect 74 | github.com/spf13/pflag v1.0.5 // indirect 75 | github.com/thanhpk/randstr v1.0.4 // indirect 76 | github.com/yuin/goldmark v1.7.7 // indirect 77 | github.com/yuin/goldmark-meta v1.1.0 // indirect 78 | github.com/zclconf/go-cty v1.16.2 // indirect 79 | go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect 80 | go.mongodb.org/mongo-driver v1.10.0 // indirect 81 | golang.org/x/crypto v0.36.0 // indirect 82 | golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect 83 | golang.org/x/mod v0.22.0 // indirect 84 | golang.org/x/net v0.38.0 // indirect 85 | golang.org/x/oauth2 v0.8.0 // indirect 86 | golang.org/x/sync v0.12.0 // indirect 87 | golang.org/x/sys v0.31.0 // indirect 88 | golang.org/x/term v0.30.0 // indirect 89 | golang.org/x/text v0.23.0 // indirect 90 | google.golang.org/appengine v1.6.7 // indirect 91 | google.golang.org/protobuf v1.33.0 // indirect 92 | gopkg.in/yaml.v2 v2.4.0 // indirect 93 | gopkg.in/yaml.v3 v3.0.1 // indirect 94 | ) 95 | -------------------------------------------------------------------------------- /tools/tools.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //go:build generate 5 | 6 | package tools 7 | 8 | import ( 9 | // document generation 10 | _ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" 11 | // copywrite header generation 12 | _ "github.com/hashicorp/copywrite" 13 | ) 14 | 15 | // Generate copyright headers 16 | //go:generate go run github.com/hashicorp/copywrite headers -d .. --config ../.copywrite.hcl 17 | // Format Terraform code for use in documentation. 18 | // If you do not have Terraform installed, you can remove the formatting command, but it is suggested 19 | // to ensure the documentation is formatted properly. 20 | //go:generate terraform fmt -recursive ../examples/ 21 | // Generate documentation. 22 | //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-dir .. 23 | -------------------------------------------------------------------------------- /version/VERSION: -------------------------------------------------------------------------------- 1 | 0.13.1 2 | --------------------------------------------------------------------------------