-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/azurerm: Create azure App services #12001
Changes from 5 commits
ab002c4
bddfc79
24e6082
ddaf7a1
165889b
d6d6541
af32b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/web" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmAppService() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmWebAppCreateUpdate, | ||
Read: resourceArmWebAppRead, | ||
Update: resourceArmWebAppCreateUpdate, | ||
Delete: resourceArmWebAppDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given this is a breaking change, this'll need a |
||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given this is a breaking change, this'll need a |
||
}, | ||
"skip_dns_registration": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
"skip_custom_domain_verification": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
"force_dns_registration": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"ttl_in_seconds": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this'd be better as an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ttl_in_seconds is passed in as a string https://godoc.org/github.com/Azure/azure-sdk-for-go/arm/web#AppsClient.CreateOrUpdate |
||
}, | ||
"server_farm_id": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename this to |
||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"always_on": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
"location": locationSchema(), | ||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmWebAppCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
appClient := client.appsClient | ||
|
||
log.Printf("[INFO] preparing arguments for Azure ARM Web App creation.") | ||
|
||
resGroup := d.Get("resource_group_name").(string) | ||
name := d.Get("name").(string) | ||
location := d.Get("location").(string) | ||
skipDNSRegistration := d.Get("skip_dns_registration").(bool) | ||
skipCustomDomainVerification := d.Get("skip_custom_domain_verification").(bool) | ||
forceDNSRegistration := d.Get("force_dns_registration").(bool) | ||
ttlInSeconds := d.Get("ttl_in_seconds").(string) | ||
tags := d.Get("tags").(map[string]interface{}) | ||
|
||
siteConfig := web.SiteConfig{} | ||
if v, ok := d.GetOk("always_on"); ok { | ||
alwaysOn := v.(bool) | ||
siteConfig.AlwaysOn = &alwaysOn | ||
} | ||
|
||
siteProps := web.SiteProperties{ | ||
SiteConfig: &siteConfig, | ||
} | ||
if v, ok := d.GetOk("server_farm_id"); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above - can we rename this to |
||
serverFarmID := v.(string) | ||
siteProps.ServerFarmID = &serverFarmID | ||
} | ||
|
||
siteEnvelope := web.Site{ | ||
Location: &location, | ||
Tags: expandTags(tags), | ||
SiteProperties: &siteProps, | ||
} | ||
|
||
_, err := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds, make(chan struct{})) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
read, err := appClient.Get(resGroup, name) | ||
if err != nil { | ||
return err | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Site %s (resource group %s) ID", name, resGroup) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename |
||
} | ||
|
||
d.SetId(*read.ID) | ||
|
||
return resourceArmWebAppRead(d, meta) | ||
} | ||
|
||
func resourceArmWebAppRead(d *schema.ResourceData, meta interface{}) error { | ||
appClient := meta.(*ArmClient).appsClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Reading web app details %s", id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename |
||
|
||
resGroup := id.ResourceGroup | ||
name := id.Path["sites"] | ||
|
||
resp, err := appClient.Get(resGroup, name) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("Error making Read request on Azure Web App %s: %s", name, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename |
||
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resGroup) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the other fields need to be set here too:
|
||
|
||
return nil | ||
} | ||
|
||
func resourceArmWebAppDelete(d *schema.ResourceData, meta interface{}) error { | ||
appClient := meta.(*ArmClient).appsClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
name := id.Path["sites"] | ||
|
||
log.Printf("[DEBUG] Deleting web app %s: %s", resGroup, name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename |
||
|
||
deleteMetrics := true | ||
deleteEmptyServerFarm := true | ||
skipDNSRegistration := true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given we're defaulting these values for the delete - should we do the same for the create? |
||
|
||
_, err = appClient.Delete(resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration) | ||
|
||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: can we rename these methods to say
AppService
rather thanWebApp
?