diff --git a/examples/role/main.tf b/examples/role/main.tf new file mode 100644 index 000000000..70ac6be5e --- /dev/null +++ b/examples/role/main.tf @@ -0,0 +1,77 @@ +provider "nutanix" { + username = var.user + password = var.password + endpoint = var.endpoint + insecure = var.insecure + port = var.port + wait_timeout = 60 +} + +# Create Kubernetes Infrastructure Provision role +# --------------- +data "nutanix_permission" "k8s_infra_provision_permissions" { + for_each = toset(var.k8s_infra_provision_permissions) + permission_name = each.key +} + +resource "nutanix_role" "kubernetes_infrastructure_provision" { + name = "Kubernetes Infrastructure Provision" + description = "Access for Kubernetes cluster infrastructure VMs resources" + dynamic "permission_reference_list" { + for_each = data.nutanix_permission.k8s_infra_provision_permissions + content { + kind = "permission" + uuid = permission_reference_list.value.id + } + } +} + +data "nutanix_role" "kubernetes_infrastructure_provision" { + role_id = nutanix_role.kubernetes_infrastructure_provision.id +} + +# Create CSI System role +# --------------- +data "nutanix_permission" "csi_system_role_permissions" { + for_each = toset(var.csi_system_role_permissions) + permission_name = each.key +} + +resource "nutanix_role" "csi_system" { + name = "CSI System" + description = "Full access for Kubernetes cluster infrastructure resources for CSI" + dynamic "permission_reference_list" { + for_each = data.nutanix_permission.csi_system_role_permissions + content { + kind = "permission" + uuid = permission_reference_list.value.id + } + } +} + +data "nutanix_role" "csi_system" { + role_id = nutanix_role.csi_system.id +} + +# Create Kubernetes Data Services System role +# --------------- +data "nutanix_permission" "k8s_data_services_system_role_permissions" { + for_each = toset(var.k8s_data_services_system_role_permissions) + permission_name = each.key +} + +resource "nutanix_role" "k8s_data_services_system" { + name = "Kubernetes Data Services System" + description = "Full access for Kubernetes cluster infrastructure resources for Kubernetes Data Services" + dynamic "permission_reference_list" { + for_each = data.nutanix_permission.k8s_data_services_system_role_permissions + content { + kind = "permission" + uuid = permission_reference_list.value.id + } + } +} + +data "nutanix_role" "k8s_data_services_system" { + role_id = nutanix_role.k8s_data_services_system.id +} diff --git a/examples/role/outputs.tf b/examples/role/outputs.tf new file mode 100644 index 000000000..dcd9b0a50 --- /dev/null +++ b/examples/role/outputs.tf @@ -0,0 +1,11 @@ +output "k8s_infra_provision_role_id" { + value = data.nutanix_role.kubernetes_infrastructure_provision.id +} + +output "k8s_data_services_system_role_id" { + value = data.nutanix_role.k8s_data_services_system.id +} + +output "csi_system_role_id" { + value = data.nutanix_role.csi_system.id +} \ No newline at end of file diff --git a/examples/role/variables.tf b/examples/role/variables.tf new file mode 100644 index 000000000..c0ac2f64a --- /dev/null +++ b/examples/role/variables.tf @@ -0,0 +1,184 @@ +variable "user" { + type = string +} +variable "password" { + type = string +} +variable "endpoint" { + type = string +} +variable "insecure" { + type = bool +} +variable "port" { + type = number +} + +variable "k8s_infra_provision_permissions" { + type = list(string) + default = [ + "Create_Category_Mapping", + "Create_Image", + "Create_Or_Update_Name_Category", + "Create_Or_Update_Value_Category", + "Create_Virtual_Machine", + "Delete_Category_Mapping", + "Delete_Image", + "Delete_Name_Category", + "Delete_Value_Category", + "Delete_Virtual_Machine", + "Update_Category_Mapping", + "Update_Virtual_Machine_Project", + "Update_Virtual_Machine", + "View_Category_Mapping", + "View_Cluster", + "View_Image", + "View_Name_Category", + "View_Project", + "View_Subnet", + "View_Value_Category", + "View_Virtual_Machine" + ] +} + +variable "csi_system_role_permissions" { + type = list(string) + default = [ + "Create_Volume_Group_Disk", + "Delete_Volume_Group_Disk", + "Update_Volume_Group_Disk_Internal", + "View_Project", + "View_Task", + "Create_Or_Update_Value_Category", + "Create_Category", + "View_Name_Category", + "View_Category", + "View_External_iSCSI_Client", + "View_VM_Recovery_Point", + "View_Virtual_Machine", + "View_Volume_Group_Details", + "View_Volume_Group_Disks", + "View_Volume_Group_iSCSI_Attachments", + "View_Volume_Group_VM_Attachments", + "View_Volume_Group_Category_Associations", + "View_Volume_Group_Metadata", + "Create_Virtual_Machine", + "Restore_VM_Recovery_Point", + "Delete_Image", + "Associate_Volume_Group_Categories", + "Disassociate_Volume_Group_Categories", + "Update_Virtual_Machine_Project", + "Update_Container_Disks", + "View_Image", + "Create_Category_Mapping", + "Create_Volume_Group", + "Delete_Category_Mapping", + "Update_Category_Mapping", + "View_Category_Mapping", + "View_Subnet", + "Delete_Availability_Zone", + "Create_Or_Update_Name_Category", + "Delete_Volume_Group", + "View_Cluster", + "View_Value_Category", + "Delete_Category", + "Create_Image", + "Delete_Virtual_Machine", + "View_Container", + "View_Storage_Container", + "View_Any_Virtual_Machine", + "Create_Job", + "Update_Virtual_Machine", + "Update_Network_Function_Chain", + "Delete_Name_Category", + "Create_Vm_Snapshot", + "Update_Account", + "Delete_Value_Category", + "Update_Category", + "Update_Remote_Connection", + "Attach_Volume_Group_To_External_iSCSI_Client", + "Detach_Volume_Group_From_External_iSCSI_Client", + "Create_Consistency_Group", + "Update_Consistency_Group", + "View_Consistency_Group", + "Create_Recovery_Point", + "View_Recovery_Point", + "Delete_Recovery_Point", + "Set_Expiration_Time_Recovery_Point", + "View_Container_Datastore", + "View_Container_Stats", + "Update_Volume_Group_Details_Internal", + "Update_External_iSCSI_Client_Internal" + ] +} + +variable "k8s_data_services_system_role_permissions" { + type = list(string) + default = [ + "Create_Volume_Group_Disk", + "Delete_Volume_Group_Disk", + "Update_Volume_Group_Disk_Internal", + "View_Project", + "View_Task", + "Create_Or_Update_Value_Category", + "Create_Category", + "View_Name_Category", + "View_Category", + "View_External_iSCSI_Client", + "View_VM_Recovery_Point", + "View_Virtual_Machine", + "View_Volume_Group_Details", + "View_Volume_Group_Disks", + "View_Volume_Group_iSCSI_Attachments", + "View_Volume_Group_VM_Attachments", + "View_Volume_Group_Category_Associations", + "View_Volume_Group_Metadata", + "Create_Virtual_Machine", + "Restore_VM_Recovery_Point", + "Delete_Image", + "Associate_Volume_Group_Categories", + "Disassociate_Volume_Group_Categories", + "Update_Virtual_Machine_Project", + "Update_Container_Disks", + "View_Image", + "Create_Category_Mapping", + "Create_Volume_Group", + "Delete_Category_Mapping", + "Update_Category_Mapping", + "View_Category_Mapping", + "View_Subnet", + "Delete_Availability_Zone", + "Create_Or_Update_Name_Category", + "Delete_Volume_Group", + "View_Cluster", + "View_Value_Category", + "Delete_Category", + "Create_Image", + "Delete_Virtual_Machine", + "View_Container", + "View_Storage_Container", + "View_Any_Virtual_Machine", + "Create_Job", + "Update_Virtual_Machine", + "Update_Network_Function_Chain", + "Delete_Name_Category", + "Create_Vm_Snapshot", + "Update_Account", + "Delete_Value_Category", + "Update_Category", + "Update_Remote_Connection", + "Attach_Volume_Group_To_External_iSCSI_Client", + "Detach_Volume_Group_From_External_iSCSI_Client", + "Create_Consistency_Group", + "Update_Consistency_Group", + "View_Consistency_Group", + "Create_Recovery_Point", + "View_Recovery_Point", + "Delete_Recovery_Point", + "Set_Expiration_Time_Recovery_Point", + "View_Container_Datastore", + "View_Container_Stats", + "Update_Volume_Group_Details_Internal", + "Update_External_iSCSI_Client_Internal" + ] +} diff --git a/examples/role/versions.tf b/examples/role/versions.tf new file mode 100644 index 000000000..62383997f --- /dev/null +++ b/examples/role/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + nutanix = { + source = "nutanix/nutanix" + version = "1.9.2" + } + } +}