Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
njuCZ committed Apr 8, 2020
1 parent 526e6b4 commit 10e036b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
Expand Up @@ -57,7 +57,6 @@ func resourceArmSpringCloudActiveDeployment() *schema.Resource {
"deployment_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.SpringCloudDeploymentName,
},

Expand Down
Expand Up @@ -101,6 +101,31 @@ func TestAccAzureRMSpringCloudActiveDeployment_update(t *testing.T) {
})
}

func TestAccAzureRMSpringCloudActiveDeployment_switchActiveDeployment(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_active_deployment", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccAzureRMSpringCloudActiveDeployment_basic(data),
Check: resource.ComposeTestCheckFunc(
testAccAzureRMSpringCloudActiveDeploymentExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMSpringCloudActiveDeployment_switchActiveDeployment(data),
Check: resource.ComposeTestCheckFunc(
testAccAzureRMSpringCloudActiveDeploymentExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testAccAzureRMSpringCloudActiveDeploymentExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -186,6 +211,39 @@ resource "azurerm_spring_cloud_active_deployment" "test" {
`, template)
}

func testAccAzureRMSpringCloudActiveDeployment_switchActiveDeployment(data acceptance.TestData) string {
template := testAccAzureRMSpringCloudActiveDeployment_template(data)
lowerRandomString := strings.ToLower(data.RandomString)
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_deployment" "test2" {
name = "acctest-scd2-%s"
resource_group_name = azurerm_resource_group.test.name
service_name = azurerm_spring_cloud_service.test.name
app_name = azurerm_spring_cloud_app.test.name
cpu = 2
memory_in_gb = 2
instance_count = 2
runtime_version = "Java_11"
jvm_options = "-Xms1G -Xmx1G"
env = {
name1 = "value1"
name2 = "value2"
}
}
resource "azurerm_spring_cloud_active_deployment" "test" {
resource_group_name = azurerm_resource_group.test.name
service_name = azurerm_spring_cloud_service.test.name
app_name = azurerm_spring_cloud_app.test.name
deployment_name = azurerm_spring_cloud_deployment.test2.name
}
`, template, lowerRandomString)
}

func testAccAzureRMSpringCloudActiveDeployment_template(data acceptance.TestData) string {
lowerRandomString := strings.ToLower(data.RandomString)
return fmt.Sprintf(`
Expand Down
Expand Up @@ -156,39 +156,42 @@ func testCheckAzureRMSpringCloudDeploymentDestroy(s *terraform.State) error {

func testAccAzureRMSpringCloudDeployment_basic(data acceptance.TestData) string {
template := testAccAzureRMSpringCloudDeployment_template(data)
lowerRandomString := strings.ToLower(data.RandomString)
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_deployment" "test" {
name = "acctest-scd-%d"
name = "acctest-scd-%s"
resource_group_name = azurerm_resource_group.test.name
service_name = azurerm_spring_cloud_service.test.name
app_name = azurerm_spring_cloud_app.test.name
}
`, template, data.RandomInteger)
`, template, lowerRandomString)
}

func testAccAzureRMSpringCloudDeployment_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMSpringCloudDeployment_basic(data)
lowerRandomString := strings.ToLower(data.RandomString)
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_deployment" "import" {
name = "acctest-scd-%d"
name = "acctest-scd-%s"
resource_group_name = azurerm_resource_group.test.name
service_name = azurerm_spring_cloud_service.test.name
app_name = azurerm_spring_cloud_app.test.name
}
`, template, data.RandomInteger)
`, template, lowerRandomString)
}

func testAccAzureRMSpringCloudDeployment_complete(data acceptance.TestData) string {
template := testAccAzureRMSpringCloudDeployment_template(data)
lowerRandomString := strings.ToLower(data.RandomString)
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_deployment" "test" {
name = "acctest-scd-%d"
name = "acctest-scd-%s"
resource_group_name = azurerm_resource_group.test.name
service_name = azurerm_spring_cloud_service.test.name
app_name = azurerm_spring_cloud_app.test.name
Expand All @@ -206,7 +209,7 @@ resource "azurerm_spring_cloud_deployment" "test" {
name2 = "value2"
}
}
`, template, data.RandomInteger)
`, template, lowerRandomString)
}

func testAccAzureRMSpringCloudDeployment_template(data acceptance.TestData) string {
Expand Down
Expand Up @@ -59,7 +59,7 @@ The following arguments are supported:

* `app_name` - (Required) The name of the Spring Cloud Application resource. Changing this forces a new resource to be created.

* `deployment_name` - (Required) The name of the Spring Cloud deployment resource which will become active. Changing this forces a new resource to be created.
* `deployment_name` - (Required) The name of the Spring Cloud deployment resource which will become active.

* `public` - (Optional) is the app's public endpoint exposed? Defaults to `false`.

Expand Down

0 comments on commit 10e036b

Please sign in to comment.