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

App Service: Updating Connection Strings to a Set #2609

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions azurerm/data_source_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func dataSourceArmAppService() *schema.Resource {
Computed: true,
},
"value": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Sensitive: true,
Computed: true,
},
"type": {
Type: schema.TypeString,
Expand Down
9 changes: 6 additions & 3 deletions azurerm/data_source_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ func TestAccDataSourceAzureRMAppService_connectionString(t *testing.T) {
{
Config: testAccDataSourceAppService_connectionStrings(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.name", "Example"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.type", "PostgreSQL"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.name", "First"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.value", "first-connection-string"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.type", "Custom"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.name", "Second"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.type", "PostgreSQL"),
),
},
},
Expand Down
10 changes: 6 additions & 4 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func resourceArmAppService() *schema.Resource {
},

"connection_string": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -549,7 +549,7 @@ func expandAppServiceAppSettings(d *schema.ResourceData) map[string]*string {
}

func expandAppServiceConnectionStrings(d *schema.ResourceData) map[string]*web.ConnStringValueTypePair {
input := d.Get("connection_string").([]interface{})
input := d.Get("connection_string").(*schema.Set).List()
output := make(map[string]*web.ConnStringValueTypePair, len(input))

for _, v := range input {
Expand All @@ -568,14 +568,16 @@ func expandAppServiceConnectionStrings(d *schema.ResourceData) map[string]*web.C
return output
}

func flattenAppServiceConnectionStrings(input map[string]*web.ConnStringValueTypePair) interface{} {
func flattenAppServiceConnectionStrings(input map[string]*web.ConnStringValueTypePair) []interface{} {
results := make([]interface{}, 0)

for k, v := range input {
result := make(map[string]interface{})
result["name"] = k
result["type"] = string(v.Type)
result["value"] = *v.Value
if v.Value != nil {
result["value"] = *v.Value
}
results = append(results, result)
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_app_service_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func resourceArmAppServiceSlot() *schema.Resource {
},

"connection_string": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Expand Down
80 changes: 74 additions & 6 deletions azurerm/resource_arm_app_service_slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,35 @@ func TestAccAzureRMAppServiceSlot_clientAffinityEnabledUpdate(t *testing.T) {
func TestAccAzureRMAppServiceSlot_connectionStrings(t *testing.T) {
resourceName := "azurerm_app_service_slot.test"
ri := acctest.RandInt()
config := testAccAzureRMAppServiceSlot_connectionStrings(ri, testLocation())
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMAppServiceSlot_connectionStrings(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"),
),
},
{
Config: testAccAzureRMAppServiceSlot_connectionStringsUpdated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.name", "Example"),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.type", "PostgreSQL"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"),
),
},
},
Expand Down Expand Up @@ -1175,10 +1190,63 @@ resource "azurerm_app_service_slot" "test" {
app_service_name = "${azurerm_app_service.test.name}"
connection_string {
name = "Example"
name = "First"
value = "first-connection-string"
type = "Custom"
}
connection_string {
name = "Second"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
}
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_connectionStringsUpdated(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
}
resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
app_service_name = "${azurerm_app_service.test.name}"
connection_string {
name = "Second"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
}
connection_string {
name = "First"
value = "first-connection-string"
type = "Custom"
}
}
`, rInt, location, rInt, rInt, rInt)
}
Expand Down
72 changes: 66 additions & 6 deletions azurerm/resource_arm_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,35 @@ func TestAccAzureRMAppService_clientAffinityUpdate(t *testing.T) {
func TestAccAzureRMAppService_connectionStrings(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := acctest.RandInt()
config := testAccAzureRMAppService_connectionStrings(ri, testLocation())
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMAppService_connectionStrings(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.name", "Example"),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.0.type", "PostgreSQL"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"),
),
},
{
Config: testAccAzureRMAppService_connectionStringsUpdated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"),
resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"),
),
},
{
Expand Down Expand Up @@ -1665,10 +1680,55 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
connection_string {
name = "Example"
name = "First"
value = "first-connection-string"
type = "Custom"
}
connection_string {
name = "Second"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
}
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_connectionStringsUpdated(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
connection_string {
name = "Second"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
}
connection_string {
name = "First"
value = "first-connection-string"
type = "Custom"
}
}
`, rInt, location, rInt, rInt)
}
Expand Down