-
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
azurerm_app_service
- support for MSI
#1130
Changes from all commits
dce0ae5
91c4e54
97f3ea3
1e8ae9d
3afa18e
f68b8e5
0132836
a730b04
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 |
---|---|---|
|
@@ -29,6 +29,33 @@ func resourceArmAppService() *schema.Resource { | |
ValidateFunc: validateAppServiceName, | ||
}, | ||
|
||
"identity": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Computed: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"SystemAssigned", | ||
}, true), | ||
}, | ||
"principal_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"location": locationSchema(), | ||
|
@@ -336,6 +363,11 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error | |
}, | ||
} | ||
|
||
if _, ok := d.GetOk("identity"); ok { | ||
appServiceIdentity := expandAzureRmAppServiceIdentity(d) | ||
siteEnvelope.Identity = appServiceIdentity | ||
} | ||
|
||
if v, ok := d.GetOkExists("client_affinity_enabled"); ok { | ||
enabled := v.(bool) | ||
siteEnvelope.SiteProperties.ClientAffinityEnabled = utils.Bool(enabled) | ||
|
@@ -431,6 +463,28 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error | |
} | ||
} | ||
|
||
if d.HasChange("identity") { | ||
site, err := client.Get(ctx, resGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error getting configuration for App Service %q: %+v", name, err) | ||
} | ||
|
||
appServiceIdentity := expandAzureRmAppServiceIdentity(d) | ||
site.Identity = appServiceIdentity | ||
|
||
future, err := client.CreateOrUpdate(ctx, resGroup, name, site) | ||
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 handle this error? this is returned for instance when the request is invalid (vs the polling method when the long running request/modifications fail) 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. Sure, sorry my bad |
||
|
||
if err != nil { | ||
return fmt.Errorf("Error updating Managed Service Identity for App Service %q: %+v", name, err) | ||
} | ||
|
||
err = future.WaitForCompletion(ctx, client.Client) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error updating Managed Service Identity for App Service %q: %+v", name, err) | ||
} | ||
} | ||
|
||
return resourceArmAppServiceRead(d, meta) | ||
} | ||
|
||
|
@@ -528,6 +582,11 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { | |
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
identity := flattenAzureRmAppServiceMachineIdentity(resp.Identity) | ||
if err := d.Set("identity", identity); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -784,6 +843,33 @@ func flattenAppServiceAppSettings(input map[string]*string) map[string]string { | |
return output | ||
} | ||
|
||
func expandAzureRmAppServiceIdentity(d *schema.ResourceData) *web.ManagedServiceIdentity { | ||
identities := d.Get("identity").([]interface{}) | ||
identity := identities[0].(map[string]interface{}) | ||
identityType := identity["type"].(string) | ||
return &web.ManagedServiceIdentity{ | ||
Type: web.ManagedServiceIdentityType(identityType), | ||
} | ||
} | ||
|
||
func flattenAzureRmAppServiceMachineIdentity(identity *web.ManagedServiceIdentity) []interface{} { | ||
if identity == nil { | ||
return make([]interface{}, 0) | ||
} | ||
|
||
result := make(map[string]interface{}) | ||
result["type"] = string(identity.Type) | ||
|
||
if identity.PrincipalID != nil { | ||
result["principal_id"] = *identity.PrincipalID | ||
} | ||
if identity.TenantID != nil { | ||
result["tenant_id"] = *identity.TenantID | ||
} | ||
|
||
return []interface{}{result} | ||
} | ||
|
||
func validateAppServiceName(v interface{}, k string) (ws []string, es []error) { | ||
value := v.(string) | ||
|
||
|
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 document these properties in the documentation? That's stored in this file, it'll want the
type
property documented in theArgument Reference
block and theprincipal_id
andtenant_id
fields documented in theAttributes Reference
blockThere 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.
done