Skip to content

Conversation

@pascalinthecloud
Copy link
Contributor

Description

This PR introduces support for conditions in IAM policies. Conditions allow to restrict permissions based on resources, date or customer's information.

It also adds an expired_at attribute to policies.

The conditions attribute is implemented with a 3-level nested schema. This is a workaround for the fact that Terraform does not support recursive schema definitions. The depth of 3 levels was chosen as a reasonable default, but this can be adjusted in the future if needed.

This PR also includes two minor bug fixes:

  • Fix a formatting issue in the ovh_cloud_project_network_private resource. This was a minor fix to remove an unnecessary fmt.Sprintf.
  • Fix a formatting issue in the error handling of cloud project databases. This was a minor fix to add the correct format specifier to an fmt.Errorf call.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The new conditions and expired_at attributes have been tested with acceptance tests.

  • Test A: make testacc TESTARGS="-run TestAccIamPolicy_conditions"
  • Test B: make testacc TESTARGS="-run TestAccIamPolicy_withExpirationDate"
  • Test C: make testacc TESTARGS="-run TestAccIamPolicy"

Test Configuration:

  • Terraform version: terraform version: Terraform v1.11.3
  • Existing HCL configuration you used:
resource "ovh_iam_policy" "workdays_and_ip_and_expiring" {
  name        = "workdays_and_ip_and_expiring"
  description = "Allow access only on workdays, expires end of 2026"
  identities  = ["urn:v1:eu:identity:user:my-user"]
  resources   = ["urn:v1:eu:resource:vps:*"]

  allow = [
    "vps:apiovh:*",
  ]

  conditions {
    operator = "AND"
    condition {
      operator = "MATCH"
      values = {
        "date(Europe/Paris).WeekDay.In" = "monday,tuesday,wednesday,thursday,friday"
      }
    }
    condition {
      operator = "MATCH"
      values = {
        "request.IP" = "192.72.0.1"
      }
    }
  }

  expired_at = "2026-12-31T23:59:59Z"
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes
  • I ran successfully go mod vendor if I added or modify go.mod file

@pascalinthecloud pascalinthecloud requested a review from a team as a code owner November 29, 2025 09:25
@pascalinthecloud pascalinthecloud force-pushed the feat/iam-policy-conditions-and-expire-at branch from dc548c3 to cc7f704 Compare November 29, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant