Skip to content

Commit

Permalink
project internal changes (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishekism9450 authored Aug 31, 2022
1 parent d97329a commit fe670b2
Show file tree
Hide file tree
Showing 15 changed files with 3,522 additions and 165 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.7.1 (August 31, 2022)
[Full Changelog](https://github.com/nutanix/terraform-provider-nutanix/compare/v1.7.0...v1.7.1)

**Implemented enhancements:**

- Support for /projects_internal API in nutanix projects [\#487](https://github.com/nutanix/terraform-provider-nutanix/pull/487)

**Closed Issues:**
- project internal changes [\#488] (https://github.com/nutanix/terraform-provider-nutanix/pull/488)


## 1.7.0 (August 12, 2022)

[Full Changelog](https://github.com/nutanix/terraform-provider-nutanix/compare/v1.6.1...v1.7.0)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Terraform provider plugin to integrate with Nutanix Enterprise Cloud

NOTE: The latest version of the Nutanix provider is [v1.7.0](https://github.com/nutanix/terraform-provider-nutanix/releases/tag/v1.7.0)
NOTE: The latest version of the Nutanix provider is [v1.7.1](https://github.com/nutanix/terraform-provider-nutanix/releases/tag/v1.7.1)

Modules based on Terraform Nutanix Provider can be found here : [Modules](https://github.com/nutanix/terraform-provider-nutanix/tree/master/modules)
## Build, Quality Status
Expand Down Expand Up @@ -44,12 +44,16 @@ The Terraform Nutanix provider is designed to work with Nutanix Prism Central an
> For the 1.7.0 release of the provider it will have N-2 compatibility with the Prism Central APIs. This release was tested against Prism Central versions pc2022.6, pc2022.4 and pc2022.1.0.2.
> For the 1.7.1 release of the provider it will have N-2 compatibility with the Prism Central APIs. This release was tested against Prism Central versions pc2022.6, pc2022.4.0.1 and pc2022.1.0.2.
### note
With v1.6.1 release of flow networking feature in provider, IAMv2 setups would be mandate.
Also, there is known issue for access_control_policies resource where update would be failing. We are continuously tracking the issue internally.

with v1.7.0 release of user groups feature in provider, pc version should be minimum 2022.1 to support organisational and saml user group.

With v1.7.1 release of project internal in provider is supported. Note to use this, set "use_project_internal" to true. It also enables the ACP mapping with projects.

## Foundation
> For the 1.5.0-beta release of the provider it will have N-1 compatibility with the Foundation. This release was tested against Foundation versions v5.2 and v5.1.1
Expand Down
39 changes: 39 additions & 0 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ type Service interface {
ListAllFloatingIPs(ctx context.Context, filter string) (*FloatingIPsListIntentResponse, error)
GetStaticRoute(ctx context.Context, vpcUUID string) (*StaticRouteIntentResponse, error)
UpdateStaticRoute(ctx context.Context, uuid string, body *StaticRouteIntentInput) (*StaticRouteIntentResponse, error)
CreateProjectInternal(ctx context.Context, request *ProjectInternalIntentInput) (*ProjectInternalIntentResponse, error)
GetProjectInternal(ctx context.Context, uuid string) (*ProjectInternalIntentResponse, error)
UpdateProjectInternal(ctx context.Context, uuid string, body *ProjectInternalIntentInput) (*ProjectInternalIntentResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -2822,3 +2825,39 @@ func (op Operations) ListAllFloatingIPs(ctx context.Context, filter string) (*Fl

return resp, nil
}

func (op Operations) CreateProjectInternal(ctx context.Context, request *ProjectInternalIntentInput) (*ProjectInternalIntentResponse, error) {
req, err := op.client.NewRequest(ctx, http.MethodPost, "/projects_internal", request)
if err != nil {
return nil, err
}

projectResponse := new(ProjectInternalIntentResponse)

return projectResponse, op.client.Do(ctx, req, projectResponse)
}

func (op Operations) GetProjectInternal(ctx context.Context, projectUUID string) (*ProjectInternalIntentResponse, error) {
path := fmt.Sprintf("/projects_internal/%s", projectUUID)
project := new(ProjectInternalIntentResponse)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}

return project, op.client.Do(ctx, req, project)
}

func (op Operations) UpdateProjectInternal(ctx context.Context, uuid string, body *ProjectInternalIntentInput) (*ProjectInternalIntentResponse, error) {
path := fmt.Sprintf("/projects_internal/%s", uuid)

projectInput := new(ProjectInternalIntentResponse)

req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
if err != nil {
return nil, err
}

return projectInput, op.client.Do(ctx, req, projectInput)
}
94 changes: 94 additions & 0 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2861,3 +2861,97 @@ type StaticRouteIntentResponse struct {

Status *StaticRouteDefStatus `json:"status"`
}

// ProjectResources ...
type ProjectInternalResources struct {
ResourceDomain *ResourceDomain `json:"resource_domain,omitempty"`
AccountReferenceList []*ReferenceValues `json:"account_reference_list,omitempty"`
EnvironmentReferenceList []*ReferenceValues `json:"environment_reference_list,omitempty"`
DefaultSubnetReference *ReferenceValues `json:"default_subnet_reference,omitempty"`
UserReferenceList []*ReferenceValues `json:"user_reference_list,omitempty"`
TunnelReferenceList []*ReferenceValues `json:"tunnel_reference_list,omitempty"`
ExternalUserGroupReferenceList []*ReferenceValues `json:"external_user_group_reference_list,omitempty"`
ClusterReferenceList []*ReferenceValues `json:"cluster_reference_list,omitempty"`
SubnetReferenceList []*ReferenceValues `json:"subnet_reference_list,omitempty"`
VPCReferenceList []*ReferenceValues `json:"vpc_reference_list,omitempty"`
ExternalNetworkList []*ReferenceValues `json:"external_network_list,omitempty"`
DefaultEnvironmentReference *Reference `json:"default_environment_reference,omitempty"`
IsDefault bool `json:"is_default,omitempty"`
}

type ProjectStatusResources struct {
Name *string `json:"name,omitempty"`
State *string `json:"state,omitempty"`
Reason *string `json:"reason,omitempty"`
Message *string `json:"message,omitempty"`
Resources *ProjectInternalResources `json:"resources,omitempty"`
Description *string `json:"description,omitempty"`
}

type ProjectAccessControlPolicyStatus struct {
Name *string `json:"name,omitempty"`
IsSystemDefined bool `json:"is_system_defined,omitempty"`
State *string `json:"state,omitempty"`
MessageList []*MessageResource `json:"message_list,omitempty"`
Resources *AccessControlPolicyResources `json:"resources,omitempty"`
Description *string `json:"description,omitempty"`
}

type ProjectAccessControlPolicyListStatus struct {
Metadata *Metadata `json:"metadata,omitempty"`
ProjectAccessControlPolicyStatus *ProjectAccessControlPolicyStatus `json:"access_control_policy_status,omitempty"`
}

// ProjectStatus ...
type ProjectInternalStatus struct {
AccessControlPolicyListStatus []*ProjectAccessControlPolicyListStatus `json:"access_control_policy_list_status,omitempty"`
ProjectStatus *ProjectStatusResources `json:"project_status,omitempty"`
ExecutionContext *ExecutionContext `json:"execution_context,omitempty"`
State *string `json:"state,omitempty"`
}

type ProjectDetails struct {
Name *string `json:"name,omitempty"`
Resources *ProjectInternalResources `json:"resources,omitempty"`
Description *string `json:"description,omitempty"`
}

type AccessControlPolicyList struct {
Operation *string `json:"operation,omitempty"`
ACP *AccessControlPolicySpec `json:"acp,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}

type UserList struct {
Operation *string `json:"operation,omitempty"`
User *UserSpec `json:"user,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}

type UserGroupList struct {
Operation *string `json:"operation,omitempty"`
UserGroup *UserGroupSpec `json:"user_group,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}

// ProjectSpec ...
type ProjectInternalSpec struct {
ProjectDetail *ProjectDetails `json:"project_detail,omitempty"`
AccessControlPolicyList []*AccessControlPolicyList `json:"access_control_policy_list,omitempty"`
UserList []*UserList `json:"user_list"`
UserGroupList []*UserGroupList `json:"user_group_list"`
}

type ProjectInternalIntentInput struct {
Spec *ProjectInternalSpec `json:"spec,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
APIVersion string `json:"api_version,omitempty"`
}

// Project Response object for intentful operations on a Host
type ProjectInternalIntentResponse struct {
Status *ProjectInternalStatus `json:"status,omitempty"`
Spec *ProjectInternalSpec `json:"spec,omitempty"`
APIVersion string `json:"api_version,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}
105 changes: 105 additions & 0 deletions examples/projects/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
terraform{
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.7.1"
}
}
}

#defining nutanix configuration
provider "nutanix"{
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

# set use_project_internal flag to use user-role mapping

data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

# ### Define Terraform Managed Subnets
resource "nutanix_subnet" "infra-managed-network-140" {
# What cluster will this VLAN live on?
cluster_uuid = local.cluster1

# General Information
name = "infra-managed-network-140"
vlan_id = 140
subnet_type = "VLAN"

# Provision a Managed L3 Network
# This bit is only needed if you intend to turn on AHV's IPAM
subnet_ip = "10.xx.xx.xx"

default_gateway_ip = "10.xx.xx.xx"
prefix_length = 24

dhcp_options = {
boot_file_name = "bootfile"
domain_name = "lab"
tftp_server_name = "10.xx.xx.xx"
}

dhcp_server_address = {
ip = "10.xx.xx.xx"
}

dhcp_domain_name_server_list = ["10.xx.xx.xx"]
dhcp_domain_search_list = ["ntnxlab.local"]
#ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]
}

# Note: user reference and acp->user_reference should be same for mapping the role. Also whenever acp is given
# it's mandate to provide cluster_uuid to get the filter context list and scope of each defined user.

resource "nutanix_project" "testp1" {
name = "testProj"
description = "test project description"

# cluster uuid is required to map acp in projects
cluster_uuid = "${local.cluster1}"

# set this use_project_internal flag for using projects_internal API
use_project_internal=true

# set project collaboration, default it is true
enable_collab = true
default_subnet_reference{
kind="subnet"
uuid=resource.nutanix_subnet.sub.id
}
user_reference_list{
name= "{{user_name}}"
kind= "user"
uuid= "{{user_uuid}}"
}
subnet_reference_list{
uuid=resource.nutanix_subnet.sub.id
}
acp{
# acp name consists name_uuid string, it should be different for each acp.
name="{{acp_name}}"
role_reference{
kind= "role"
uuid= "{{role_uuid}}"
name="Developer"
}
user_reference_list{
name= "{{user_name}}"
kind= "user"
uuid= "{{user_uuid}}"
}
description= "descripton"
}
api_version = "3.1"
}
5 changes: 5 additions & 0 deletions examples/projects/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/projects/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#define the type of variables to be used in terraform file
variable "nutanix_username" {
type = string
}
variable "nutanix_password" {
type = string
}
variable "nutanix_endpoint" {
type = string
}
variable "nutanix_port" {
type = string
}
Loading

0 comments on commit fe670b2

Please sign in to comment.