
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJ	r	  SSK
Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R,                  " \R.                  R0                  5       " S S\R2                  5      5       rg)zCommand provides active assist recommendations for input Terraform plan.

Step 1: Convert Terraform plan into CAI using terraform tools.
Step 2: Fetches the recommendations using the recommender API for resources in
the CAI output.

    )absolute_import)division)unicode_literalsN)insight)base)flags)EnvironmentVariables)
exceptions)files)"TerraformToolsTfplanToCaiOperationc                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	List(   z;Lists recommendations relevant to the input terraform plan.EXAMPLESzn
        Lists recommendations relevant to the input terraform plan.

        $ {command} tfplan.json
        c                 L    [         R                  " 5       R                  U 5        g)af  Args is called by calliope to gather arguments for this command.

It takes arguments in alphabetical order except for no- or a clear-
pair for that argument which can follow the argument itself.
Args:
  parser: An argparse parser that you can use to add arguments that go
      on the command line after this command. Positional arguments are
      allowed.
N)r   TerraformplanjsonAddToParser)parsers    -lib/surface/terraform/recommendations/list.pyArgs	List.Args5   s     
))&1    c                 "   [        5       n[        5       n[        R                  " 5        n[        R
                  R                  US5      nU" SUR                  SSUR                  SUUR                  S9nUR                  U l
        U R                  S:  a
   S S S 5        g [        R                  " U R                  5       5      nSSS	S
.0n[        R                  " U5       n	 [        R                   " U	5      n
U
 H  nU H  nX;   d  M
  X   S   S	:X  a  S	nOSnUS   S:X  a'  SR)                  US   R+                  S5      S   5      nOML  U(       d  MU  SR)                  UUX   S   5      nUR-                  XR.                  UR0                  5      s  s  sS S S 5        sS S S 5        $    M     S S S 5        S S S 5        g ! [        R"                   a    [$        R&                  " S5      ef = f! , (       d  f       NE= f! , (       d  f       g = f)Nzcai_assets.jsonztfplan-to-cai debug)commandprojectregionzoneterraform_plan_json	verbosityoutput_pathenvr   
iam_policyzgoogle.iam.policy.Insightglobal)insight_typelocationzPlease check the following:
                                 - Input plan file is correct.
                                 - You have appropriate permissions to read
                                 inventory of resources inside the plan file.r'   regional
asset_typez+cloudresourcemanager.googleapis.com/Projectzprojects/{}name/z{}/locations/{}/insightTypes/{}r&   )r	   r   r   TemporaryDirectoryospathjoinr   r    env_vars	exit_coder   CreateClientReleaseTrack
FileReaderjsonloadJSONDecodeErrorr
   Errorformatsplitr   	page_sizelimit)selfargsenvironment_variablestfplan_to_cai_operationtempdir
cai_assetsresponseclientcai_insight_typesfcai_jsonresourcecai_typer'   resource_parentinsight_parents                   r   RunList.RunB   s   02@B		!	!	#w77<<):;j(!'//"66 #,,.h  ))dn	!	  
$	#  ##D$5$5$78f
 9" J'1	"YYq\( !H+h#",Z8HD# & <(BC #0"6"6V$**3/3#  !B!I!I#%/?" {{>>>4::NNK ('; 
$	#N , ! (; 
$	#@ ## 	"   "Q " "	" ('; 
$	#s]   A.H !AH "G/$G:G/AG/AG/	H *G/0H +G,,G//
G=	9H  
H)r2   N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   rM   __static_attributes__ r   r   r   r   (   s1    C - 
2 
2FOr   r   )rS   
__future__r   r   r   r6   os.pathr.   "googlecloudsdk.api_lib.recommenderr   googlecloudsdk.callioper   $googlecloudsdk.command_lib.terraformr   -googlecloudsdk.command_lib.terraform.env_varsr	   googlecloudsdk.corer
   googlecloudsdk.core.utilr   surface.terraform.vetr   ReleaseTracksr4   ALPHAListCommandr   rW   r   r   <module>rd      sn     '  '   6 ( 6 N * * D D%%++,_O4 _O -_Or   