Repository: ansible/ansible-modules-extras

Issue:
Redshift module public_accessible = False does not work 
<!--- Verify first that your issue/request is not already reported in GitHub -->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the plugin/module/task -->
redshift.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
latest dev from git 
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.

Ubuntu 16.04
-->

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->


When creating a cluster with : 
   "module_args": {
            "availability_zone": "us-east-1a", 
            "cluster_subnet_group_name": "redshift-subnet", 
            "cluster_type": "multi-node", 
            "command": "create", 
            "identifier": "XXXXX", 
            "node_type": "dc1.large", 
            "number_of_nodes": 2, 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "publicly_accessible": false, 
            "region": "us-east-1", 
            "username": "XXXXX", 
            "validate_certs": true, 
            "vpc_security_group_ids": [
                "sg-XXXXX"
            ], 
            "wait": true, 
            "wait_timeout": "300"


Cluster is still created with public_accessible  True . 


<!--- Paste example playbooks or commands between quotes below -->
```

---

- name: Create Redshift Cluster
  tags: ['redshift']
  redshift:
    command: create
    availability_zone: '{{subnets[1].az}}'
    identifier: '{{redshift_identifier}}'
    username: '{{redshift_username}}'
    password: '{{redshift_password}}'
    node_type: '{{redshift_node_type}}'
    cluster_subnet_group_name: redshift-subnet
    cluster_type: multi-node
    number_of_nodes: '{{redshift_number_of_nodes}}'
    publicly_accessible: False
    region: us-east-1
    vpc_security_group_ids: '{{nrgredshiftsg}}'
    wait: true
    wait_timeout: 600
  register: redshiftinfo


- name: Print Redshift Details
  tags: ['redshift']
  debug:
    msg: '{{redshiftinfo|to_json}}'


- name: Create redshiftinfo.json file
  tags: ['redshift']
  copy:
     content="{{ redshiftinfo|to_json }}"
     dest="/tmp/redshift.json"



```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:
<!-- @amishel: Thanks for filing this bug report! -->

@j-carl ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->


Resolving patch:
diff --git a/cloud/amazon/redshift.py b/cloud/amazon/redshift.py
--- a/cloud/amazon/redshift.py
+++ b/cloud/amazon/redshift.py
@@ -37,115 +37,94 @@
   node_type:
     description:
       - The node type of the cluster. Must be specified when command=create.
-    required: false
     choices: ['ds1.xlarge', 'ds1.8xlarge', 'ds2.xlarge', 'ds2.8xlarge', 'dc1.large', 'dc1.8xlarge', 'dw1.xlarge', 'dw1.8xlarge', 'dw2.large', 'dw2.8xlarge']
   username:
     description:
       - Master database username. Used only when command=create.
-    required: false
   password:
     description:
       - Master database password. Used only when command=create.
-    required: false
   cluster_type:
     description:
       - The type of cluster.
-    required: false
     choices: ['multi-node', 'single-node' ]
     default: 'single-node'
   db_name:
     description:
       - Name of the database.
-    required: false
     default: null
   availability_zone:
     description:
       - availability zone in which to launch cluster
-    required: false
     aliases: ['zone', 'aws_zone']
   number_of_nodes:
     description:
       - Number of nodes. Only used when cluster_type=multi-node.
-    required: false
     default: null
   cluster_subnet_group_name:
     description:
       - which subnet to place the cluster
-    required: false
     aliases: ['subnet']
   cluster_security_groups:
     description:
       - in which security group the cluster belongs
-    required: false
     default: null
     aliases: ['security_groups']
   vpc_security_group_ids:
     description:
       - VPC security group
-    required: false
     aliases: ['vpc_security_groups']
     default: null
   preferred_maintenance_window:
     description:
       - maintenance window
-    required: false
     aliases: ['maintance_window', 'maint_window']
     default: null
   cluster_parameter_group_name:
     description:
       - name of the cluster parameter group
-    required: false
     aliases: ['param_group_name']
     default: null
   automated_snapshot_retention_period:
     description:
       - period when the snapshot take place
-    required: false
     aliases: ['retention_period']
     default: null
   port:
     description:
       - which port the cluster is listining
-    required: false
     default: null
   cluster_version:
     description:
       - which version the cluster should have
-    required: false
     aliases: ['version']
     choices: ['1.0']
     default: null
   allow_version_upgrade:
     description:
       - flag to determinate if upgrade of version is possible
-    required: false
     aliases: ['version_upgrade']
-    default: null
+    default: true
   publicly_accessible:
     description:
       - if the cluster is accessible publicly or not
-    required: false
-    default: null
+    default: false
   encrypted:
     description:
       -  if the cluster is encrypted or not
-    required: false
-    default: null
+    default: false
   elastic_ip:
     description:
       - if the cluster has an elastic IP or not
-    required: false
     default: null
   new_cluster_identifier:
     description:
       - Only used when command=modify.
-    required: false
     aliases: ['new_identifier']
     default: null
   wait:
     description:
       - When command=create, modify or restore then wait for the database to enter the 'available' state. When command=delete wait for the database to be terminated.
-    required: false
     default: "no"
     choices: [ "yes", "no" ]
   wait_timeout:
@@ -282,7 +261,7 @@ def create_cluster(module, redshift):
               'cluster_version', 'allow_version_upgrade',
               'number_of_nodes', 'publicly_accessible',
               'encrypted', 'elastic_ip'):
-        if module.params.get( p ):
+        if p in module.params:
             params[ p ] = module.params.get( p )
 
     try:
@@ -389,12 +368,11 @@ def modify_cluster(module, redshift):
               'cluster_parameter_group_name',
               'automated_snapshot_retention_period', 'port', 'cluster_version',
               'allow_version_upgrade', 'number_of_nodes', 'new_cluster_identifier'):
-        if module.params.get(p):
+        if p in module.params:
             params[p] = module.params.get(p)
 
     try:
         redshift.describe_clusters(identifier)['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
-        changed = False
     except boto.exception.JSONResponseError as e:
         try:
             redshift.modify_cluster(identifier, **params)
@@ -444,10 +422,10 @@ def main():
             automated_snapshot_retention_period = dict(aliases=['retention_period']),
             port                                = dict(type='int'),
             cluster_version                     = dict(aliases=['version'], choices=['1.0']),
-            allow_version_upgrade               = dict(aliases=['version_upgrade'], type='bool'),
+            allow_version_upgrade               = dict(aliases=['version_upgrade'], type='bool', default=True),
             number_of_nodes                     = dict(type='int'),
-            publicly_accessible                 = dict(type='bool'),
-            encrypted                           = dict(type='bool'),
+            publicly_accessible                 = dict(type='bool', default=False),
+            encrypted                           = dict(type='bool', default=False),
             elastic_ip                          = dict(required=False),
             new_cluster_identifier              = dict(aliases=['new_identifier']),
             wait                                = dict(type='bool', default=False),


Test patch: