
    Vht                        d Z dZdZ	 ddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ dZg dZeg dz   Zg dZddddZ ed ej9                         D              Z eej?                               Z  e
jB                  dddddg      d        Z" e
jB                  ddg       d!        Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+dBd*Z,d+ Z-d, Z.d- Z/d. Z0dCd/Z1dCd0Z2d1 Z3dCd2Z4d3 Z5d4 Z6d5 Z7d6 Z8dDd7Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBeCdAk(  r eB        yy# e$ r Y 7w xY w)Ea%  
---
module: dynamodb_table
version_added: 1.0.0
short_description: Create, update or delete AWS Dynamo DB tables
description:
  - Create or delete AWS Dynamo DB tables.
  - Can update the provisioned throughput on existing tables.
  - Returns the status of the specified table.
author:
  - Alan Loi (@loia)
options:
  state:
    description:
      - Create or delete the table.
    choices: ['present', 'absent']
    default: 'present'
    type: str
  name:
    description:
      - Name of the table.
    required: true
    type: str
  hash_key_name:
    description:
      - Name of the hash key.
      - Required when I(state=present) and table doesn't exist.
    type: str
  hash_key_type:
    description:
      - Type of the hash key.
      - Defaults to C('STRING') when creating a new table.
    choices: ['STRING', 'NUMBER', 'BINARY']
    type: str
  range_key_name:
    description:
      - Name of the range key.
    type: str
  range_key_type:
    description:
      - Type of the range key.
      - Defaults to C('STRING') when creating a new range key.
    choices: ['STRING', 'NUMBER', 'BINARY']
    type: str
  billing_mode:
    description:
      - Controls whether provisoned pr on-demand tables are created.
    choices: ['PROVISIONED', 'PAY_PER_REQUEST']
    type: str
  read_capacity:
    description:
      - Read throughput capacity (units) to provision.
      - Defaults to C(1) when creating a new table.
    type: int
  write_capacity:
    description:
      - Write throughput capacity (units) to provision.
      - Defaults to C(1) when creating a new table.
    type: int
  indexes:
    description:
      - list of dictionaries describing indexes to add to the table. global indexes can be updated. local indexes don't support updates or have throughput.
      - "required options: ['name', 'type', 'hash_key_name']"
      - "other options: ['hash_key_type', 'range_key_name', 'range_key_type', 'includes', 'read_capacity', 'write_capacity']"
    suboptions:
      name:
        description: The name of the index.
        type: str
        required: true
      type:
        description:
          - The type of index.
        type: str
        required: true
        choices: ['all', 'global_all', 'global_include', 'global_keys_only', 'include', 'keys_only']
      hash_key_name:
        description:
          - The name of the hash-based key.
          - Required if index doesn't already exist.
          - Can not be modified once the index has been created.
        required: false
        type: str
      hash_key_type:
        description:
          - The type of the hash-based key.
          - Defaults to C('STRING') when creating a new index.
          - Can not be modified once the index has been created.
        type: str
        choices: ['STRING', 'NUMBER', 'BINARY']
      range_key_name:
        description:
          - The name of the range-based key.
          - Can not be modified once the index has been created.
        type: str
      range_key_type:
        type: str
        description:
          - The type of the range-based key.
          - Defaults to C('STRING') when creating a new index.
          - Can not be modified once the index has been created.
        choices: ['STRING', 'NUMBER', 'BINARY']
      includes:
        type: list
        description: A list of fields to include when using C(global_include) or C(include) indexes.
        elements: str
      read_capacity:
        description:
          - Read throughput capacity (units) to provision for the index.
        type: int
      write_capacity:
        description:
          - Write throughput capacity (units) to provision for the index.
        type: int
    default: []
    type: list
    elements: dict
  table_class:
    description:
      - The class of the table.
    choices: ['STANDARD', 'STANDARD_INFREQUENT_ACCESS']
    type: str
    version_added: 3.1.0
  wait_timeout:
    description:
      - How long (in seconds) to wait for creation / update / deletion to complete.
      - AWS only allows secondary indexies to be updated one at a time, this module will automatically update them
        in serial, and the timeout will be separately applied for each index.
    aliases: ['wait_for_active_timeout']
    default: 900
    type: int
  wait:
    description:
      - When I(wait=True) the module will wait for up to I(wait_timeout) seconds
        for index updates, table creation or deletion to complete before returning.
    default: True
    type: bool
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.tags
  - amazon.aws.boto3
a  
- name: Create dynamo table with hash and range primary key
  community.aws.dynamodb_table:
    name: my-table
    region: us-east-1
    hash_key_name: id
    hash_key_type: STRING
    range_key_name: create_time
    range_key_type: NUMBER
    read_capacity: 2
    write_capacity: 2
    tags:
      tag_name: tag_value

- name: Update capacity on existing dynamo table
  community.aws.dynamodb_table:
    name: my-table
    region: us-east-1
    read_capacity: 10
    write_capacity: 10

- name: Create pay-per-request table
  community.aws.dynamodb_table:
    name: my-table
    region: us-east-1
    hash_key_name: id
    hash_key_type: STRING
    billing_mode: PAY_PER_REQUEST

- name: set index on existing dynamo table
  community.aws.dynamodb_table:
    name: my-table
    region: us-east-1
    indexes:
      - name: NamedIndex
        type: global_include
        hash_key_name: id
        range_key_name: create_time
        includes:
          - other_field
          - other_field2
        read_capacity: 10
        write_capacity: 10

- name: Delete dynamo table
  community.aws.dynamodb_table:
    name: my-table
    region: us-east-1
    state: absent
a  
table:
  description: The returned table params from the describe API call.
  returned: success
  type: complex
  contains: {}
  sample: {
    "arn": "arn:aws:dynamodb:us-east-1:721066863947:table/ansible-test-table",
    "attribute_definitions": [
        {
            "attribute_name": "id",
            "attribute_type": "N"
        }
    ],
    "billing_mode": "PROVISIONED",
    "creation_date_time": "2022-02-04T13:36:01.578000+00:00",
    "id": "533b45fe-0870-4b66-9b00-d2afcfe96f19",
    "item_count": 0,
    "key_schema": [
        {
            "attribute_name": "id",
            "key_type": "HASH"
        }
    ],
    "name": "ansible-test-14482047-alinas-mbp",
    "provisioned_throughput": {
        "number_of_decreases_today": 0,
        "read_capacity_units": 1,
        "write_capacity_units": 1
    },
    "size": 0,
    "status": "ACTIVE",
    "table_arn": "arn:aws:dynamodb:us-east-1:721066863947:table/ansible-test-table",
    "table_id": "533b45fe-0870-4b66-9b00-d2afcfe96f19",
    "table_name": "ansible-test-table",
    "table_size_bytes": 0,
    "table_status": "ACTIVE",
    "tags": {}
  }
table_status:
  description: The current status of the table.
  returned: success
  type: str
  sample: ACTIVE
    N)camel_dict_to_snake_dict)is_boto3_error_code)AWSRetry)ansible_dict_to_boto3_tag_list)boto3_tag_list_to_ansible_dict)compare_aws_tags)wait_indexes_active)wait_table_exists)wait_table_not_exists)AnsibleCommunityAWSModuleSTRING)nametypehash_key_name)hash_key_typerange_key_namerange_key_typeincludesread_capacitywrite_capacity)all
global_allglobal_includeglobal_keys_onlyinclude	keys_onlySNB)r   NUMBERBINARYc              #   *   K   | ]  \  }}||f  y wN ).0kvs      p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/dynamodb_table.py	<genexpr>r)     s     M1aVMs   -         ResourceInUseExceptionResourceNotFoundExceptionretriesdelay	max_delaycatch_extra_error_codesc                  j    t        j                  ddt        j                  j	                  d      i| S )N	TableNamer   r$   )clientupdate_tablemoduleparamsget)changess    r(   _update_table_with_long_retryr<     s,     N):):6)BNgNN    LimitExceededExceptionr3   c                  ,    t        j                  di | S )Nr$   )r6   describe_table)r9   s    r(   _describe_tablerB   (  s      *6**r=   c                      t        t        t        j                  j                  d      t        j                  j                  d             y Nwait_timeoutr   )r
   r8   r9   r:   r$   r=   r(   wait_existsrF   -  s1    .)&!r=   c                      t        t        t        j                  j                  d      t        j                  j                  d             y rD   )r   r8   r9   r:   r$   r=   r(   wait_not_existsrH   5  s1    .)&!r=   c                      t        t        t        j                  j                  d      t        j                  j                  d             y rD   )r	   r8   r9   r:   r$   r=   r(   wait_indexesrJ   =  s1    .)&!r=   c                 4    | sy t         j                  | d       S r#   )DYNAMO_TYPE_MAP_SHORTr:   )	short_keys    r(   _short_type_to_longrN   E  s     $$Y55r=   c                 4    | sy t         j                  | d       S r#   )DYNAMO_TYPE_MAP_LONGr:   )long_keys    r(   _long_type_to_shortrR   K  s    ##Hd33r=   c                     t        | |      S )N)AttributeNameKeyType)dict)key_namekey_types     r(   _schema_dictrY   Q  s     r=   c                 >    t        |      }|j                  |        |S r#   )rV   update)indexcurrent_indexidxs      r(   _merge_index_paramsr_   X  s    
}
CJJuJr=   c                 J   t        | j                  dg       dd      }t        | j                  dg       dd      }|j                  d      }t        |j                  |d            }|j                  d	d      }t        |j                  |d            }t        ||||
      S )z
    Decodes the primary index info from the current table definition
    splitting it up into the keys we use as parameters
    
key_schemarX   attribute_nametag_name_key_nametag_value_key_nameattribute_definitionsattribute_typeHASHNRANGE)r   r   r   r   )r   r:   rN   rV   )current_tableschema
attributesr   r   r   r   s          r(   _decode_primary_indexrm   ^  s     ,,+$+	F 0126*+	J JJv&M'
}d(KLMZZ.N()MNN##%%	 r=   c                    	 t        | d         }t        |       } || d<   |j                  t        |              | j                  di       }||d<   |r(|j                  d      |d<   |j                  d      |d<   | j                  d	i       }|r,||j                  d
      z   |d<   |j                  dg       |d<   |S # t        $ r"}t
        j                  |d|        Y d }~y d }~ww xY w)N
index_name)r   rf   provisioned_throughputread_capacity_unitsr   write_capacity_unitsr   
projectionprojection_typer   non_key_attributesr   zDecode failure)msg
index_data)rV   r[   rm   r:   	Exceptionr8   fail_json_aws)rw   rl   type_prefix	index_map
throughputrs   es          r(   _decode_indexr~     s    ML)
	 *%
.8
*+.z:;^^$<bA
.8	*+)38M)NIo&*4..9O*PI&'^^L"5
 +jnn=N.O OIf$.NN3G$LIj! MQ$4LLMs   B;B> >	C)C$$C)c                    | s
t               S | j                  d      }t        |       }|j                  d      }|j                  d      }|j                  d      }|j                  d      }t               }| j                  di       }| j                  di       }	|D ]3  }
t        ||
         }|j	                  dd        |j                  |       5 |	D ]3  }
t        |	|
         }|j	                  dd        |j                  |       5 t        ||||||t        j                  | j                  d	d       | j                  d
i       j                  dd       | j                  dd       | j                  di             }|dk(  r<| j                  di       }|j                  dd       |d<   |j                  dd       |d<   |S )Nbilling_moder   r   r   r   _global_index_map_local_index_maprp   
table_nametable_class_summarytable_classtable_statustags)r   r   r   r   indexesr   regionr   r   r   r   PROVISIONEDrq   r   rr   r   )rV   r:   rm   listpopappendr8   r   )rj   r   primary_indexesr   r   r   r   r   global_indexeslocal_indexesr\   r^   compat_resultsr|   s                 r(   compatability_resultsr     s   v $$^4L+M:O#''8M#''8M$(()9:N$(()9:NfG"&&':B?N!%%&8"=M >%()($/s  ='(($/s
 ##%%!}} $$\48!%%&;R@DD]TXY"&&~t<vr*N }$"&&'?D
*4..9NPT*U'+5>>:PRV+W'(r=   c                  D   t         j                  j                  d      } 	 t        |       }d   }	 t        j                  d|d   	      d
   }t              }t        |      }|d   |d<   |d   |d<   |d   |d<   |d   |d<   |d   |d<   ||d<   d|v r|d   d   |d<   d|v r|d   d   |d<   nd|d<   |d   }t               }t               }|j                  dg       D ]  }t!        ||d       }|||d   <    |j                  d!g       D ]  }t!        ||      }|||d   <    ||d"<   ||d#<   |S # t	        d      $ r Y y t
        j                  j                  t
        j                  j                  f$ r"}t         j                  |d       Y d }~jd }~ww xY w# t	        d      $ r t         j                  d       g }Y wt
        j                  j                  t
        j                  j                  f$ r"}t         j                  |d       Y d }~d }~ww xY w)$Nr   r5   r.   zFailed to describe tablerv   TableTTableArn)	aws_retryResourceArnTagsAccessDeniedExceptionz#Permission denied when listing tagszFailed to list table tags	table_arnarnr   r   statustable_ididtable_size_bytessizer   r   r   billing_mode_summaryr   r   rf   global_secondary_indexesglobal_)rz   local_secondary_indexesr   r   )r8   r9   r:   rB   r   botocore
exceptionsClientErrorBotoCoreErrorry   r6   list_tags_of_resourcewarnr   r   rV   r~   )	r   tabler}   r   rl   global_index_maplocal_index_mapr\   r^   s	            r(   get_dynamodb_tabler     sx   ""6*J@*5 'NE	A++djHY+Z[ab *$/D$U+E %E%L,'E&MN+E(O
#E$K,-E&ME&M%$%:;MJm & %&< =n Mn -n ./JvfO5r: ,E:9E(+V%, 4b9 +E:.'*F$+ "2E
 /E
Lo :; '')) @ 	Q$>??	@ 67 9:'')) A 	Q$?@@	As:   D4 F 4F6F:FF%H6H=HHc                  n   t               } t        j                  gt        j                  j                  d      D ]v  }dD ]o  }|j                  |dz         }|s|j                  |dz         xs t        }t        |      }|| v r&|| |   k7  sNt        j                  d|| |   |       k|| |<   q x | S )z+
    Builds a map of Key Names to Type
    r   )hashrange	_key_name	_key_typezConflicting attribute type)rv   type_1type_2rW   )rV   r8   r9   r:   DYNAMO_TYPE_DEFAULTrR   	fail_json)rl   r\   trW   rX   _types         r(   _generate_attribute_mapr     s     J--?&--"3"3I">? -" 	-Ayy[1Hyy[1H5HH'1E:%Jx00$$8zZbOcnv %  (-
8$	--  r=   c                  H    t               } t        | dd      }t        |      S )NrT   AttributeTyperc   )r   r   r   )rl   attrss     r(   _generate_attributesr      s)    (*J +o/E ;r=   c                     | st         j                  } | j                  d      xs d}| j                  d      xs d}t        ||      }|S )Nr      r   ReadCapacityUnitsWriteCapacityUnitsr8   r9   r:   rV   )r9   r   r   r|   s       r(   _generate_throughputr   +  sM    JJ/41MZZ 016QN')J
 r=   c                     | st         j                  } t               }| j                  d      }| j                  d      }|rt	        |d      }|j                  |       |rt	        |d      }|j                  |       |S )Nr   r   rh   ri   )r8   r9   r   r:   rY   r   )r9   rk   r   r   entrys        r(   _generate_schemar   9  sm    VFJJ/MZZ 01N]F3e^W5eMr=   c                 p   t        |       }|j                  d      }t        j                  j                  d      }|j                  d      }t        j                  j                  d      }|j                  d      }t        j                  j                  d      }|j                  d      }t        j                  j                  d      }	t	               }
|r||k7  r|
j                  d       |r||k7  r|
j                  d       |r||k7  r|
j                  d       |	r|	|k7  r|
j                  d       |
S )Nr   r   r   r   )rm   r:   r8   r9   r   r   )rj   primary_indexr   _hash_key_namer   _hash_key_typer   _range_key_namer   _range_key_typechangeds              r(   _primary_index_changesr   K  s   )-8M!%%o6M]]&&7N!%%o6M]]&&7N"&&'78Nmm''(89O"&&'78Nmm''(89OfG>]:'>]:'O~='(O~='(Nr=   c                 (   |st         j                  }| j                  di       }|j                  dd       }|j                  d      xs |}|j                  dd       }|j                  d      xs |}||k7  s||k7  rt        ||      S t               S )Nrp   rq   r   rr   r   r   r   )rj   r9   r|   r   _read_capacityr   _write_capacitys          r(   _throughput_changesr   e  s    ""#;R@JNN#8$?MZZ0AMN^^$:DANjj!12DnO'^-N,.
 	

 6Mr=   c                    t               }t               }d}| dk(  rd}t        j                  j	                  d      D ]  }|j	                  d      dvr|j	                  d      }||v rt        j                  d| d	
       |d   j                         dd  |d<   t        ||      }d||<   |j                  |        |S )NTPAY_PER_REQUESTFr   r   r   r   r   r   Duplicate key  in list of global indexesr      	rV   r   r8   r9   r:   r   upper_generate_indexr   )r   index_existsr   include_throughputr\   r   s         r(   _generate_global_indexesr   x  s    6LfG(("""9- 
99V$XXyy <>$7Q!RSf++-ab1f'9:!Tu
 Nr=   c                  l   t               } t               }t        j                  j	                  d      D ]}  }|j	                  d      dvr|j	                  d      }|| v rt        j                  d| d       |d   j                         |d<   t        |d      }d	| |<   |j                  |        |S )
Nr   r   r   r   r   r   r    in list of local indexesr   FTr   )r   r   r\   r   s       r(   _generate_local_indexesr     s    6LfG""9- 	99V$CCyy <>$7P!QRf++-fu-!Tu	 Nr=   c                 f   t               }| d   }t        j                  j                  d      D ]  }|j                  d      dvr|j                  d      }||v rt        j	                  d| d       t        ||j                  |i             }|d   j                         d	d  |d<   |||<    |S )
Nr   r   r   r   r   r   r   r   r   rV   r8   r9   r:   r   r_   r   )rj   r   existing_indexesr\   r   r^   s         r(   _generate_global_index_mapr     s    v$%89""9- 	%99V$XXyy ##>$7Q!RS!%)9)=)=dB)GH&k'')!"-F!$	% r=   c                 `   t               }| d   }t        j                  j                  d      D ]|  }|j                  d      dvr|j                  d      }||v rt        j	                  d| d       t        ||j                  |i             }|d   j                         |d<   |||<   ~ |S )	Nr   r   r   r   r   r   r   r   r   )rj   r   r   r\   r   r^   s         r(   _generate_local_index_mapr     s    fO$%78""9- 	$99V$CCyy ?">$7P!QR!%)9)=)=dB)GH&k'')F #	$ r=   c                     t        |       }t        |       }| d   xs g }t        | d         }| d   dk7  r|r#||d<   n|rt        j	                  d| d           t        | d   ||      }|r||d	<   |S )
Nr   r   )ProjectionTypeALLNonKeyAttributeszlDynamoDB does not support specifying non-key-attributes ('includes') for indexes of type 'all'. Index name: r   )	IndexName	KeySchema
ProjectionProvisionedThroughput)r   r   rV   r8   r   )r\   r   ra   r|   ru   rs   r^   s          r(   r   r     s    !%(J%e,Jz*0bV}J V}-?J)*-*
 -C '1#$Jr=   c                     t               S r#   )r   rj   s    r(   _attribute_changesr     s    !!r=   c                     | d   }t        |       }| j                  d      }t        j                  j                  d      |}nt        j                  j                  d      }d}|dk(  rd}t	               }|j                         D ]  \  }}t        t        ||            }	||vr|j                  t        |	             <||   }
|}|sFt        t        |
|            }|s^t        ||      }|j                  t        |	              |S )
Nr   r   Tr   F)r   )Create)r   r   )Update)
r   r:   r8   r9   r   itemsrV   r   r   r   )rj   current_global_index_mapr   current_billing_moder   r   index_changesr   current_valuer^   _current_newchanger[   s                 r(   _global_index_changesr    s   ,-@A1-@(,,^<}}(0+}}((8(("FM  0557 >m?=EWXY//  S!12
 05H D!1(DAB!"&.4F "((V)<=%>( r=   c                     g S r#   r$   r   s    r(   _local_index_changesr    s	     Ir=   c                    t               }t               }t        |       }|r||d<   | j                  d      }t        j
                  j                  d      }||}||k7  r||d<   t        j
                  j                  d      rSt        j
                  j                  d      | j                  d      k7  r"t        j
                  j                  d      |d<   t        |       }|r&||d<   ||k(  rt        |      dkD  r|d   g|d<   |dd  }t        |       }|r||d	<   |sy
t        j                  ry|s|rt               |d<   	 t        j                  ddt        j
                  j                  d      d| |r#|D ]  }	t%                	 t'        |	g|d            y# t        j                  j                  t        j                  j                   f$ r!}t        j#                  |d       Y d }~yd }~ww xY w# t        j                  j                  t        j                  j                   f$ r#}t        j#                  |d||       Y d }~d }~ww xY w)Nr   r   BillingModer   
TableClassGlobalSecondaryIndexUpdatesr   r   LocalSecondaryIndexUpdatesFTAttributeDefinitionsr   )r   r5   zFailed to update tabler   )r	  r  )rv   r;   additional_global_index_changesr$   )rV   r   r   r:   r8   r9   r  lenr  
check_moder   r6   r7   r   r   r   r   ry   rJ   r<   )
rj   r;   r  throughput_changesr   new_billing_modeglobal_index_changeslocal_index_changesr}   r\   s
             r(   _update_tabler    sN   fG&*f# -];+='((,,^<}}((8///!1 }}'==]+}/@/@/OO$*MM$5$5m$DGL!0?1E-.
  #33'(1,:Nq:Q9R562Fqr2J/.}=0C,-2*>*@&'>[dfmm6G6G6O[SZ[ '4 	EN
-16gVlNm	 % ++X-@-@-N-NO >Q$<==> ''33X5H5H5V5VW $$0#4S	 %  s0   5F 	G87G5G00G587I/IIc                    t         j                  j                  d      }|yt        | d   t         j                  j                  d      t         j                  j                  d            \  }}|s|syt         j                  ry|r%	 t
        j                  d| d   t        |             |r	 t
        j                  d| d   |
       yy# t        j                  j                  t        j                  j                  f$ r!}t         j                  |d	       Y d }~sd }~ww xY w# t        j                  j                  t        j                  j                  f$ r!}t         j                  |d	       Y d }~yd }~ww xY w)Nr   F
purge_tags)r  Tr   )r   r   r   zFailed to tag tabler   )r   r   TagKeyszFailed to untag table)r8   r9   r:   r   r  r6   tag_resourcer   r   r   r   r   ry   untag_resource)rj   _tagstags_to_addtags_to_remover}   s        r(   _update_tagsr  \  s]   MMf%E}"2fv}}008V]]EVEVWcEd#K
 >	?)%03K@    	A!!)%0& "   ##//1D1D1R1RS 	?  (= >>	? ##//1D1D1R1RS 	A  (? @@	As0   
$C 1D) 7D&D!!D&)7F E<<Fc                     t        |       }|rt        j                  d|        d}|t        |       z  }|t	        |       z  }t        j
                  j                  d      rt                t                |S )NzWDynamoDB does not support updating the Primary keys on a table. Changed paramters are: Fwait)	r   r8   r   r  r  r9   r:   rF   rJ   )rj   primary_index_changesr   s      r(   r7   r7     sp    2=Aef{e|}	
 G}]++G|M**G}} Nr=   c                     t         j                  j                  d      } t         j                  j                  d      }t         j                  j                  d      }t         j                  j                  d      }|d}t        t         j                  j                  d      xs i       }|st         j	                  d       t         j
                  ry|dk(  r
t               }t               }t               }t               }t        |      }	t        | ||||	      }
|r||
d
<   |dk(  r|
d<   |r||
d<   |	r|	|
d<   	 t        j                  dddi|
 t         j                  j                  d      rt'                t)                y# t        j                  j                   t        j                  j"                  f$ r!}t         j%                  |d       Y d }~d }~ww xY w)Nr   r   r   r   r   r   z;"hash_key_name" must be provided when creating a new table.T)r5   r  r   r   r  r  r   LocalSecondaryIndexesGlobalSecondaryIndexesr   zFailed to create tabler   r  r$   )r8   r9   r:   r   r   r  r   r   r   r   r   rV   r6   create_tabler   r   r   r   ry   rF   rJ   )r   r   r   r   r   r|   rl   ra   r   r   r9   r}   s               r(   r#  r#    s   ""6*J--##M2KMM%%o6M==$$^4L$)&--*;*;F*C*IrJDVW}$)+
%'J!#J+-M-l;N' 	F *|}$*4&'*7&'+9'(>5d5f5 }}  ++X-@-@-N-NO >Q$<==>s   =F 7G ?GG c                    | syt         j                  ryt         j                  j                  d      }t	        j
                  dddddg	      }	   |t        j                        |
       t         j                  j                  d      r
t                y# t        d      $ r Y yt        j                  j                  t        j                  j                  f$ r!}t         j                  |d       Y d }~d }~ww xY w)NFTr   r*   r+   r,   r>   r-   r/   r   r.   zFailed to delete tabler   r  )r8   r  r9   r:   r   jittered_backoffr6   delete_tabler   r   r   r   r   ry   rH   )rj   r   
long_retryr}   s       r(   r&  r&    s    ""6*J **!9;S T	J>'
6&&'*= }}  :; '')) > 	Q$<==	>s   B C>'6C>C99C>c                     t        t        dd      t        ddt              t        dd      t        ddt              t        dd      t        ddt              t        ddd      t        dd      t        dd      		      } t        t        d
d
dg      t        dd      t        d      t        dt              t        d      t        dt              t        dddg      t        d      t        d      t        g dd|       t        dddg      t        ddg      t        dd      t        dd      t        dddg            }t        |dd      at        j                  g d       }t        j                  d!|"      at               }d}d }t               }t        j                  j                  d#      }|d
k(  r)|r|t        |      z  }n|t               z  }t               }n|dk(  r|t        |      z  }t        |      }|r|j                  |       ||d$<   |r)|j!                  d%d        |j!                  d&d        ||d'<   t	        j"                  d(i | y ))NstrT)r   required)r   r*  choicesFr   )r   r*  elementsint)	r   r   r   r   r   r   r   r   r   presentabsent)defaultr+  )r*  r   )r   )r   r+  r   r   rV   )r0  r   r,  optionsSTANDARDSTANDARD_INFREQUENT_ACCESSresource_tags)r   aliasesbool)r   r0  i  wait_for_active_timeout)r0  r   r5  )stater   r   r   r   r   r   r   r   r   r   r   r  r  rE   )argument_specsupports_check_modecheck_boto3)r>   r-   r.   r?   dynamodb)retry_decoratorr8  r   r   r   r   r$   )rV   INDEX_TYPE_OPTIONSKEY_TYPE_CHOICESAnsibleAWSModuler8   r   r%  r6   r   r9   r:   r7   r#  r&  r   r[   r   	exit_json)	index_optionsr9  r=  rj   r   r   resultsr8  r   s	            r(   mainrD    s>    ut, ut5GH6?OP7@PQ6EEB67M 9y(.CD4e,&/?@'0@Au}>O.PQ&'Rfv}Uej:V-WXv'89VT2vt,#E<U;VWM$ # F // qO ]]:]GF&(MGEfGMMg&E	|M22G|~%G"$	(	<..*51N~& GI		%t,		$d+ 
wr=   __main__) r#   )T)DDOCUMENTATIONEXAMPLESRETURNr   ImportError0ansible.module_utils.common.dict_transformationsr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   r   r   ?ansible_collections.community.aws.plugins.module_utils.dynamodbr	   r
   r   >ansible_collections.community.aws.plugins.module_utils.modulesr   r@  r   INDEX_REQUIRED_OPTIONSINDEX_OPTIONSr>  rP   rV   r   rL   r   keysr?  r%  r<   rB   rF   rH   rJ   rN   rR   rY   r_   rm   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r7   r#  r&  rD  __name__r$   r=   r(   <module>rU     s  M^1f,
\	 V \ P f f X _ ] a x : & *  i "%D M0D0J0J0LMM ,1134  
57RS	OO
 4LNf3gh+ i+64BM6,^;|2$4&0$  :"
'TDN#L$6rDM ` zF M  		s   D; ;EE