-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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 resource: dedicated_host_group (compute) #5048
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,101 @@ | ||||||
package azurerm | ||||||
|
||||||
import ( | ||||||
"fmt" | ||||||
|
||||||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||||||
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||||||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||||||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||||||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||||||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||||||
) | ||||||
|
||||||
func dataSourceArmDedicatedHostGroup() *schema.Resource { | ||||||
return &schema.Resource{ | ||||||
Read: dataSourceArmDedicatedHostGroupRead, | ||||||
|
||||||
Schema: map[string]*schema.Schema{ | ||||||
"name": { | ||||||
Type: schema.TypeString, | ||||||
Required: true, | ||||||
ValidateFunc: validate.NoEmptyStrings, | ||||||
}, | ||||||
|
||||||
"location": azure.SchemaLocationForDataSource(), | ||||||
|
||||||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||||||
|
||||||
"hosts": { | ||||||
Type: schema.TypeList, | ||||||
Computed: true, | ||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
"id": { | ||||||
Type: schema.TypeString, | ||||||
Computed: true, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
|
||||||
"platform_fault_domain_count": { | ||||||
Type: schema.TypeInt, | ||||||
Computed: true, | ||||||
}, | ||||||
|
||||||
"type": { | ||||||
Type: schema.TypeString, | ||||||
Computed: true, | ||||||
}, | ||||||
|
||||||
"zones": { | ||||||
Type: schema.TypeList, | ||||||
Computed: true, | ||||||
Elem: &schema.Schema{ | ||||||
Type: schema.TypeString, | ||||||
}, | ||||||
}, | ||||||
|
||||||
"tags": tags.SchemaDataSource(), | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
func dataSourceArmDedicatedHostGroupRead(d *schema.ResourceData, meta interface{}) error { | ||||||
client := meta.(*ArmClient).Compute.DedicatedHostGroupsClient | ||||||
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d) | ||||||
defer cancel() | ||||||
|
||||||
name := d.Get("name").(string) | ||||||
resourceGroupName := d.Get("resource_group_name").(string) | ||||||
|
||||||
resp, err := client.Get(ctx, resourceGroupName, name) | ||||||
if err != nil { | ||||||
if utils.ResponseWasNotFound(resp.Response) { | ||||||
return fmt.Errorf("Error: Dedicated Host Group %q (Resource Group %q) was not found", name, resourceGroupName) | ||||||
} | ||||||
return fmt.Errorf("Error reading Dedicated Host Group %q (Resource Group %q): %+v", name, resourceGroupName, err) | ||||||
} | ||||||
|
||||||
d.SetId(*resp.ID) | ||||||
|
||||||
d.Set("name", name) | ||||||
d.Set("resource_group_name", resourceGroupName) | ||||||
if location := resp.Location; location != nil { | ||||||
d.Set("location", azure.NormalizeLocation(*location)) | ||||||
} | ||||||
if dedicatedHostGroupProperties := resp.DedicatedHostGroupProperties; dedicatedHostGroupProperties != nil { | ||||||
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. minor we typically use a shorter name here
Suggested change
|
||||||
if err := d.Set("hosts", flattenArmDedicatedHostGroupSubResourceReadOnly(dedicatedHostGroupProperties.Hosts)); err != nil { | ||||||
return fmt.Errorf("Error setting `hosts`: %+v", err) | ||||||
} | ||||||
d.Set("platform_fault_domain_count", int(*dedicatedHostGroupProperties.PlatformFaultDomainCount)) | ||||||
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. we don't need to deref and convert for top level properties
Suggested change
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. Why is that? I assume a |
||||||
} | ||||||
d.Set("type", resp.Type) | ||||||
if resp.Zones != nil { | ||||||
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 think the flatten function does this check? |
||||||
d.Set("zones", utils.FlattenStringSlice(resp.Zones)) | ||||||
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. Could we check for an error here? |
||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMDedicatedHostGroup_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_dedicated_host_group.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
rName := acctest.RandStringFromCharSet(4, acctest.CharSetAlpha) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceDedicatedHostGroup_basic(ri, location, rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMDedicatedHostGroupExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "zones.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "zones.0", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "platform_fault_domain_count", "2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceDedicatedHostGroup_basic(rInt int, location string, rName string) string { | ||
config := testAccAzureRMDedicatedHostGroup_complete(rInt, location, rName) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_dedicated_host_group" "test" { | ||
resource_group_name = "${azurerm_dedicated_host_group.test.resource_group_name}" | ||
name = "${azurerm_dedicated_host_group.test.name}" | ||
} | ||
`, config) | ||
} |
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.
I don't; think this makes sense for terraform?