Skip to content

Commit

Permalink
Merge pull request #40191 from AP-Hunt/f_support-codebuild-using-code…
Browse files Browse the repository at this point in the history
…star-connection

Support AWS CodeBuild using CodeStar Connection
  • Loading branch information
ewbankkit authored Mar 10, 2025
2 parents 5501413 + 95f8f10 commit bf5b10c
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .changelog/40191.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_codebuild_project: Add `secondary_sources.auth` configuration block
```
68 changes: 68 additions & 0 deletions internal/service/codebuild/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,25 @@ func resourceProject() *schema.Resource {
MaxItems: 12,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource": {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidARN,
},
names.AttrType: {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: enum.Validate[types.AuthType](),
},
},
},
},
"build_status_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -613,6 +632,25 @@ func resourceProject() *schema.Resource {
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrType: {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: enum.Validate[types.AuthType](),
},
"resource": {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidARN,
},
},
},
},
"build_status_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1638,6 +1676,21 @@ func expandProjectSource(tfMap map[string]interface{}) *types.ProjectSource {
}
}

if v, ok := tfMap["auth"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
tfMap := v[0].(map[string]interface{})

sourceAuthConfig := &types.SourceAuth{}

if v, ok := tfMap["resource"].(string); ok && v != "" {
sourceAuthConfig.Resource = aws.String(v)
}
if v, ok := tfMap[names.AttrType].(string); ok && v != "" {
sourceAuthConfig.Type = types.SourceAuthType(v)
}

apiObject.Auth = sourceAuthConfig
}

return apiObject
}

Expand Down Expand Up @@ -1903,6 +1956,8 @@ func flattenProjectSource(apiObject *types.ProjectSource) map[string]interface{}
tfMap["source_identifier"] = aws.ToString(apiObject.SourceIdentifier)
}

tfMap["auth"] = flattenSourceAuth(apiObject.Auth)

return tfMap
}

Expand Down Expand Up @@ -2020,6 +2075,19 @@ func flattenEnvironmentVariables(apiObjects []types.EnvironmentVariable) []inter
return tfList
}

func flattenSourceAuth(apiObject *types.SourceAuth) []interface{} {
if apiObject == nil {
return []interface{}{}
}

tfMap := map[string]interface{}{
"resource": aws.ToString(apiObject.Resource),
names.AttrType: apiObject.Type,
}

return []interface{}{tfMap}
}

func ValidProjectName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexache.MustCompile(`^[0-9A-Za-z]`).MatchString(value) {
Expand Down
Loading

0 comments on commit bf5b10c

Please sign in to comment.