Skip to content
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

Add additional parameters for webapp site config #695

Merged
merged 5 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions plugins/modules/azure_rm_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@
- Repository type of deployment source, for example C(LocalGit), C(GitHub).
- List of supported values maintained at U(https://docs.microsoft.com/en-us/rest/api/appservice/webapps/createorupdate#scmtype).

always_on:
description:
- Keeps the app loaded even when there's no traffic.
type: bool

min_tls_version:
description:
- The minimum TLS encryption version required for the app.
type: str
choices:
- 1.0
- 1.1
- 1.2

ftps_state:
description:
- The state of the FTP/FTPS service.
type: str
choices:
- AllAllowed
- FtpsOnly
- Disabled

deployment_source:
description:
- Deployment source for git.
Expand Down Expand Up @@ -446,6 +469,17 @@ def __init__(self):
scm_type=dict(
type='str',
),
always_on=dict(
type='bool',
),
min_tls_version=dict(
type='str',
choices=['1.0', '1.1', '1.2'],
),
ftps_state=dict(
type='str',
choices=['AllAllowed', 'FtpsOnly', 'Disabled'],
),
deployment_source=dict(
type='dict',
options=deployment_source_spec
Expand Down Expand Up @@ -537,7 +571,10 @@ def __init__(self):
"java_version",
"php_version",
"python_version",
"scm_type"]
"scm_type",
"always_on",
"min_tls_version",
"ftps_state"]

# updatable_properties
self.updatable_properties = ["client_affinity_enabled",
Expand All @@ -561,7 +598,7 @@ def exec_module(self, **kwargs):
if hasattr(self, key):
setattr(self, key, kwargs[key])
elif kwargs[key] is not None:
if key == "scm_type":
if key in ["scm_type", "always_on", "min_tls_version", "ftps_state"]:
self.site_config[key] = kwargs[key]

old_response = None
Expand Down Expand Up @@ -662,7 +699,6 @@ def exec_module(self, **kwargs):
if self.https_only is not None:
self.site.https_only = self.https_only

if self.client_affinity_enabled:
self.site.client_affinity_enabled = self.client_affinity_enabled
l3ender marked this conversation as resolved.
Show resolved Hide resolved

# check if the web app already present in the resource group
Expand Down Expand Up @@ -808,10 +844,10 @@ def is_updatable_property_changed(self, existing_webapp):

# compare xxx_version
def is_site_config_changed(self, existing_config):
for fx_version in self.site_config_updatable_properties:
if self.site_config.get(fx_version):
if not getattr(existing_config, fx_version) or \
getattr(existing_config, fx_version).upper() != self.site_config.get(fx_version).upper():
for updatable_property in self.site_config_updatable_properties:
if self.site_config.get(updatable_property):
if not getattr(existing_config, updatable_property) or \
str(getattr(existing_config, updatable_property)).upper() != str(self.site_config.get(updatable_property)).upper():
return True

return False
Expand Down
22 changes: 22 additions & 0 deletions plugins/modules/azure_rm_webapp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@
"version": "5.6"
}
]
always_on:
description:
- If the app is kept loaded even when there's no traffic.
returned: always
type: bool
sample: true
min_tls_version:
description:
- The minimum TLS encryption version required for the app.
returned: always
type: str
sample: 1.2
ftps_state:
description:
- The state of the FTP/FTPS service.
returned: always
type: str
sample: FtpsOnly
availability_state:
description:
- Availability of this web app.
Expand Down Expand Up @@ -458,6 +476,10 @@ def construct_curated_webapp(self,
if len(tmp) == 2:
curated_output['frameworks'].append({'name': tmp[0].lower(), 'version': tmp[1]})

curated_output['always_on'] = configuration.get('always_on')
curated_output['ftps_state'] = configuration.get('ftps_state')
curated_output['min_tls_version'] = configuration.get('min_tls_version')

# curated app_settings
if app_settings and app_settings.get('properties', None):
curated_output['app_settings'] = dict()
Expand Down
107 changes: 106 additions & 1 deletion tests/integration/targets/azure_rm_webapp/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
- name: Prepare facts
set_fact:
resource_prefix: "{{ resource_group_secondary | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
run_once: yes

- name: Fix resource prefix
set_fact:
linux_app_plan_resource_group: "{{ resource_group_secondary }}"
win_app_name: "{{ (resource_prefix | replace('-','x'))[-8:] }}{{ 1000 | random}}winapp"
linux_app_name: "{{ (resource_prefix | replace('-','x'))[-8:] }}{{ 1000 | random}}linuxapp"
win_plan_name: "{{ (resource_prefix | replace('-','x'))[-8:] }}winplan"
linux_plan_name: "{{ (resource_group_secondary | replace('-','x'))[-8:] }}linplan"
slot1_name: "stage1"
Expand Down Expand Up @@ -344,6 +350,105 @@
that:
- facts.webapps[0].ftp_publish_url != ''

- name: Create a web app with various site config params
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ linux_app_name }}-siteconfig"
plan:
resource_group: "{{ linux_app_plan_resource_group }}"
name: "{{ linux_app_name }}-siteconfig-plan"
is_linux: true
sku: S1
frameworks:
- name: java
version: "8"
settings:
java_container: "tomcat"
java_container_version: "8.5"
client_affinity_enabled: false
https_only: true
always_on: true
min_tls_version: "1.2"
ftps_state: "Disabled"
register: output
- name: Assert the web app was created
assert:
that: output.changed

- name: Create a web app with various site config params - idempotent
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ linux_app_name }}-siteconfig"
plan:
resource_group: "{{ linux_app_plan_resource_group }}"
name: "{{ linux_app_name }}-siteconfig-plan"
is_linux: true
sku: S1
frameworks:
- name: java
version: "8"
settings:
java_container: "tomcat"
java_container_version: "8.5"
client_affinity_enabled: false
https_only: true
always_on: true
min_tls_version: "1.2"
ftps_state: "Disabled"
register: output
- name: Assert the web app not changed
assert:
that: not output.changed

- name: Get facts for site config params
azure_rm_webapp_info:
resource_group: "{{ resource_group }}"
name: "{{ linux_app_name }}-siteconfig"
register: facts
- name: Assert site config params meet expectations
assert:
that:
- facts.webapps[0].always_on
- facts.webapps[0].min_tls_version == '1.2'
- facts.webapps[0].ftps_state == 'Disabled'

- name: Update web app with various site config params - single change
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ linux_app_name }}-siteconfig"
plan:
resource_group: "{{ linux_app_plan_resource_group }}"
name: "{{ linux_app_name }}-siteconfig-plan"
is_linux: true
sku: S1
frameworks:
- name: java
version: "8"
settings:
java_container: "tomcat"
java_container_version: "8.5"
client_affinity_enabled: false
https_only: true
always_on: true
min_tls_version: "1.2"
ftps_state: "FtpsOnly"
register: output
- name: Assert the web app was updated
assert:
that: output.changed

- name: Get facts for site config params
azure_rm_webapp_info:
resource_group: "{{ resource_group }}"
name: "{{ linux_app_name }}-siteconfig"
register: facts
- name: Assert site config params meet expectations
assert:
that:
- facts.webapps[0].always_on
- facts.webapps[0].min_tls_version == '1.2'
- facts.webapps[0].ftps_state == 'FtpsOnly'

- name: Create a webapp slot (Check mode)
azure_rm_webappslot:
resource_group: "{{ resource_group }}"
Expand Down Expand Up @@ -431,4 +536,4 @@
- name: Assert stopped
assert:
that:
- output.changed
- output.changed