github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/internal/adapters/terraform/google/iam/projects.go (about)

     1  package iam
     2  
     3  import (
     4  	"github.com/khulnasoft-lab/defsec/pkg/providers/google/iam"
     5  )
     6  
     7  type parentedProject struct {
     8  	blockID       string
     9  	orgBlockID    string
    10  	folderBlockID string
    11  	id            string
    12  	orgID         string
    13  	folderID      string
    14  	project       iam.Project
    15  }
    16  
    17  func (a *adapter) adaptProjects() {
    18  	for _, projectBlock := range a.modules.GetResourcesByType("google_project") {
    19  		var project parentedProject
    20  		project.project.Metadata = projectBlock.GetMetadata()
    21  		idAttr := projectBlock.GetAttribute("project_id")
    22  		if !idAttr.IsString() {
    23  			continue
    24  		}
    25  		project.id = idAttr.Value().AsString()
    26  
    27  		project.blockID = projectBlock.ID()
    28  
    29  		orgAttr := projectBlock.GetAttribute("org_id")
    30  		if orgAttr.IsString() {
    31  			project.orgID = orgAttr.Value().AsString()
    32  		}
    33  		folderAttr := projectBlock.GetAttribute("folder_id")
    34  		if folderAttr.IsString() {
    35  			project.folderID = folderAttr.Value().AsString()
    36  		}
    37  
    38  		autoCreateNetworkAttr := projectBlock.GetAttribute("auto_create_network")
    39  		project.project.AutoCreateNetwork = autoCreateNetworkAttr.AsBoolValueOrDefault(true, projectBlock)
    40  
    41  		if orgAttr.IsNotNil() {
    42  			if referencedBlock, err := a.modules.GetReferencedBlock(orgAttr, projectBlock); err == nil {
    43  				if referencedBlock.TypeLabel() == "google_organization" {
    44  					project.orgBlockID = referencedBlock.ID()
    45  					a.addOrg(project.orgBlockID)
    46  				}
    47  			}
    48  		}
    49  		if folderAttr.IsNotNil() {
    50  			if referencedBlock, err := a.modules.GetReferencedBlock(folderAttr, projectBlock); err == nil {
    51  				if referencedBlock.TypeLabel() == "google_folder" {
    52  					project.folderBlockID = referencedBlock.ID()
    53  				}
    54  			}
    55  		}
    56  		a.projects = append(a.projects, project)
    57  	}
    58  }