Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
njuCZ committed Mar 10, 2020
1 parent fe81d78 commit 7d65042
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
6 changes: 3 additions & 3 deletions azurerm/internal/services/appplatform/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type Client struct {
}

func NewClient(o *common.ClientOptions) *Client {
ServicesClient := appplatform.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ServicesClient.Client, o.ResourceManagerAuthorizer)
servicesClient := appplatform.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&servicesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ServicesClient: &ServicesClient,
ServicesClient: &servicesClient,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func dataSourceArmSpringCloud() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateSpringCloudName,
ValidateFunc: ValidateSpringCloudName,
},

"location": azure.SchemaLocationForDataSource(),
Expand Down Expand Up @@ -62,7 +62,10 @@ func dataSourceArmSpringCloudRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error reading Spring Cloud %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
if resp.ID != nil && *resp.ID != "" {
d.SetId(*resp.ID)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"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/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand All @@ -24,7 +24,7 @@ func dataSourceArmSpringCloudConfigServer() *schema.Resource {
"spring_cloud_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: validate.SpringCloudID,
},

"uri": {
Expand Down
19 changes: 7 additions & 12 deletions azurerm/internal/services/appplatform/resource_arm_spring_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func resourceArmSpringCloud() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateSpringCloudName,
ValidateFunc: ValidateSpringCloudName,
},

// Spring Cloud Service only supports following locations, we are still supporting more locations (Wednesday, November 20, 2019 4:20 PM):
// `East US`, `Southeast Asia`, `West Europe`, `West US 2`
"location": azure.SchemaLocation(),

"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),
"resource_group_name": azure.SchemaResourceGroupName(),

"service_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -88,11 +88,10 @@ func resourceArmSpringCloudCreate(d *schema.ResourceData, meta interface{}) erro
}

location := azure.NormalizeLocation(d.Get("location").(string))
t := d.Get("tags").(map[string]interface{})

resource := appplatform.ServiceResource{
Location: utils.String(location),
Tags: tags.Expand(t),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, resource)
Expand All @@ -107,7 +106,7 @@ func resourceArmSpringCloudCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error retrieving Spring Cloud %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil {
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Cannot read Spring Cloud %q (Resource Group %q) ID", name, resourceGroup)
}
d.SetId(*resp.ID)
Expand Down Expand Up @@ -155,13 +154,12 @@ func resourceArmSpringCloudUpdate(d *schema.ResourceData, meta interface{}) erro

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
t := d.Get("tags").(map[string]interface{})

resource := appplatform.ServiceResource{
Tags: tags.Expand(t),
springCloud := appplatform.ServiceResource{
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

future, err := client.Update(ctx, resourceGroup, name, resource)
future, err := client.Update(ctx, resourceGroup, name, springCloud)
if err != nil {
return fmt.Errorf("Error updating Spring Cloud %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand All @@ -184,9 +182,6 @@ func resourceArmSpringCloudDelete(d *schema.ResourceData, meta interface{}) erro

future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
}
return fmt.Errorf("Error deleting Spring Cloud %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

"github.com/Azure/azure-sdk-for-go/services/preview/appplatform/mgmt/2019-05-01-preview/appplatform"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform/validate"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -42,13 +42,13 @@ func resourceArmSpringCloudConfigServer() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: validate.SpringCloudID,
},

"uri": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateConfigServerURI,
ValidateFunc: ValidateConfigServerURI,
},
"host_key": {
Type: schema.TypeString,
Expand Down Expand Up @@ -79,12 +79,12 @@ func resourceArmSpringCloudConfigServer() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.NoEmptyStrings,
ValidateFunc: validation.StringIsNotEmpty,
},
"uri": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateConfigServerURI,
ValidateFunc: ValidateConfigServerURI,
},
"host_key": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestAccAzureRMSpringCloudConfigServer_update(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "repositories.#", "0"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMSpringCloudConfigServer_complete(data),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -69,6 +70,7 @@ func TestAccAzureRMSpringCloudConfigServer_update(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "repositories.1.search_paths.1", "dir2"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMSpringCloudConfigServer_basic(data),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccAzureRMSpringCloud_update(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "tags.Env", "Test"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMSpringCloud_complete(data),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -61,6 +62,7 @@ func TestAccAzureRMSpringCloud_update(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "tags.version", "1"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMSpringCloud_basic(data),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -173,6 +175,10 @@ func testCheckAzureRMSpringCloudDestroy(s *terraform.State) error {

func testAccAzureRMSpringCloud_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-spring-%d"
location = "%s"
Expand All @@ -193,6 +199,10 @@ resource "azurerm_spring_cloud" "test" {

func testAccAzureRMSpringCloud_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-spring-%d"
location = "%s"
Expand All @@ -215,6 +225,7 @@ func testAccAzureRMSpringCloud_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMSpringCloud_basic(data)
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud" "import" {
name = azurerm_spring_cloud.test.name
location = azurerm_resource_group.test.location
Expand Down
22 changes: 22 additions & 0 deletions azurerm/internal/services/appplatform/validate/spring_cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package validate

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appplatform/parse"
)

func SpringCloudID(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

if _, err := parse.SpringCloudID(v); err != nil {
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err))
return
}

return warnings, errors
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azure
package appplatform

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azure
package appplatform

import "testing"

Expand Down

0 comments on commit 7d65042

Please sign in to comment.