-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Create azure App Service Plan resource #1
Create azure App Service Plan resource #1
Conversation
@tombuildsstuff I have migrated the code in pull requests hashicorp/terraform#12001 and hashicorp/terraform#13634 to this repository. |
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.
Hi @lstolyarov
Thanks for this contribution / porting this over to the new repo - I've reviewed and left some comments in-line - but this is off to a good start :)
Thanks!
client := meta.(*ArmClient) | ||
AppServicePlanClient := client.appServicePlansClient | ||
|
||
log.Printf("[INFO] preparing arguments for Azure App Service Plan creation.") |
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.
can we update this to AzureRM
for consistency?
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"location": { |
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.
can we switch this to use locationSchema()
?
|
||
func resourceArmAppServicePlanCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient) | ||
AppServicePlanClient := client.appServicePlansClient |
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: we'd generally combine these into one variable client
Create: resourceArmAppServicePlanCreateUpdate, | ||
Read: resourceArmAppServicePlanRead, | ||
Update: resourceArmAppServicePlanCreateUpdate, | ||
Delete: resourceArmAppServicePlanDelete, |
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.
given there's a test for it, can we add import support here:
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
}, | ||
"maximum_number_of_workers": { | ||
Type: schema.TypeString, | ||
Optional: true, |
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.
should this also be Computed
?
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resGroup) |
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.
can we set the other field values here?
} | ||
} | ||
|
||
var testAccAzureRMAppServicePlan_standard = ` |
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.
for newer resources we're tending to make this a function which returns a formatted string:
func testAccAzureRMAppServicePlan_standard(rInt int) string {
return fmt.Sprintf(`foo`, rInt)
}
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAzureRMAppServicePlan_standard(t *testing.T) { |
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.
Can we add another test case with all fields set?
"tier": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, |
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.
Looking at the SkuDescription
object:
// SkuDescription is description of a SKU for a scalable resource.
type SkuDescription struct {
Name *string `json:"name,omitempty"`
Tier *string `json:"tier,omitempty"`
Size *string `json:"size,omitempty"`
Family *string `json:"family,omitempty"`
Capacity *int32 `json:"capacity,omitempty"`
SkuCapacity *SkuCapacity `json:"skuCapacity,omitempty"`
Locations *[]string `json:"locations,omitempty"`
Capabilities *[]Capability `json:"capabilities,omitempty"`
}
I think it makes sense to separate this out into it's own block i.e.:
sku {
name = "Standard_S0"
tier = "Standard"
size = "S0"
...
}
Here's an example of the Schema usage - expanding/parsing it out and flattening/writing it back - which I'm hoping makes sense?
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmAppServicePlan() *schema.Resource { |
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 add some documentation for this resource too?
Hey @tombuildsstuff, I am facing a problem when running the acceptance test for the App Service Plan. I get the following error: |
Hey @lstolyarov Taking a look at the request made in Debug mode, I can confirm I'm seeing the same response - which appears to be an Azure API / Service error:
Which returns the response:
I've also tested in an HTTP client submitting via a POST rather than a PUT to check if this allowed is to be created - but unfortunately this doesn't appear to be an option. As such, I believe this is a service error, and the next step would be to open an issue over on the Azure Rest API Specs Repository which would allow the team to investigate further. Hope that helps? :) |
Hey @lstolyarov thanks for all your work on this. I'd love to help you resolve the issue so we can move your change along. I did a bit of looking and testing and it looks like you have "S0" as the plan for your tests. Using your code, I changed it to "S1" and the tests almost passed :) (got a different, hopefully familiar error). Here are a couple of links to take a look at: App Service Plans: https://azure.microsoft.com/en-us/pricing/details/app-service/ Let me know if this helps or if there's something else going on here. |
👋 hey @lstolyarov - have you had a chance to look into @echuvyrov's comments? :) |
Hi @tombuildsstuff, Apologies, I haven't had a chance yet. @echuvyrov thanks for the suggestion. I am aiming to try it out this week. Thanks |
@lstolyarov let me know if you could use a helping hand - I think this is one of the key resources for Azure :) |
Hey guys, I just had a look at this and the app service plan does get created with the sku size set to "S1". However, the tests now fail when resources are being destroyed. The destroy command cannot execute because the resource still has a create operation running on it:
@tombuildsstuff have you come across this before? |
Hey @lstolyarov From what you've said above, I'd guess the SDK is returning from the To work around that - in some resources we have functions which poll to check the resource has been created - which is what I'd suggest adding to the Create method. Hopefully that should solve the issue you're seeing here :) Thanks! |
Hi @tombuildsstuff, Thanks for the suggestion. I added the function but it doesn't help. The ProvisioningState is updated to "Succeeded" when the app service is created. I also tested this manually and I am only able to delete the app service plan about 5 minutes after it has been provisioned so there is definitely something else happening. I have got an issue open here updated with the latest problems. |
hey @lstolyarov @tombuildsstuff I am running into the same issue you are. Looking into this into internally and hope to have an answer very soon. |
* added .travis.yml and deploy.sh * added deploy script, updated travis.yml to build topic- branches * generate random string for hostname * plan now produces output plan, apply now consumes outputted plan * cleanup; sane defaults * explicit build dirs
Hey @echuvyrov Did you manage to get anywhere with this internally? :) Thanks! |
There's been an update on the SDK issue. Are we sure that |
Sku: &sku, | ||
} | ||
|
||
_, error := AppServicePlanClient.CreateOrUpdate(resGroup, name, appServicePlan, make(chan struct{})) |
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.
You may as well update this to be:
_, error := AppServicePlanClient.CreateOrUpdate(resGroup, name, appServicePlan, nil)
Instantiating a channel like this on the fly doesn't allow you a way to cancel and just adds a little garbage to be cleaned up later. :) Notice in this playground example nil is passed to wait(...)
but never triggers the cancel select case.
Hey @lstolyarov, Did you get a chance to look at the comments? Let me know if you need a hand - I would be really keen to see this as a supported resource. |
hey @georgeedwards @lstolyarov @tombuildsstuff we should have this unblocked this week, will keep you posted. I will test at the end of the week or at the beginning of the next week to confirm. |
hey @lstolyarov @tombuildsstuff @georgeedwards - our team reporting the acceptance tests passing now, can you please confirm that you are unblocked when you get a chance? |
Hi @echuvyrov, thanks a lot for having a look at this. The tests are now passing:
@tombuildsstuff I have added a couple more tests and updated the documentation. Is there anything else that needs to be done before this can be merged? Thanks, |
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.
Hey @lstolyarov
Thanks for the continued effort on this PR :)
I've taken a look through and left some comments, but they're mostly minor - if we can fix those up this otherwise looks good to merge :)
Thanks!
Set: resourceAzureRMAppServicePlanSkuHash, | ||
}, | ||
"maximum_number_of_workers": { | ||
Type: schema.TypeString, |
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.
I think this should be an int rather than a String?
azurerm/appserviceplan.go
Outdated
|
||
return res, string(res.AppServicePlanProperties.ProvisioningState), nil | ||
} | ||
} |
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 could we move this into the resource_arm_app_service_plan.go
file?
Timeout: 10 * time.Minute, | ||
} | ||
if _, err := stateConf.WaitForState(); err != nil { | ||
return fmt.Errorf("Error waiting for App Service Plan (%s) to become available: %s", name, 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 make this second formatting argument %+v
rather than %s
to show the full error?
azurerm/appserviceplan.go
Outdated
return func() (interface{}, string, error) { | ||
res, err := client.appServicePlansClient.Get(resourceGroupName, appserviceplan) | ||
if err != nil { | ||
return nil, "", fmt.Errorf("Error issuing read request in appServicePlanStateRefreshFunc to Azure ARM for App Service Plan '%s' (RG: '%s'): %s", appserviceplan, resourceGroupName, 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.
can we make the final formatting argument %+v
here to return the full error?
azurerm/appserviceplan.go
Outdated
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func appServicePlanStateRefreshFunc(client *ArmClient, resourceGroupName string, appserviceplan string) resource.StateRefreshFunc { |
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.
really minor it'd be good to call appserviceplan
-> name
for consistency across these methods, if possible
size = "B1" | ||
} | ||
} | ||
`, rInt, rInt) |
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.
can we add location
as the second argument here?
website/azurerm.erb
Outdated
@@ -42,6 +42,17 @@ | |||
</ul> | |||
</li> | |||
|
|||
<li<%= sidebar_current("docs-azurerm-resource-app-service") %>> | |||
<a href="#">App Service Resources</a> |
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.
🤔 do you think it's worth making this "App Service (Web Apps) Resources", like we've done for CosmosDB/DocumentDB?
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.
Good point. Yes, I think it is worth doing that.
website/azurerm.erb
Outdated
<ul class="nav nav-visible"> | ||
|
||
<li<%= sidebar_current("docs-azurerm-resource-app-service-plan") %>> | ||
<a href="/docs/providers/azurerm/r/app_service_pla.html">azurerm_app_service_plan</a> |
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.
app_service_pla.html
-> app_service_plan.html
* `tier` - (Required) Specified the plan's pricing tier. | ||
* `size` - (Required) Specified the plan's instance size. | ||
|
||
* `maximum_number_of_workers` - (Optional) . |
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 add a description for this field, here's the description from the Azure docs: "Maximum number of instances that can be assigned to this App Service plan."
|
||
resource "azurerm_app_service_plan" "test" { | ||
name = "acctestASP-%d" | ||
location = "West Europe" |
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.
can we make this ${azurerm_resource_group.test.location}
to only insert the location formatting argument a single time?
@lstolyarov Are ther any plans to support adding env variables to the configuration? |
catch up with main fork
Fixes for `azurerm_policy_definition`
add _id to fields for clarity
Sync master from Terraform head
Updated to include TRIAL as a SKU
Add network interface and security group association
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
No description provided.