Sentinel Policies to delete Terraform cloud Workspace

Hi All,

I am new to Sentinel ; want to know can we write policy to delete workspace into an org past x month? any Sample or reference will help.

Hi @avinashkrsingh,

Can you provide more context about why you want to be able to do this?

Currently, Sentinel does not have any built-in capabilities to perform this type of operation in Terraform Cloud. In theory, you could write a custom Sentinel module to do this, but it would be an anti-pattern.

Here is how one way of doing it:

  1. Use the tfrun import
  2. Look for the workspace block and attribute created_at . This will give you the timestamp when workspace was created
  3. Use the calender import to get the current date/month
  4. Use appropriate logic in your code to calculate the difference in current month and month when workspace was created
  5. If the number > x(whatever timeframe you want) months, policy fails.