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

[Refactoring] Devspace Controller #2182

Merged
merged 11 commits into from
Oct 31, 2018
29 changes: 29 additions & 0 deletions azurerm/helpers/validate/base64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package validate

import (
"encoding/base64"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func Base64String() schema.SchemaValidateFunc {
return func(i interface{}, k string) (s []string, es []error) {
// Empty string is not allowed
if s, es = validation.NoZeroValues(i, k); len(es) > 0 {
return
}

v, ok := i.(string)
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be string", k))
return
}

if _, err := base64.StdEncoding.DecodeString(v); err != nil {
es = append(es, fmt.Errorf("expect value (%s) of %s is base64 string", v, k))
}

return
}
}
35 changes: 35 additions & 0 deletions azurerm/helpers/validate/base64_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package validate

import (
"testing"
)

func TestBase64String(t *testing.T) {
cases := []struct {
Input string
Errors int
}{
{
Input: "",
Errors: 1,
},
{
Input: "aGVsbG8td29ybGQ=",
Errors: 0,
},
{
Input: "hello-world",
Errors: 1,
},
}

for _, tc := range cases {
t.Run(tc.Input, func(t *testing.T) {
_, errors := Base64String()(tc.Input, "base64")

if len(errors) != tc.Errors {
t.Fatalf("Expected Base64 string to have %d not %d errors for %q: %v", tc.Errors, len(errors), tc.Input, errors)
}
})
}
}
30 changes: 15 additions & 15 deletions azurerm/resource_arm_devspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceArmDevSpaceController() *schema.Resource {
Required: true,
ForceNew: true,
Sensitive: true,
ValidateFunc: validation.NoZeroValues,
ValidateFunc: validate.Base64String(),
},

"tags": tagsSchema(),
Expand Down Expand Up @@ -162,7 +162,7 @@ func resourceArmDevSpaceControllerRead(d *schema.ResourceData, meta interface{})
return nil
}

return fmt.Errorf("Error making Read request on DevSpace Controller Lab %q (Resource Group %q): %+v", name, resGroupName, err)
return fmt.Errorf("Error making Read request on DevSpace Controller %q (Resource Group %q): %+v", name, resGroupName, err)
}

d.Set("name", result.Name)
Expand All @@ -171,21 +171,19 @@ func resourceArmDevSpaceControllerRead(d *schema.ResourceData, meta interface{})
d.Set("location", azureRMNormalizeLocation(*location))
}

d.Set("sku", flattenDevSpaceControllerSku(result.Sku))
if err := d.Set("sku", flattenDevSpaceControllerSku(result.Sku)); err != nil {
return fmt.Errorf("Error flattenning Sku for DevSpace Controller %q (Resource Group %q): %+v", name, resGroupName, err)
metacpp marked this conversation as resolved.
Show resolved Hide resolved
}

var hostSuffix, dataPlaneFqdn, targetContainerHostResourceID *string
if props := result.ControllerProperties; props != nil {
if props.HostSuffix != nil {
d.Set("host_suffix", props.HostSuffix)
}

if props.DataPlaneFqdn != nil {
d.Set("data_plane_fqdn", props.DataPlaneFqdn)
}

if props.TargetContainerHostResourceID != nil {
d.Set("target_container_host_resource_id", props.TargetContainerHostResourceID)
}
hostSuffix = props.HostSuffix
dataPlaneFqdn = props.DataPlaneFqdn
targetContainerHostResourceID = props.TargetContainerHostResourceID
}
d.Set("host_suffix", hostSuffix)
d.Set("data_plane_fqdn", dataPlaneFqdn)
d.Set("target_container_host_resource_id", targetContainerHostResourceID)
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved

flattenAndSetTags(d, result.Tags)

Expand Down Expand Up @@ -264,7 +262,9 @@ func flattenDevSpaceControllerSku(skuObj *devspaces.Sku) []interface{} {
}

skuConfig := make(map[string]interface{}, 0)
skuConfig["name"] = *skuObj.Name
if skuObj.Name != nil {
skuConfig["name"] = *skuObj.Name
}
skuConfig["tier"] = skuObj.Tier

return []interface{}{skuConfig}
Expand Down
20 changes: 10 additions & 10 deletions website/docs/r/devspace_controller.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_devspace_controller"
sidebar_current: "docs-azurerm-resource-devspace-controller"
description: |-
Manages an Azure DevSpace Controller.
Manages a DevSpace Controller.
---

# azurerm_devspace_controller

Manages an Azure DevSpace Controller.
Manages a DevSpace Controller.

## Example Usage

Expand Down Expand Up @@ -60,15 +60,15 @@ resource "azurerm_devspace_controller" test {

The following arguments are supported:

* `name` - (Required) Specifies the name of the Azure DevSpace Controller. Changing this forces a new resource to be created.
* `name` - (Required) Specifies the name of the DevSpace Controller. Changing this forces a new resource to be created.

* `resource_group_name` - (Required) The name of the resource group under which the Azure DevSpace Controller resource has to be created. Changing this forces a new resource to be created.
* `resource_group_name` - (Required) The name of the resource group under which the DevSpace Controller resource has to be created. Changing this forces a new resource to be created.

* `location` - (Required) Specifies the supported Azure location where the Azure DevSpace Controller should exist. Changing this forces a new resource to be created.
* `location` - (Required) Specifies the supported location where the DevSpace Controller should exist. Changing this forces a new resource to be created.

* `sku` - (Required) A `sku` block as documented below. Changing this forces a new resource to be created.

* `host_suffix` - (Required) The host suffix for the Azure DevSpace Controller. Changing this forces a new resource to be created.
* `host_suffix` - (Required) The host suffix for the DevSpace Controller. Changing this forces a new resource to be created.

* `target_container_host_resource_id` - (Required) The resource id of Azure Kubernetes Service cluster. Changing this forces a new resource to be created.

Expand All @@ -80,20 +80,20 @@ The following arguments are supported:

A `sku` block supports the following:

* `name` - (Required) The name of the SKU for Azure DevSpace Controller. Currently supported value is `S1`. Changing this forces a new resource to be created.
* `tier` - (Required) The tier of the SKU for Azure DevSpace Controller. Currently supported value is `Standard`. Changing this forces a new resource to be created.
* `name` - (Required) The name of the SKU for DevSpace Controller. Currently supported value is `S1`. Changing this forces a new resource to be created.
metacpp marked this conversation as resolved.
Show resolved Hide resolved
* `tier` - (Required) The tier of the SKU for DevSpace Controller. Currently supported value is `Standard`. Changing this forces a new resource to be created.
metacpp marked this conversation as resolved.
Show resolved Hide resolved

## Attributes Reference

The following attributes are exported:

* `id` - The ID of the Azure DevSpace Controller.
* `id` - The ID of the DevSpace Controller.

* `data_plane_fqdn` - DNS name for accessing DataPlane services.

## Import

Azure DevSpace Controller can be imported using the `resource id`, e.g.
DevSpace Controller can be imported using the `resource id`, e.g.
metacpp marked this conversation as resolved.
Show resolved Hide resolved

```shell
terraform import azurerm_devspace_controller.controller1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DevSpaces/controllers/controller1Name
Expand Down