Skip to content

Commit

Permalink
azurerm_spring_cloud_app - ingress_settings (#19386)
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu authored Nov 23, 2022
1 parent ae26fcd commit c8495ec
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
97 changes: 97 additions & 0 deletions internal/services/springcloud/spring_cloud_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,56 @@ func resourceSpringCloudApp() *pluginsdk.Resource {
Default: false,
},

"ingress_settings": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"backend_protocol": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(appplatform.BackendProtocolDefault),
ValidateFunc: validation.StringInSlice([]string{
string(appplatform.BackendProtocolDefault),
string(appplatform.BackendProtocolGRPC),
}, false),
},

"read_timeout_in_seconds": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 300,
ValidateFunc: validation.IntAtLeast(0),
},

"send_timeout_in_seconds": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 60,
ValidateFunc: validation.IntAtLeast(0),
},

"session_affinity": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(appplatform.SessionAffinityNone),
ValidateFunc: validation.StringInSlice([]string{
string(appplatform.SessionAffinityCookie),
string(appplatform.SessionAffinityNone),
}, false),
},

"session_cookie_max_age": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(0),
},
},
},
},

"persistent_disk": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -230,6 +280,9 @@ func resourceSpringCloudAppCreate(d *pluginsdk.ResourceData, meta interface{}) e
PublicEndpoint: utils.Bool(enabled),
}
}
// IngressSettings could only be set by update
// Issue: https://github.com/Azure/azure-rest-api-specs/issues/21536
app.Properties.IngressSettings = expandSpringCloudAppIngressSetting(d.Get("ingress_settings").([]interface{}))
future, err = client.CreateOrUpdate(ctx, id.ResourceGroup, id.SpringName, id.AppName, app)
if err != nil {
return fmt.Errorf("update %q: %+v", id, err)
Expand Down Expand Up @@ -269,6 +322,7 @@ func resourceSpringCloudAppUpdate(d *pluginsdk.ResourceData, meta interface{}) e
EnableEndToEndTLS: utils.Bool(d.Get("tls_enabled").(bool)),
Public: utils.Bool(d.Get("is_public").(bool)),
HTTPSOnly: utils.Bool(d.Get("https_only").(bool)),
IngressSettings: expandSpringCloudAppIngressSetting(d.Get("ingress_settings").([]interface{})),
PersistentDisk: expandSpringCloudAppPersistentDisk(d.Get("persistent_disk").([]interface{})),
CustomPersistentDisks: expandAppCustomPersistentDiskResourceArray(d.Get("custom_persistent_disk").([]interface{}), *id),
},
Expand Down Expand Up @@ -336,6 +390,9 @@ func resourceSpringCloudAppRead(d *pluginsdk.ResourceData, meta interface{}) err
if err := d.Set("custom_persistent_disk", flattenAppCustomPersistentDiskResourceArray(prop.CustomPersistentDisks)); err != nil {
return fmt.Errorf("setting `custom_persistent_disk`: %+v", err)
}
if err := d.Set("ingress_settings", flattenSpringCloudAppIngressSettings(prop.IngressSettings)); err != nil {
return fmt.Errorf("setting `ingress_settings`: %+v", err)
}
if prop.VnetAddons != nil {
d.Set("public_endpoint_enabled", prop.VnetAddons.PublicEndpoint)
}
Expand Down Expand Up @@ -426,6 +483,21 @@ func expandSpringCloudAppAddon(input string) (map[string]map[string]interface{},
return addonConfig, nil
}

func expandSpringCloudAppIngressSetting(input []interface{}) *appplatform.IngressSettings {
if len(input) == 0 || input[0] == nil {
return nil
}
raw := input[0].(map[string]interface{})

return &appplatform.IngressSettings{
ReadTimeoutInSeconds: utils.Int32(int32(raw["read_timeout_in_seconds"].(int))),
SendTimeoutInSeconds: utils.Int32(int32(raw["send_timeout_in_seconds"].(int))),
SessionAffinity: appplatform.SessionAffinity(raw["session_affinity"].(string)),
SessionCookieMaxAge: utils.Int32(int32(raw["session_cookie_max_age"].(int))),
BackendProtocol: appplatform.BackendProtocol(raw["backend_protocol"].(string)),
}
}

func flattenSpringCloudAppIdentity(input *appplatform.ManagedIdentityProperties) (*[]interface{}, error) {
var transform *identity.SystemAndUserAssignedMap
if input != nil {
Expand Down Expand Up @@ -523,3 +595,28 @@ func flattenSpringCloudAppAddon(configs map[string]map[string]interface{}) *stri
addonConfig, _ := json.Marshal(configs)
return utils.String(string(addonConfig))
}

func flattenSpringCloudAppIngressSettings(input *appplatform.IngressSettings) interface{} {
if input == nil {
return make([]interface{}, 0)
}
var readTimeout, sendTimeout, maxAge int32
backendProtocol := string(input.BackendProtocol)
sessionAffinity := string(input.SessionAffinity)
if input.ReadTimeoutInSeconds != nil {
readTimeout = *input.ReadTimeoutInSeconds
}
if input.SendTimeoutInSeconds != nil {
sendTimeout = *input.SendTimeoutInSeconds
}
if input.SessionCookieMaxAge != nil {
maxAge = *input.SessionCookieMaxAge
}
return []interface{}{map[string]interface{}{
"backend_protocol": backendProtocol,
"read_timeout_in_seconds": readTimeout,
"send_timeout_in_seconds": sendTimeout,
"session_affinity": sessionAffinity,
"session_cookie_max_age": maxAge,
}}
}
62 changes: 62 additions & 0 deletions internal/services/springcloud/spring_cloud_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ func TestAccSpringCloudApp_customPersistentDisksUpdate(t *testing.T) {
})
}

func TestAccSpringCloudApp_ingressSettings(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_app", "test")
r := SpringCloudAppResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.ingressSettings(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.ingressSettingsUpdated(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSpringCloudApp_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_spring_cloud_app", "test")
r := SpringCloudAppResource{}
Expand Down Expand Up @@ -472,6 +494,46 @@ resource "azurerm_spring_cloud_storage" "test2" {
`, r.template(data), data.RandomInteger, data.RandomStringOfLength(10))
}

func (r SpringCloudAppResource) ingressSettings(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_app" "test" {
name = "acctest-sca-%[2]d"
resource_group_name = azurerm_spring_cloud_service.test.resource_group_name
service_name = azurerm_spring_cloud_service.test.name
ingress_settings {
session_affinity = "None"
read_timeout_in_seconds = 70
send_timeout_in_seconds = 70
session_cookie_max_age = 0
backend_protocol = "Default"
}
}
`, SpringCloudServiceResource{}.basic(data), data.RandomInteger)
}

func (r SpringCloudAppResource) ingressSettingsUpdated(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_spring_cloud_app" "test" {
name = "acctest-sca-%[2]d"
resource_group_name = azurerm_spring_cloud_service.test.resource_group_name
service_name = azurerm_spring_cloud_service.test.name
ingress_settings {
session_affinity = "Cookie"
read_timeout_in_seconds = 700
send_timeout_in_seconds = 700
session_cookie_max_age = 700
backend_protocol = "GRPC"
}
}
`, SpringCloudServiceResource{}.basic(data), data.RandomInteger)
}

func (SpringCloudAppResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
16 changes: 16 additions & 0 deletions website/docs/r/spring_cloud_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The following arguments are supported:

* `https_only` - (Optional) Is only HTTPS allowed? Defaults to `false`.

* `ingress_settings` - (Optional) An `ingress_settings` block as defined below.

* `persistent_disk` - (Optional) An `persistent_disk` block as defined below.

* `public_endpoint_enabled` - (Optional) Should the App in vnet injection instance exposes endpoint which could be accessed from Internet?
Expand Down Expand Up @@ -90,6 +92,20 @@ An `identity` block supports the following:

---

An `ingress_settings` block supports the following:

* `backend_protocol` - (Optional) Specifies how ingress should communicate with this app backend service. Allowed values are `GRPC` and `Default`. Defaults to `Default`.

* `read_timeout_in_seconds` - (Optional) Specifies the ingress read time out in seconds. Defaults to 300.

* `send_timeout_in_seconds` - (Optional) Specifies the ingress send time out in seconds. Defaults to 60.

* `session_affinity` - (Optional) Specifies the type of the affinity, set this to `Cookie` to enable session affinity. Allowed values are `Cookie` and `None`. Defaults to `None`.

* `session_cookie_max_age` - (Optional) Specifies the time in seconds until the cookie expires.

---

An `persistent_disk` block supports the following:

* `size_in_gb` - (Required) Specifies the size of the persistent disk in GB. Possible values are between `0` and `50`.
Expand Down

0 comments on commit c8495ec

Please sign in to comment.