-
Notifications
You must be signed in to change notification settings - Fork 112
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
Org VDC import, data source and read fix #324
Changes from 39 commits
6585559
e247d25
cf1e7c2
be6790f
6f4c5cb
c73d402
261d142
c431d43
414b3bf
8b03ab8
36c5487
db397a2
9180dc2
db01eec
638d286
4db6be4
558c726
7875bfd
0eac92d
c232e4f
c2ea184
cc66000
8270605
69a1307
1383c19
81e1e2b
8af6b38
f40293f
c5c829a
5b3da56
4325821
e12e4d3
331e895
87be04c
9f643aa
4d67b97
71e54a1
af69dbf
1de8c02
e0dad07
7a6bd51
847e4d8
c46bb79
d2468fb
72adf38
7b87d2b
83a9b0f
f6bfd64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,3 +154,21 @@ func getMajorVersion() string { | |
// Where the first element is the full text matched, and the second one is the first captured text | ||
return versionList[0][1] | ||
} | ||
|
||
// getHashValuesFromKey returns the hash values of a TypeSet Key | ||
// Given "parent.1234.child.5678.something", it will return "1234" and "5678" | ||
// for Example: compute_capacity.315866465.memory.508945747.limit | ||
// (returns 315866465 and 508945747) | ||
// Warning this function works fine when there is only one key with parent | ||
func getHashValuesFromKey(stateFileMap map[string]string, parentKey, childKey string) (string, string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a warning and explanation on how function deals with situations where there are more than one instance of the TypeSet element. In E.g.:
Finally, more and more it seems that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added warning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When you say "should", you mean we should change it? Because right now it's:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess now this gets to a question if this is used at all. Although it may come in handy in some other place in future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
|
||
var searchPattern = regexp.MustCompile(parentKey + `\.(\d+)\.` + childKey + `\.(\d+)\.\w+`) | ||
for k, _ := range stateFileMap { | ||
foundList := searchPattern.FindAllStringSubmatch(k, -1) | ||
if len(foundList) > 0 && len(foundList[0]) > 0 { | ||
return foundList[0][1], foundList[0][2], nil | ||
} | ||
} | ||
|
||
return "", "", fmt.Errorf("error extracting hashes from '%s', err %s", parentKey, childKey) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
package vcd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func datasourceVcdOrgVdc() *schema.Resource { | ||
capacityWithUsage := schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
MinItems: 1, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"allocated": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Capacity that is committed to be available. Value in MB or MHz. Used with AllocationPool (Allocation pool) and ReservationPool (Reservation pool).", | ||
}, | ||
"limit": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Capacity limit relative to the value specified for Allocation. It must not be less than that value. If it is greater than that value, it implies over provisioning. A value of 0 specifies unlimited units. Value in MB or MHz. Used with AllocationVApp (Pay as you go).", | ||
}, | ||
"reserved": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"used": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"overhead": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
Read: datasourceVcdOrgVdcRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"org": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Organization to create the VDC in", | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"allocation_model": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The allocation model used by this VDC; must be one of {AllocationVApp, AllocationPool, ReservationPool}", | ||
}, | ||
"compute_capacity": &schema.Schema{ | ||
Computed: true, | ||
MinItems: 1, | ||
MaxItems: 1, | ||
Type: schema.TypeList, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"cpu": &capacityWithUsage, | ||
"memory": &capacityWithUsage, | ||
}, | ||
}, | ||
Description: "The compute capacity allocated to this VDC.", | ||
}, | ||
"nic_quota": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Maximum number of virtual NICs allowed in this VDC. Defaults to 0, which specifies an unlimited number.", | ||
}, | ||
"network_quota": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Maximum number of network objects that can be deployed in this VDC. Defaults to 0, which means no networks can be deployed.", | ||
}, | ||
"vm_quota": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The maximum number of VMs that can be created in this VDC. Includes deployed and undeployed VMs in vApps and vApp templates. Defaults to 0, which specifies an unlimited number.", | ||
}, | ||
"enabled": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if this VDC is enabled for use by the organization VDCs. Default is true.", | ||
}, | ||
"storage_profile": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Computed: true, | ||
MinItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Name of Provider VDC storage profile.", | ||
}, | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if this storage profile is enabled for use in the VDC.", | ||
}, | ||
"limit": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Maximum number of MB allocated for this storage profile. A value of 0 specifies unlimited MB.", | ||
}, | ||
"default": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if this is default storage profile for this VDC. The default storage profile is used when an object that can specify a storage profile is created with no storage profile specified.", | ||
}, | ||
}, | ||
}, | ||
Description: "Storage profiles supported by this VDC.", | ||
}, | ||
"memory_guaranteed": &schema.Schema{ | ||
Type: schema.TypeFloat, | ||
Computed: true, | ||
Description: "Percentage of allocated memory resources guaranteed to vApps deployed in this VDC. " + | ||
"For example, if this value is 0.75, then 75% of allocated resources are guaranteed. " + | ||
"Required when AllocationModel is AllocationVApp or AllocationPool. When Allocation model is AllocationPool minimum value is 0.2. If the element is empty, vCD sets a value.", | ||
}, | ||
"cpu_guaranteed": &schema.Schema{ | ||
Type: schema.TypeFloat, | ||
Computed: true, | ||
Description: "Percentage of allocated CPU resources guaranteed to vApps deployed in this VDC. " + | ||
"For example, if this value is 0.75, then 75% of allocated resources are guaranteed. " + | ||
"Required when AllocationModel is AllocationVApp or AllocationPool. If the element is empty, vCD sets a value", | ||
}, | ||
"cpu_speed": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Specifies the clock frequency, in Megahertz, for any virtual CPU that is allocated to a VM. A VM with 2 vCPUs will consume twice as much of this value. Ignored for ReservationPool. Required when AllocationModel is AllocationVApp or AllocationPool, and may not be less than 256 MHz. Defaults to 1000 MHz if the element is empty or missing.", | ||
}, | ||
"enable_thin_provisioning": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Boolean to request thin provisioning. Request will be honored only if the underlying datastore supports it. Thin provisioning saves storage space by committing it on demand. This allows over-allocation of storage.", | ||
}, | ||
"network_pool_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The name of a network pool in the Provider VDC. Required if this VDC will contain routed or isolated networks.", | ||
}, | ||
"provider_vdc_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "A reference to the Provider VDC from which this organization VDC is provisioned.", | ||
}, | ||
"enable_fast_provisioning": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Request for fast provisioning. Request will be honored only if the underlying datas tore supports it. Fast provisioning can reduce the time it takes to create virtual machines by using vSphere linked clones. If you disable fast provisioning, all provisioning operations will result in full clones.", | ||
}, | ||
// Always null in the response to a GET request. On update, set to false to disallow the update if the AllocationModel is AllocationPool or ReservationPool | ||
// and the ComputeCapacity you specified is greater than what the backing Provider VDC can supply. Defaults to true if empty or missing. | ||
"allow_over_commit": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Set to false to disallow creation of the VDC if the AllocationModel is AllocationPool or ReservationPool and the ComputeCapacity you specified is greater than what the backing Provider VDC can supply. Default is true.", | ||
}, | ||
"enable_vm_discovery": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "True if discovery of vCenter VMs is enabled for resource pools backing this VDC. If left unspecified, the actual behaviour depends on enablement at the organization level and at the system level.", | ||
}, | ||
"metadata": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Description: "Key and value pairs for Org VDC metadata", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceVcdOrgVdcRead(d *schema.ResourceData, meta interface{}) error { | ||
dataclouder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vcdClient := meta.(*VCDClient) | ||
|
||
adminOrg, err := vcdClient.GetAdminOrgFromResource(d) | ||
if err != nil { | ||
return fmt.Errorf(errorRetrievingOrg, err) | ||
} | ||
|
||
adminVdc, err := adminOrg.GetAdminVDCByName(d.Get("name").(string), false) | ||
if err != nil { | ||
log.Printf("[DEBUG] Unable to find VDC") | ||
return fmt.Errorf("unable to find VDC %s", err) | ||
} | ||
|
||
d.SetId(adminVdc.AdminVdc.ID) | ||
|
||
return setOrgVdcData(d, vcdClient, adminOrg, adminVdc) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting it gets the "read" capability as someone may be surprised getting changes after regular
terraform apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add note