Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform 0.12 Provider Support. #72

Merged
merged 30 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d8c7665
chore: update terraform 0.12 dependencies
marinsalinas Jul 11, 2019
c5c4d17
feat: add logging transport to DEBUG HTTP Calls
marinsalinas Jul 11, 2019
1904f8c
test: update subnet resource and data source test configuration to be…
marinsalinas Jul 11, 2019
cda270b
refactor: change terraform unique id instead uuid in clusters data so…
marinsalinas Jul 14, 2019
6c1885e
test: change virtual machine acceptance test configuration to support…
marinsalinas Jul 14, 2019
69cd9d6
test: change virtual machine data source acc-test configuration to su…
marinsalinas Jul 14, 2019
bf1fae9
test: change subnet resource acc-test configuration to support tf 0.1…
marinsalinas Jul 14, 2019
0330c62
test: change category value resource acc-test configuration to suppor…
marinsalinas Jul 14, 2019
350d873
test: change subnet datasource acc-test configuration to support tf 0…
marinsalinas Jul 14, 2019
9f1640c
test: change image datasource acc-test configuration to support tf 0.…
marinsalinas Jul 14, 2019
e22031d
test: change category_key datasource acc-test configuration to suppor…
marinsalinas Jul 14, 2019
d1ee5f5
website: remove network_security_rule documentation link
marinsalinas Jul 15, 2019
2496729
website: change examples in website documentation to support tf 0.12
marinsalinas Jul 15, 2019
907c767
chore: update example configuration to support terraform 0.12 syntax
marinsalinas Jul 15, 2019
b22b01e
chore: update Readme.md for tf0.12 support
marinsalinas Jul 17, 2019
2391117
refactor: fix network security rule strutcs
marinsalinas Jul 30, 2019
40265ad
feat: add network_security_rule resource
marinsalinas Jul 30, 2019
1bf3aab
chore: fix structs for network security rules
marinsalinas Aug 13, 2019
14cea6c
refactor: refuse outbound rule logic
marinsalinas Aug 13, 2019
5ce4139
test: add isolation rule test case
marinsalinas Aug 13, 2019
2b96b5a
website: add new examples of network security rules resource
marinsalinas Aug 14, 2019
f53d196
website: add network_security_rules resource link in provider index page
marinsalinas Aug 14, 2019
3019218
feat: add network security rule data source
marinsalinas Aug 15, 2019
d06578a
website: add network security rules data source documentation
marinsalinas Aug 16, 2019
0bc067a
chore: remove quarantine rule feature in resource nutanix_network_sec…
marinsalinas Aug 20, 2019
0b952b1
test: change source_uri in nutanix_image with large image url test case
marinsalinas Aug 20, 2019
d0fd095
refactor: add expand and flatten portlist function
marinsalinas Aug 27, 2019
040a6ee
test: add isolation rule test case for security rules
marinsalinas Aug 27, 2019
4db7177
refactor: add portRange schema function
marinsalinas Aug 28, 2019
f0db2ae
website: add network security rule data source description
marinsalinas Aug 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,16 @@ We'll be working with HashiCorp as code stabilizes to upstream this properly, at

## Building/Developing Provider

Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provider-nutanix`
We recomment to use Go 1.12+ to be able to use `go modules`

```sh
$ mkdir $GOPATH/src/github.com/terraform-providers && cd "$_" #if you already created it only change directory
$ git clone https://github.com/terraform-providers/terraform-provider-nutanix.git
```

Enter the provider directory and build the provider

```sh
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-nutanix
$ make deps
$ make tools
$ make build
```

Expand All @@ -258,9 +256,39 @@ This will create a binary file `terraform-provider-nutanix` you can copy to your
Alternative build: with our demo

```sh
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-nutanix
$ make deps
$ make tools
$ go build -o examples/terraform-provider-nutanix
$ cd examples
$ terraform init #to try out our demo
```

If you need multi-OS binaries such as Linux, macOS, Windows. Run the following command.

```sh
$ make tools
$ make cibuild
```

This coommand will create a `pkg/` directory with all the binaries for the most popular OS.


### Common Issues using the development binary.

Terraform download the released binary instead developent one.

Just follow this steps to get the development binary:

1. Copy the development terraform binary in the root folder of the project (i.e. where your main.tf is), this should be named `terraform-provider-nutanix`
2. Remove the entire “.terraform” directory.
```sh
rm -rf .terraform/
```

3. Run the following command in the same folder where you have copied the development terraform binary.
```sh
terraform init -upgrade
terraform providers -version
```

4. You should see version as “nutanix (unversioned)”
5. Then run your main.tf
7 changes: 2 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"net/http"
"net/url"

"github.com/terraform-providers/terraform-provider-nutanix/utils"
"github.com/hashicorp/terraform/helper/logging"
)

const (
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewClient(credentials *Credentials) (*Client, error) {

httpClient := http.DefaultClient

httpClient.Transport = transCfg
httpClient.Transport = logging.NewTransport("Nutanix", transCfg)

baseURL, err := url.Parse(fmt.Sprintf(defaultBaseURL, credentials.URL))

Expand Down Expand Up @@ -155,13 +155,10 @@ func (c *Client) OnRequestCompleted(rc RequestCompletionCallback) {
// Do performs request passed
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) error {
req = req.WithContext(ctx)
utils.DebugRequest(req)
resp, err := c.client.Do(req)
if err != nil {
return err
}

utils.DebugResponse(resp)
defer func() {
if rerr := resp.Body.Close(); err == nil {
err = rerr
Expand Down
18 changes: 9 additions & 9 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,19 +1629,19 @@ type NetworkSecurityRuleIntentInput struct {

// NetworkSecurityRuleDefStatus ... Network security rule status
type NetworkSecurityRuleDefStatus struct {
AppRule *NetworkSecurityRuleResourcesRule `json:"app_rule,omitempty"`
IsolationRule *NetworkSecurityRuleIsolationRule `json:"isolation_rule,omitempty"`
QuarantineRule *NetworkSecurityRuleResourcesRule `json:"quarantine_rule,omitempty"`
State *string `json:"state,omitmepty"`
ExecutionContext *ExecutionContext `json:"execution_context,omitempty"`
Resources *NetworkSecurityRuleResources `json:"resources,omitmepty"`
State *string `json:"state,omitempty"`
ExecutionContext *ExecutionContext `json:"execution_context,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
}

// NetworkSecurityRuleIntentResponse Response object for intentful operations on a network_security_rule
type NetworkSecurityRuleIntentResponse struct {
APIVersion *string `json:"api_version,omitempty"`
Metadata *Metadata `json:"metadata"`
Spec *NetworkSecurityRule `json:"spec,omitempty"`
Status NetworkSecurityRuleDefStatus `json:"status,omitempty" bson:"status,omitempty"`
APIVersion *string `json:"api_version,omitempty"`
Metadata *Metadata `json:"metadata"`
Spec *NetworkSecurityRule `json:"spec,omitempty"`
Status *NetworkSecurityRuleDefStatus `json:"status,omitempty"`
}

// NetworkSecurityRuleStatus The status of a REST API call. Only used when there is a failure to report.
Expand Down
80 changes: 40 additions & 40 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
port = 9440
} */

data "nutanix_clusters" "clusters" {}
data "nutanix_clusters" "clusters" {
}

### Define Script Local Variables
### This can be used for any manner of things, but is useful for like clusterid,
### to store a mapping of targets for provisioning
### TODO: Need to make clusters a data source object, such that consumers do
### not need to manually provision cluster ID
locals {
cluster1 = "${data.nutanix_clusters.clusters.entities.1.metadata.uuid}"
cluster1 = data.nutanix_clusters.clusters.entities[1].metadata.uuid
}

##########################
Expand All @@ -55,28 +56,28 @@ locals {
### state files, or deploying terraform into an existing / brownfield environment
### Virtual Machine Data Sources
# data "nutanix_virtual_machine" "nutanix_virtual_machine" {
# vm_id = "${nutanix_virtual_machine.vm1.id}"
# vm_id = nutanix_virtual_machine.vm1.id
# }
### Image Data Sources
# data "nutanix_image" "test" {
# metadata = {
# kind = "image"
# }
# image_id = "${nutanix_image.test.id}"
# image_id = nutanix_image.test.id
# }
### Subnet Data Sources
# data "nutanix_subnet" "next-iac-managed" {
# metadata = {
# kind = "subnet"
# }
# image_id = "${nutanix_subnet.next-iac-managed.id}"
# image_id = nutanix_subnet.next-iac-managed.id
#}
### Cluster Data Sources
#data "nutanix_image" "test" {
# metadata = {
# kind = "image"
# }
# image_id = "${nutanix_image.test.id}"
# image_id = nutanix_image.test.id
#}
##########################
### Resources
Expand Down Expand Up @@ -147,7 +148,7 @@ resource "nutanix_image" "cirros-034-disk" {
# ### Define Terraform Managed Subnets
resource "nutanix_subnet" "infra-managed-network-140" {
# What cluster will this VLAN live on?
cluster_uuid = "${local.cluster1}"
cluster_uuid = local.cluster1

# General Information
name = "infra-managed-network-140"
Expand All @@ -156,18 +157,18 @@ resource "nutanix_subnet" "infra-managed-network-140" {

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

default_gateway_ip = "172.21.32.1"
prefix_length = 24

dhcp_options {
dhcp_options = {
boot_file_name = "bootfile"
domain_name = "ntnxlab"
tftp_server_name = "172.21.32.200"
}

dhcp_server_address {
dhcp_server_address = {
ip = "172.21.32.254"
}

Expand Down Expand Up @@ -195,56 +196,54 @@ resource "nutanix_virtual_machine" "demo-01-web" {
memory_size_mib = 4096

# What cluster will this VLAN live on?
cluster_uuid = "${local.cluster1}"
cluster_uuid = local.cluster1

# What networks will this be attached to?
nic_list = [{
nic_list {
# subnet_reference is saying, which VLAN/network do you want to attach here?
subnet_uuid = "${nutanix_subnet.infra-managed-network-140.id}"

subnet_uuid = nutanix_subnet.infra-managed-network-140.id
# Used to set static IP.
# ip_endpoint_list = {
# ip = "172.21.32.20"
# type = "ASSIGNED"
# }
}]
# ip_endpoint_list {
# ip = "172.21.32.20"
# type = "ASSIGNED"
# }
}

# What disk/cdrom configuration will this have?
disk_list = [{
disk_list {
# data_source_reference in the Nutanix API refers to where the source for
# the disk device will come from. Could be a clone of a different VM or a
# image like we're doing here
data_source_reference = [{
kind = "image"
uuid = "${nutanix_image.cirros-034-disk.id}"
}]
data_source_reference = {
kind = "image"
uuid = nutanix_image.cirros-034-disk.id
}


device_properties = [{
disk_address {
device_properties {
disk_address = {
device_index = 0
adapter_type = "SCSI"
}

device_type = "DISK"
}]
},
{
# defining an additional entry in the disk_list array will create another.

#disk_size_mib and disk_size_bytes must be set together.
disk_size_mib = 100000
disk_size_bytes = 104857600000
},
]
}
}
disk_list {
# defining an additional entry in the disk_list array will create another.

#disk_size_mib and disk_size_bytes must be set together.
disk_size_mib = 100000
disk_size_bytes = 104857600000
}
#Using provisioners
#Use as the following provisioner block if you know that you are geeting an reachable IP address.
#Get ssh connection and execute commands.
# provisioner "remote-exec" {
# connection {
# user = "cirros" # user from the image attached
# password = "cubswin:)" #password from the user
# #host = "172.21.32.20" #Set if you know
# host = "172.21.32.20" #host is now a required value for connection, you can use `self.nic_list_status[0].ip_endpoint_list[0].ip` to set the IP or if you know the IP you could set manually.
# }

# inline = [
Expand All @@ -254,6 +253,7 @@ resource "nutanix_virtual_machine" "demo-01-web" {
}

# Show IP address
output "ip_address" {
value = "${lookup(nutanix_virtual_machine.demo-01-web.nic_list_status.0.ip_endpoint_list[0], "ip")}"
}
output "ip_address" {
value = nutanix_virtual_machine.demo-01-web.nic_list_status.0.ip_endpoint_list[0]["ip"]
}

Loading