Skip to content

Commit

Permalink
Merge pull request #12130 from tellnes/codebuild_efs
Browse files Browse the repository at this point in the history
resource/aws_codebuild_project - add `file_system_locations`
  • Loading branch information
ewbankkit authored Apr 30, 2021
2 parents 2a9c843 + cbe9491 commit 66da654
Show file tree
Hide file tree
Showing 4 changed files with 668 additions and 226 deletions.
3 changes: 3 additions & 0 deletions .changelog/12130.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_codebuild_project: Add `file_system_locations` argument
```
148 changes: 139 additions & 9 deletions aws/resource_aws_codebuild_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,36 @@ func resourceAwsCodeBuildProject() *schema.Resource {
},
},
},
"file_system_locations": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Type: schema.TypeString,
Optional: true,
},
"location": {
Type: schema.TypeString,
Optional: true,
},
"mount_options": {
Type: schema.TypeString,
Optional: true,
},
"mount_point": {
Type: schema.TypeString,
Optional: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Default: codebuild.FileSystemTypeEfs,
ValidateFunc: validation.StringInSlice(codebuild.FileSystemType_Values(), false),
},
},
},
},
"logs_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -659,6 +689,7 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{})
projectSecondarySources := expandProjectSecondarySources(d)
projectLogsConfig := expandProjectLogsConfig(d)
projectBatchConfig := expandCodeBuildBuildBatchConfig(d)
projectFileSystemLocations := expandProjectFileSystemLocations(d)

if aws.StringValue(projectSource.Type) == codebuild.SourceTypeNoSource {
if aws.StringValue(projectSource.Buildspec) == "" {
Expand All @@ -671,15 +702,16 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{})
}

params := &codebuild.CreateProjectInput{
Environment: projectEnv,
Name: aws.String(d.Get("name").(string)),
Source: &projectSource,
Artifacts: &projectArtifacts,
SecondaryArtifacts: projectSecondaryArtifacts,
SecondarySources: projectSecondarySources,
LogsConfig: projectLogsConfig,
BuildBatchConfig: projectBatchConfig,
Tags: tags.IgnoreAws().CodebuildTags(),
Environment: projectEnv,
Name: aws.String(d.Get("name").(string)),
Source: &projectSource,
Artifacts: &projectArtifacts,
SecondaryArtifacts: projectSecondaryArtifacts,
SecondarySources: projectSecondarySources,
LogsConfig: projectLogsConfig,
BuildBatchConfig: projectBatchConfig,
FileSystemLocations: projectFileSystemLocations,
Tags: tags.IgnoreAws().CodebuildTags(),
}

if v, ok := d.GetOk("cache"); ok {
Expand Down Expand Up @@ -753,6 +785,47 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{})
return resourceAwsCodeBuildProjectRead(d, meta)
}

func expandProjectFileSystemLocations(d *schema.ResourceData) []*codebuild.ProjectFileSystemLocation {
fileSystemLocations := make([]*codebuild.ProjectFileSystemLocation, 0)

configsList := d.Get("file_system_locations").(*schema.Set).List()

if len(configsList) == 0 {
return nil
}

for _, config := range configsList {
art := expandProjectFileSystemLocation(config.(map[string]interface{}))
fileSystemLocations = append(fileSystemLocations, &art)
}

return fileSystemLocations
}

func expandProjectFileSystemLocation(data map[string]interface{}) codebuild.ProjectFileSystemLocation {
projectFileSystemLocation := codebuild.ProjectFileSystemLocation{
Type: aws.String(data["type"].(string)),
}

if data["identifier"].(string) != "" {
projectFileSystemLocation.Identifier = aws.String(data["identifier"].(string))
}

if data["location"].(string) != "" {
projectFileSystemLocation.Location = aws.String(data["location"].(string))
}

if data["mount_options"].(string) != "" {
projectFileSystemLocation.MountOptions = aws.String(data["mount_options"].(string))
}

if data["mount_point"].(string) != "" {
projectFileSystemLocation.MountPoint = aws.String(data["mount_point"].(string))
}

return projectFileSystemLocation
}

func expandProjectSecondaryArtifacts(d *schema.ResourceData) []*codebuild.ProjectArtifacts {
artifacts := make([]*codebuild.ProjectArtifacts, 0)

Expand Down Expand Up @@ -1191,6 +1264,10 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("error setting environment: %s", err)
}

if err := d.Set("file_system_locations", flattenAwsCodeBuildProjectFileSystemLocations(project.FileSystemLocations)); err != nil {
return fmt.Errorf("error setting file_system_locations: %s", err)
}

if err := d.Set("cache", flattenAwsCodebuildProjectCache(project.Cache)); err != nil {
return fmt.Errorf("error setting cache: %s", err)
}
Expand Down Expand Up @@ -1264,6 +1341,11 @@ func resourceAwsCodeBuildProjectUpdate(d *schema.ResourceData, meta interface{})
params.Environment = projectEnv
}

if d.HasChange("file_system_locations") {
projectFileSystemLocations := expandProjectFileSystemLocations(d)
params.FileSystemLocations = projectFileSystemLocations
}

if d.HasChange("source") {
projectSource := expandProjectSource(d)
params.Source = &projectSource
Expand Down Expand Up @@ -1394,6 +1476,54 @@ func resourceAwsCodeBuildProjectDelete(d *schema.ResourceData, meta interface{})
return err
}

func flattenAwsCodeBuildProjectFileSystemLocations(apiObjects []*codebuild.ProjectFileSystemLocation) []interface{} {
if len(apiObjects) == 0 {
return nil
}

var tfList []interface{}

for _, apiObject := range apiObjects {
if apiObject == nil {
continue
}

tfList = append(tfList, flattenAwsCodeBuildProjectFileSystemLocation(apiObject))
}

return tfList
}

func flattenAwsCodeBuildProjectFileSystemLocation(apiObject *codebuild.ProjectFileSystemLocation) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := map[string]interface{}{}

if v := apiObject.Identifier; v != nil {
tfMap["identifier"] = aws.StringValue(v)
}

if v := apiObject.Location; v != nil {
tfMap["location"] = aws.StringValue(v)
}

if v := apiObject.MountOptions; v != nil {
tfMap["mount_options"] = aws.StringValue(v)
}

if v := apiObject.MountPoint; v != nil {
tfMap["mount_point"] = aws.StringValue(v)
}

if v := apiObject.Type; v != nil {
tfMap["type"] = aws.StringValue(v)
}

return tfMap
}

func flattenAwsCodeBuildLogsConfig(logsConfig *codebuild.LogsConfig) []interface{} {
if logsConfig == nil {
return []interface{}{}
Expand Down
Loading

0 comments on commit 66da654

Please sign in to comment.