-
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 Service Plan resource #13634
Changes from 4 commits
ab002c4
bddfc79
be430ba
9f6543b
233f5d5
c550ee3
8539ba3
2055267
6a6e1e0
4af4c7c
e0a5f0c
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,132 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/web" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmAppServicePlan() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmAppServicePlanCreateUpdate, | ||
Read: resourceArmAppServicePlanRead, | ||
Update: resourceArmAppServicePlanCreateUpdate, | ||
Delete: resourceArmAppServicePlanDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"location": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"tier": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"maximum_number_of_workers": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmAppServicePlanCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
AppServicePlanClient := client.appServicePlansClient | ||
|
||
log.Printf("[INFO] preparing arguments for Azure ARM Server Farm creation.") | ||
|
||
resGroup := d.Get("resource_group_name").(string) | ||
name := d.Get("name").(string) | ||
location := d.Get("location").(string) | ||
tier := d.Get("tier").(string) | ||
|
||
sku := web.SkuDescription{ | ||
Name: &tier, | ||
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. It'd be good to also specify the Size and the Tier here too, as we do in the other resources? We tend to make
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. @tombuildsstuff do you mean that I have to pass in the Size and Tier as inputs to the provider? At the moment I am only passing in the service tier, e.g. "S0" which determines the tier. |
||
} | ||
|
||
properties := web.AppServicePlanProperties{} | ||
if v, ok := d.GetOk("maximum_number_of_workers"); ok { | ||
maximumNumberOfWorkers := v.(int32) | ||
properties.MaximumNumberOfWorkers = &maximumNumberOfWorkers | ||
} | ||
|
||
appServicePlan := web.AppServicePlan{ | ||
Location: &location, | ||
AppServicePlanProperties: &properties, | ||
Sku: &sku, | ||
} | ||
|
||
_, err := AppServicePlanClient.CreateOrUpdate(resGroup, name, appServicePlan, make(chan struct{})) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
read, err := AppServicePlanClient.Get(resGroup, name) | ||
if err != nil { | ||
return err | ||
} | ||
if read.ID == nil { | ||
return fmt.Errorf("Cannot read Server farm %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 resourceArmAppServicePlanRead(d, meta) | ||
} | ||
|
||
func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) error { | ||
AppServicePlanClient := meta.(*ArmClient).appServicePlansClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Reading app service plan %s", id) | ||
|
||
resGroup := id.ResourceGroup | ||
name := id.Path["serverfarms"] | ||
|
||
resp, err := AppServicePlanClient.Get(resGroup, name) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("Error making Read request on Azure Server Farm %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. we need to set the other properties here, i.e. |
||
|
||
return nil | ||
} | ||
|
||
func resourceArmAppServicePlanDelete(d *schema.ResourceData, meta interface{}) error { | ||
AppServicePlanClient := meta.(*ArmClient).appServicePlansClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
resGroup := id.ResourceGroup | ||
name := id.Path["serverfarms"] | ||
|
||
log.Printf("[DEBUG] Deleting app service plan %s: %s", resGroup, name) | ||
|
||
_, err = AppServicePlanClient.Delete(resGroup, name) | ||
|
||
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.
could we rename this from
Server Farm
->App Service Plan
to match the resource?