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

Enable source control management as option for user to deploy web apps #826

Merged
merged 26 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
21db11c
resolve conflict.
metacpp Feb 13, 2018
78f5d92
Add default value for scm_type.
metacpp Feb 13, 2018
e0cd2e8
add site_source_control_props as attributes.
metacpp Feb 13, 2018
180fd76
Change the naming to simpler one and update documentation.
metacpp Feb 14, 2018
234b56f
Update the documentation and code style.
metacpp Feb 14, 2018
834c914
Update the test case and schema for source_control.
metacpp Feb 14, 2018
749960e
resolve conflict.
metacpp Feb 13, 2018
6437f64
Add default value for scm_type.
metacpp Feb 13, 2018
0765cf6
add site_source_control_props as attributes.
metacpp Feb 13, 2018
5ed289f
Change the naming to simpler one and update documentation.
metacpp Feb 14, 2018
cc4de93
Update the documentation and code style.
metacpp Feb 14, 2018
f3c7cd7
Update the test case and schema for source_control.
metacpp Feb 14, 2018
88714a9
only setting the source control block when there's values to be set
tombuildsstuff Feb 15, 2018
423ffc1
Merge branch 'master' into hack_scm
metacpp Feb 16, 2018
bbba70f
Resolve conflict.
metacpp Feb 16, 2018
d53a029
update the schema of site_config in app_service_plan to be the same a…
metacpp Feb 16, 2018
5384229
Merge branch 'master' into hack_scm
metacpp Mar 13, 2018
3c1cf85
Merge branch 'hack_scm' of github.com:terraform-providers/terraform-p…
metacpp Mar 13, 2018
1c4e460
add schema for publishing user for FTP and Git deployment.
metacpp Mar 14, 2018
ad47fdb
add expand and flattern for publishing user.
metacpp Mar 17, 2018
2d0fbf8
Add update and read for publishing_user.
metacpp Mar 20, 2018
d0d7ab5
Refine the code, test and documentation to support local git deployment.
metacpp Mar 21, 2018
1ba5381
Merge branch 'master' into hack_scm
metacpp Mar 21, 2018
4860923
Update the schema for site_credential.password to be sensitive.
metacpp Mar 26, 2018
2efd09c
Merge branch 'master' into hack_scm
metacpp Mar 26, 2018
43b5b49
Renaming `user_name` -> `username`
tombuildsstuff Mar 28, 2018
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
124 changes: 122 additions & 2 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func resourceArmAppService() *schema.Resource {
ForceNew: true,
},

// TODO: reusable schema
"site_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -160,6 +161,15 @@ func resourceArmAppService() *schema.Resource {
Optional: true,
Computed: true,
},
"scm_type": {
Type: schema.TypeString,
Optional: true,
Default: string(web.ScmTypeNone),
ValidateFunc: validation.StringInSlice([]string{
string(web.ScmTypeNone),
string(web.ScmTypeLocalGit),
}, false),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it'd also be good to expose the value of the SCM URL as a computed field - which I believe should be returned from the GetSourceControl API call when this is set to ScmTypeLocalGit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reminding, this is exactly what I did the recent commit, please see changes.

},
},
},
Expand Down Expand Up @@ -226,6 +236,25 @@ func resourceArmAppService() *schema.Resource {
// https://github.com/Azure/azure-rest-api-specs/issues/1697
"tags": tagsForceNewSchema(),

"site_credential": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
},
},

"default_site_hostname": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -235,6 +264,23 @@ func resourceArmAppService() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"source_control": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repo_url": {
Type: schema.TypeString,
Computed: true,
},
"branch": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -413,6 +459,24 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error making Read request on AzureRM App Service ConnectionStrings %q: %+v", name, err)
}

scmResp, err := client.GetSourceControl(ctx, resGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Source Control %q: %+v", name, err)
}

siteCredFuture, err := client.ListPublishingCredentials(ctx, resGroup, name)
if err != nil {
return err
}
err = siteCredFuture.WaitForCompletion(ctx, client.Client)
if err != nil {
return err
}
siteCredResp, err := siteCredFuture.Result(client)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Site Credential %q: %+v", name, err)
}

d.Set("name", name)
d.Set("resource_group_name", resGroup)
d.Set("location", azureRMNormalizeLocation(*resp.Location))
Expand All @@ -437,6 +501,16 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
return err
}

scm := flattenAppServiceSourceControl(scmResp.SiteSourceControlProperties)
if err := d.Set("source_control", scm); err != nil {
return err
}

siteCred := flattenAppServiceSiteCredential(siteCredResp.UserProperties)
if err := d.Set("site_credential", siteCred); err != nil {
return err
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down Expand Up @@ -541,6 +615,10 @@ func expandAppServiceSiteConfig(d *schema.ResourceData) web.SiteConfig {
siteConfig.WebSocketsEnabled = utils.Bool(v.(bool))
}

if v, ok := config["scm_type"]; ok {
siteConfig.ScmType = web.ScmType(v.(string))
}

return siteConfig
}

Expand Down Expand Up @@ -612,8 +690,30 @@ func flattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
result["websockets_enabled"] = *input.WebSocketsEnabled
}

results = append(results, result)
return results
result["scm_type"] = string(input.ScmType)

return append(results, result)
}

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

if input == nil {
log.Printf("[DEBUG] SiteSourceControlProperties is nil")
return results
}

if input.RepoURL != nil {
result["repo_url"] = *input.RepoURL
}
if input.Branch != nil && *input.Branch != "" {
result["branch"] = *input.Branch
} else {
result["branch"] = "master"
}

return append(results, result)
}

func expandAppServiceAppSettings(d *schema.ResourceData) *map[string]*string {
Expand Down Expand Up @@ -679,3 +779,23 @@ func validateAppServiceName(v interface{}, k string) (ws []string, es []error) {

return
}

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

if input == nil {
log.Printf("[DEBUG] UserProperties is nil")
return results
}

if input.PublishingUserName != nil {
result["username"] = *input.PublishingUserName
}

if input.PublishingPassword != nil {
result["password"] = *input.PublishingPassword
}

return append(results, result)
}
11 changes: 11 additions & 0 deletions azurerm/resource_arm_app_service_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func resourceArmAppServiceSlot() *schema.Resource {
ForceNew: true,
},

// TODO: reusable schema
"site_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -165,6 +166,16 @@ func resourceArmAppServiceSlot() *schema.Resource {
Optional: true,
Computed: true,
},

"scm_type": {
Type: schema.TypeString,
Optional: true,
Default: string(web.ScmTypeNone),
ValidateFunc: validation.StringInSlice([]string{
string(web.ScmTypeNone),
string(web.ScmTypeLocalGit),
}, false),
},
},
},
},
Expand Down
92 changes: 73 additions & 19 deletions azurerm/resource_arm_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,29 @@ func TestAccAzureRMAppService_webSockets(t *testing.T) {
})
}

func TestAccAzureRMAppService_scmType(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := acctest.RandInt()
config := testAccAzureRMAppService_scmType(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.scm_type", "LocalGit"),
resource.TestCheckResourceAttr(resourceName, "source_control.#", "1"),
resource.TestCheckResourceAttr(resourceName, "site_credential.#", "1"),
),
},
},
})
}

func testCheckAzureRMAppServiceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient

Expand Down Expand Up @@ -739,7 +762,7 @@ resource "azurerm_app_service" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
site_config {
use_32_bit_worker_process = true
use_32_bit_worker_process = true
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -769,7 +792,7 @@ resource "azurerm_app_service" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
site_config {
use_32_bit_worker_process = true
use_32_bit_worker_process = true
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -800,7 +823,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
always_on = true
always_on = true
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -831,7 +854,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
use_32_bit_worker_process = true
use_32_bit_worker_process = true
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -862,7 +885,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

app_settings {
"foo" = "bar"
"foo" = "bar"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -929,9 +952,9 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

connection_string {
name = "Example"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
name = "Example"
value = "some-postgresql-connection-string"
type = "PostgreSQL"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -962,11 +985,11 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
default_documents = [
"first.html",
"second.jsp",
"third.aspx",
]
default_documents = [
"first.html",
"second.jsp",
"third.aspx",
]
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1025,7 +1048,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
local_mysql_enabled = true
local_mysql_enabled = true
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1056,7 +1079,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

site_config {
managed_pipeline_mode = "Classic"
managed_pipeline_mode = "Classic"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1092,7 +1115,7 @@ resource "azurerm_app_service" "test" {
}

tags {
"Hello" = "World"
"Hello" = "World"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1123,7 +1146,7 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

tags {
"Hello" = "World"
"Hello" = "World"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1154,8 +1177,8 @@ resource "azurerm_app_service" "test" {
app_service_plan_id = "${azurerm_app_service_plan.test.id}"

tags {
"Hello" = "World"
"Terraform" = "AcceptanceTests"
"Hello" = "World"
"Terraform" = "AcceptanceTests"
}
}
`, rInt, location, rInt, rInt)
Expand Down Expand Up @@ -1317,3 +1340,34 @@ resource "azurerm_app_service" "test" {
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_scmType(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}"

site_config {
scm_type = "LocalGit"
}
}
`, rInt, location, rInt, rInt)
}
Loading