Skip to content

Commit

Permalink
Site and Org associations (vmware#1260)
Browse files Browse the repository at this point in the history
* Add Data Source vcd_multisite_site to read the state and associations of current site 
* Add Data Source vcd_multisite_site_data to produce the association data needed to start a site association
* Add Data Source vcd_multisite_site_association to read the details of a site association
* Add Resource vcd_multisite_site_association  to associate the current site with a remote one
* Add Data Source vcd_multisite_org_data to produce the association data needed to start an organization association
* Add Data Source vcd_multisite_org_association to read the details of an organization association
* Add Resource vcd_multisite_org_association to associate a local organization with a remote one 
* Add Guide "Site and Org associations" to describe association operations for sites and organizations
* Update vcd_resource_list for site and org associations
* Add site-all-at-once example
* Add org-all-at-once example
* Add comprehensive test for site and Org association 
* Add documentation
* Update DataSourceNotFound test
* Add Changelog entries
* Add import test for multisite resources

---------

Signed-off-by: Giuseppe Maxia <[email protected]>
  • Loading branch information
dataclouder authored Jun 24, 2024
1 parent 3fcac89 commit 8334ce4
Show file tree
Hide file tree
Showing 42 changed files with 2,500 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changes/v3.13.0/1260-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* **New Data Source:** `vcd_multisite_site` to read the state and associations of current site [GH-1260]
* **New Data Source:** `vcd_multisite_site_data` to produce the association data needed to start a site association [GH-1260]
* **New Data Source:** `vcd_multisite_site_association` to read the details of a site association [GH-1260]
* **New Resource:** `vcd_multisite_site_association` to associate the current site with a remote one [GH-1260]
* **New Data Source:** `vcd_multisite_org_data` to produce the association data needed to start an organization association [GH-1260]
* **New Data Source:** `vcd_multisite_org_association` to read the details of an organization association [GH-1260]
* **New Resource:** `vcd_multisite_org_association` to associate a local organization with a remote one [GH-1260]
* **New Guide** `Site and Org associations` to describe association operations for sites and organizations [GH-1260]
1 change: 1 addition & 0 deletions .changes/v3.13.0/1260-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Data source `vcd_resource_list` can now list site and organization associations [GH-1260]
3 changes: 3 additions & 0 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ jobs:

- name: test
run: make test

- name: tags
run: make tagverify
61 changes: 61 additions & 0 deletions examples/multi-site/org-all-at-once/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
provider "vcd" {
user = var.vcd_admin
password = var.vcd_password
token = ""
api_token = ""
auth_type = "integrated"
saml_adfs_rpt_id = ""
url = var.vcd_url
sysorg = var.vcd_sysorg
org = var.vcd_org1
allow_unverified_ssl = "true"
max_retry_timeout = 600
logging = true
logging_file = "go-vcloud-director.log"
}

data "vcd_org" "org1" {
name = var.vcd_org1
}
data "vcd_org" "org2" {
name = var.vcd_org2
}

data "vcd_multisite_org_data" "org1-data" {
org_id = data.vcd_org.org1.id
}

data "vcd_multisite_org_data" "org2-data" {
org_id = data.vcd_org.org2.id
}

data "vcd_resource_list" "orgs" {
name = "org_associations"
resource_type = "vcd_multisite_org_association"
list_mode = "name_id"
}

resource "vcd_multisite_org_association" "org1-org2" {
org_id = data.vcd_org.org1.id
association_data = data.vcd_multisite_org_data.org2-data.association_data
connection_timeout_mins = 2
}

resource "vcd_multisite_org_association" "org2-org1" {
org_id = data.vcd_org.org2.id
association_data = data.vcd_multisite_org_data.org1-data.association_data
connection_timeout_mins = 2
}

output "org2-org1" {
value = vcd_multisite_org_association.org2-org1
}


output "org1-org2" {
value = vcd_multisite_org_association.org1-org2
}

output "org_associations" {
value = data.vcd_resource_list.orgs
}
7 changes: 7 additions & 0 deletions examples/multi-site/org-all-at-once/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Rename this file to 'terraform.tfvars' and update the variables to their intended values
vcd_url = "https://example1.com/api"
vcd_admin = "administrator"
vcd_password = "myPassword"
vcd_sysorg = "System"
vcd_org1 = "nameOfMyOrg"
vcd_org2 = "nameOfMyOtherOrg"
26 changes: 26 additions & 0 deletions examples/multi-site/org-all-at-once/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

variable "vcd_url" {
type = string
}

variable "vcd_admin" {
type = string
default = "administrator"
}

variable "vcd_sysorg" {
type = string
default = "System"
}

variable "vcd_password" {
type = string
}

variable "vcd_org1" {
type = string
}

variable "vcd_org2" {
type = string
}
9 changes: 9 additions & 0 deletions examples/multi-site/org-all-at-once/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
vcd = {
source = "vmware/vcd"
version = ">=3.13.0"
}
}
}

45 changes: 45 additions & 0 deletions examples/multi-site/site-all-at-once/config1.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
provider "vcd" {
alias = "vcd1"
user = var.vcd_admin1
password = var.vcd_password1
token = ""
api_token = ""
auth_type = "integrated"
saml_adfs_rpt_id = ""
url = var.vcd_url1
sysorg = var.vcd_sysorg1
org = var.vcd_org1
allow_unverified_ssl = "true"
max_retry_timeout = 600
logging = true
logging_file = "go-vcloud-director-1.log"
}

data "vcd_org" "org1" {
provider = vcd.vcd1
name = var.vcd_org1
}

data "vcd_multisite_org_data" "org1-data" {
provider = vcd.vcd1
org_id = data.vcd_org.org1.id
download_to_file = "${var.vcd_org1}.xml"
}

data "vcd_multisite_site_data" "site1-data" {
provider = vcd.vcd1
download_to_file = "${var.site_name1}-site.xml"
}

# The data files are needed because the data will be read by resources handled by a different user, which can't read
# directly the data source that is the origin of these files

data "local_file" "site1" {
filename = "${var.site_name1}-site.xml"
depends_on = [data.vcd_multisite_site_data.site1-data]
}

data "local_file" "org1" {
filename = "${var.vcd_org1}.xml"
depends_on = [data.vcd_multisite_org_data.org1-data]
}
43 changes: 43 additions & 0 deletions examples/multi-site/site-all-at-once/config1a.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

data "vcd_resource_list" "sites" {
provider = vcd.vcd1
name = "site_associations"
resource_type = "vcd_multisite_site_association"
list_mode = "name_id"
}

data "vcd_resource_list" "orgs" {
provider = vcd.vcd1
name = "org_associations"
resource_type = "vcd_multisite_org_association"
list_mode = "name_id"
}

resource "vcd_multisite_site_association" "site1-site2" {
provider = vcd.vcd1
association_data = data.local_file.site2.content
connection_timeout_mins = 2
}

resource "vcd_multisite_org_association" "org1-org2" {
provider = vcd.vcd1
org_id = data.vcd_org.org1.id
association_data = data.local_file.org2.content
connection_timeout_mins = 2
depends_on = [vcd_multisite_site_association.site1-site2]
}

output "site1-site2" {
value = vcd_multisite_site_association.site1-site2
}

output "org1-org2" {
value = vcd_multisite_org_association.org1-org2
}

output "site_associations" {
value = data.vcd_resource_list.sites
}
output "org_associations" {
value = data.vcd_resource_list.orgs
}
45 changes: 45 additions & 0 deletions examples/multi-site/site-all-at-once/config2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
provider "vcd" {
alias = "vcd2"
user = var.vcd_admin2
password = var.vcd_password2
token = ""
api_token = ""
auth_type = "integrated"
saml_adfs_rpt_id = ""
url = var.vcd_url2
sysorg = var.vcd_sysorg2
org = var.vcd_org2
allow_unverified_ssl = "true"
max_retry_timeout = 600
logging = true
logging_file = "go-vcloud-director-2.log"
}

data "vcd_org" "org2" {
provider = vcd.vcd2
name = var.vcd_org2
}

data "vcd_multisite_org_data" "org2-data" {
provider = vcd.vcd2
org_id = data.vcd_org.org2.id
download_to_file = "${var.vcd_org2}.xml"
}

data "vcd_multisite_site_data" "site2-data" {
provider = vcd.vcd2
download_to_file = "${var.site_name2}-site.xml"
}

# The data files are needed because the data will be read by resources handled by a different user, which can't read
# directly the data source that is the origin of these files

data "local_file" "site2" {
filename = "${var.site_name2}-site.xml"
depends_on = [data.vcd_multisite_site_data.site2-data]
}

data "local_file" "org2" {
filename = "${var.vcd_org2}.xml"
depends_on = [data.vcd_multisite_org_data.org2-data]
}
22 changes: 22 additions & 0 deletions examples/multi-site/site-all-at-once/config2a.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

resource "vcd_multisite_site_association" "site2-site1" {
provider = vcd.vcd2
association_data = data.local_file.site1.content
connection_timeout_mins = 2
}

resource "vcd_multisite_org_association" "org2-org1" {
provider = vcd.vcd2
org_id = data.vcd_org.org2.id
association_data = data.local_file.org1.content
connection_timeout_mins = 2
depends_on = [vcd_multisite_site_association.site2-site1]
}

output "site2-site1" {
value = vcd_multisite_site_association.site2-site1
}

output "org2-org1" {
value = vcd_multisite_org_association.org2-org1
}
14 changes: 14 additions & 0 deletions examples/multi-site/site-all-at-once/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Rename this file to 'terraform.tfvars' and update the variables to their intended values
vcd_site_name1 = "SITE1"
vcd_url1 = "https://example1.com/api"
vcd_admin1 = "administrator"
vcd_password1 = "myPassword"
vcd_sysorg1 = "System"
vcd_org1 = "nameOfMyOrg"

vcd_site_name2 = "SITE2"
vcd_url2 = "https://example2.com/api"
vcd_admin2 = "administrator"
vcd_password2 = "anotherPassword"
vcd_sysorg2 = "System"
vcd_org2 = "nameOfMyOtherOrg"
62 changes: 62 additions & 0 deletions examples/multi-site/site-all-at-once/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

# -----------------------
# site 1
# -----------------------

variable "site_name1" {
type = string
default = "site1"
}

variable "vcd_url1" {
type = string
}

variable "vcd_admin1" {
type = string
default = "administrator"
}

variable "vcd_sysorg1" {
type = string
default = "System"
}

variable "vcd_password1" {
type = string
}

variable "vcd_org1" {
type = string
}

# -----------------------
# site 2
# -----------------------

variable "site_name2" {
type = string
default = "site2"
}

variable "vcd_url2" {
type = string
}

variable "vcd_admin2" {
type = string
default = "administrator"
}

variable "vcd_sysorg2" {
type = string
default = "System"
}

variable "vcd_password2" {
type = string
}

variable "vcd_org2" {
type = string
}
9 changes: 9 additions & 0 deletions examples/multi-site/site-all-at-once/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
vcd = {
source = "vmware/vcd"
version = ">=3.13.0"
}
}
}

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/kr/pretty v0.3.1
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.14
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.15
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.14 h1:yHY0U8bweiVqhCR3OP0ItNdMSLPXeE7uudpXeDZbH/8=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.14/go.mod h1:vbuNYzuADDBFhi9i2dIKWeNxMK1VFF0dACq01amYBIM=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.15 h1:gpTFXt/EBKqf5V2W2t7imCYZW6ruu6NJ9VY3PNXnR6c=
github.com/vmware/go-vcloud-director/v2 v2.25.0-alpha.15/go.mod h1:vbuNYzuADDBFhi9i2dIKWeNxMK1VFF0dACq01amYBIM=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
2 changes: 1 addition & 1 deletion vcd/common_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build network || nsxt || gateway || org || catalog || access_control || networkPool || providerVdc || vm || vapp || standaloneVm || user || ALL || functional
//go:build network || nsxt || gateway || org || catalog || access_control || networkPool || providerVdc || vm || vapp || standaloneVm || user || multisite || ALL || functional

package vcd

Expand Down
Loading

0 comments on commit 8334ce4

Please sign in to comment.