Skip to content

Commit

Permalink
feat(testing): add new test case for #9
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpe committed Feb 4, 2025
1 parent 8c52036 commit ac8ac53
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ crash.*.log
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
!tests/terraform/github_issue9/terraform.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ test_user_import :
# terraform -chdir=tests/terraform/crud_users state rm storagegrid_users.new-local-user;\
terraform -chdir=tests/terraform/crud_users import storagegrid_users.new-local-user b0789794-8aab-4308-985b-55ea4987e91b

github9:
rm -rf bin/terraform-provider-storagegrid
go mod tidy; go install .;\
terraform -chdir=tests/terraform/github_issue9 init;\
terraform -chdir=tests/terraform/github_issue9 plan -var-file=terraform.tfvars;\
terraform -chdir=tests/terraform/github_issue9 apply -var-file=terraform.tfvars -auto-approve;\
terraform -chdir=tests/terraform/github_issue9 destroy -auto-approve
44 changes: 44 additions & 0 deletions tests/terraform/github_issue9/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
storagegrid = {
source = "github.com/dmpe/storagegrid"
}
}
}

provider "storagegrid" {
address = "https://grid.firm.com:9443/api/v3"
username = var.grid_username
password = var.grid_password
tenant = var.grid_tenant_iid
insecure = true
}

# Create multiple groups dynamically
resource "storagegrid_groups" "groups" {
for_each = { for g in var.groups : g.unique_name => g }
unique_name = each.value.unique_name
display_name = each.value.display_name
management_read_only = each.value.management_read_only

policies = {
management = each.value.management_policies
s3 = each.value.s3
}
}

# Create multiple users dynamically
resource "storagegrid_users" "users" {
for_each = { for u in var.users : u.unique_name => u }
unique_name = each.value.unique_name
full_name = each.value.full_name
disable = each.value.disable
member_of = [for group_name in each.value.member_of : storagegrid_groups.groups[group_name].id]
}

# Create multiple user's s3 access keys dynamically
resource "storagegrid_s3_access_key" "user_keys" {
for_each = { for u in var.users : u.unique_name => u if u.create_key == true }
user_uuid = storagegrid_users.users[each.value.unique_name].id
expires = each.value.key_expiry
}
43 changes: 43 additions & 0 deletions tests/terraform/github_issue9/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
groups = [
{
unique_name = "group/demo"
display_name = "Demo"
management_policies = {
manage_all_containers = false
manage_endpoints = false
manage_own_container_objects = true
manage_own_s3_credentials = true
root_access = false
view_all_containers = false
}
s3 = {
statement = [
{
sid = "deny-policy"
effect = "Deny"
action = ["s3:*"]
resource = ["arn:aws:s3:::"]
}
]
}
}
]

users = [
{
unique_name = "user/bill"
full_name = "Bill"
disable = false
member_of = ["group/demo"]
create_key = true
key_expiry = "2026-01-01T00:00:00.000Z"
},
{
unique_name = "user/jill"
full_name = "Jill"
disable = false
member_of = ["group/demo"]
create_key = false
},

]
51 changes: 51 additions & 0 deletions tests/terraform/github_issue9/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
variable "grid_username" {
description = "Grid username"
type = string
}

variable "grid_password" {
description = "Grid password"
type = string
}

variable "grid_tenant_iid" {
description = "Tenant ID"
type = string
}

variable "groups" {
description = "List of groups to create"
type = list(object({
unique_name = string
display_name = string
management_read_only = optional(bool, true)
management_policies = object({
manage_all_containers = bool
manage_endpoints = bool
manage_own_container_objects = bool
manage_own_s3_credentials = bool
root_access = bool
view_all_containers = bool
})
s3 = object({
statement = list(object({
sid = string
effect = string
action = list(string)
resource = list(string)
}))
})
}))
}

variable "users" {
description = "List of users to create"
type = list(object({
unique_name = string
full_name = string
disable = optional(bool, false)
member_of = list(string) # List of group unique_names to assign the user to
create_key = optional(bool, false) # New field to determine if a key should be created
key_expiry = optional(string, "") # Optional expiration for the key (ISO 8601 format, e.g., "2028-01-01T00:00:00.000Z")
}))
}

0 comments on commit ac8ac53

Please sign in to comment.