-
Notifications
You must be signed in to change notification settings - Fork 453
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
New data source: vsphere_tag_category #167
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package vsphere | ||
|
||
import "github.com/hashicorp/terraform/helper/schema" | ||
|
||
func dataSourceVSphereTagCategory() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceVSphereTagCategoryRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "The display name of the category.", | ||
Required: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The description of the category.", | ||
}, | ||
"cardinality": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The associated cardinality of the category. Can be one of SINGLE (object can only be assigned one tag in this category) or MULTIPLE (object can be assigned multiple tags in this category).", | ||
}, | ||
"associable_types": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Description: "Object types to which this category's tags can be attached.", | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVSphereTagCategoryRead(d *schema.ResourceData, meta interface{}) error { | ||
client, err := meta.(*VSphereClient).TagsClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id, err := tagCategoryByName(client, d.Get("name").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(id) | ||
return resourceVSphereTagCategoryRead(d, meta) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package vsphere | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceVSphereTagCategory(t *testing.T) { | ||
var tp *testing.T | ||
testAccDataSourceVSphereTagCategoryCases := []struct { | ||
name string | ||
testCase resource.TestCase | ||
}{ | ||
{ | ||
"basic", | ||
resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(tp) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceVSphereTagCategoryConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.vsphere_tag_category.terraform-test-category-data", | ||
"name", | ||
testAccDataSourceVSphereTagCategoryConfigName, | ||
), | ||
resource.TestCheckResourceAttr( | ||
"data.vsphere_tag_category.terraform-test-category-data", | ||
"description", | ||
testAccDataSourceVSphereTagCategoryConfigDescription, | ||
), | ||
resource.TestCheckResourceAttr( | ||
"data.vsphere_tag_category.terraform-test-category-data", | ||
"cardinality", | ||
testAccDataSourceVSphereTagCategoryConfigCardinality, | ||
), | ||
resource.TestCheckResourceAttr( | ||
"data.vsphere_tag_category.terraform-test-category-data", | ||
"associable_types.#", | ||
"1", | ||
), | ||
resource.TestCheckResourceAttr( | ||
"data.vsphere_tag_category.terraform-test-category-data", | ||
"associable_types.3125094965", | ||
testAccDataSourceVSphereTagCategoryConfigAssociableType, | ||
), | ||
resource.TestCheckResourceAttrPair( | ||
"data.vsphere_tag_category.terraform-test-category-data", "id", | ||
"vsphere_tag_category.terraform-test-category", "id", | ||
), | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testAccDataSourceVSphereTagCategoryCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tp = t | ||
resource.Test(t, tc.testCase) | ||
}) | ||
} | ||
} | ||
|
||
const testAccDataSourceVSphereTagCategoryConfigName = "terraform-test-category" | ||
const testAccDataSourceVSphereTagCategoryConfigDescription = "Managed by Terraform" | ||
const testAccDataSourceVSphereTagCategoryConfigCardinality = vSphereTagCategoryCardinalitySingle | ||
const testAccDataSourceVSphereTagCategoryConfigAssociableType = vSphereTagCategoryAssociableTypeVirtualMachine | ||
|
||
func testAccDataSourceVSphereTagCategoryConfig() string { | ||
return fmt.Sprintf(` | ||
variable "tag_category_name" { | ||
default = "%s" | ||
} | ||
|
||
variable "tag_category_description" { | ||
default = "%s" | ||
} | ||
|
||
variable "tag_category_cardinality" { | ||
default = "%s" | ||
} | ||
|
||
variable "tag_category_associable_types" { | ||
default = [ | ||
"%s", | ||
] | ||
} | ||
|
||
resource "vsphere_tag_category" "terraform-test-category" { | ||
name = "${var.tag_category_name}" | ||
description = "${var.tag_category_description}" | ||
cardinality = "${var.tag_category_cardinality}" | ||
|
||
associable_types = [ | ||
"${var.tag_category_associable_types}", | ||
] | ||
} | ||
|
||
data "vsphere_tag_category" "terraform-test-category-data" { | ||
name = "${vsphere_tag_category.terraform-test-category.name}" | ||
} | ||
`, | ||
testAccDataSourceVSphereTagCategoryConfigName, | ||
testAccDataSourceVSphereTagCategoryConfigDescription, | ||
testAccDataSourceVSphereTagCategoryConfigCardinality, | ||
testAccDataSourceVSphereTagCategoryConfigAssociableType, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
layout: "vsphere" | ||
page_title: "VMware vSphere: vsphere_tag_category" | ||
sidebar_current: "docs-vsphere-data-source-tag-category" | ||
description: |- | ||
Provides a vSphere tag category data source. This can be used to reference tag categories not managed in Terraform. | ||
--- | ||
|
||
# vsphere\_tag\_category | ||
|
||
The `vsphere_tag_category` data source can be used to reference tag categories | ||
that are not managed by Terraform. Its attributes are exactly the same as the | ||
[`vsphere_tag_category` resource][resource-tag-category], and, like importing, | ||
the data source takes a name to search on. The `id` and other attributes are | ||
then populated with the data found by the search. | ||
|
||
[resource-tag-category]: /docs/providers/vsphere/r/tag_category.html | ||
|
||
~> **NOTE:** Tagging support is unsupported on direct ESXi connections and | ||
requires vCenter 6.0 or higher. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "vsphere_tag_category" "category" { | ||
name = "terraform-test-category" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (String, required) The name of the tag category. | ||
|
||
## Attribute Reference | ||
|
||
In addition to the `id` being exported, all of the fields that are available in | ||
the [`vsphere_tag_category` resource][resource-tag-category] are also | ||
populated. See that page for further details. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thoughts about linking that page?
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.
It is linked - just above as it's the same link 🙂