Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f/aws_codepipeline add support for pipeline_type and variable #34841

Merged
merged 27 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08affc5
enhancement
Dec 10, 2023
4884045
Merge branch 'main' into HEAD
ewbankkit Jan 8, 2024
59a94d9
r/aws_codepipeline_webhook: Alphabetize attributes.
ewbankkit Jan 8, 2024
c5b68b1
r/aws_codepipeline_webhook: Tidy up Create.
ewbankkit Jan 8, 2024
957de77
r/aws_codepipeline_webhook: Tidy up Read.
ewbankkit Jan 8, 2024
5e36b52
r/aws_codepipeline_webhook: Tidy up Delete.
ewbankkit Jan 8, 2024
aa97a95
r/aws_codepipeline_webhook: Tidy up Update.
ewbankkit Jan 8, 2024
891b267
r/aws_codepipeline_webhook: Handle 'WebhookNotFoundException' on Delete.
ewbankkit Jan 8, 2024
19610b1
r/aws_codepipeline_custom_action_type: Cosmetics.
ewbankkit Jan 8, 2024
1398739
r/aws_codepipeline: Alphabetize attributes.
ewbankkit Jan 8, 2024
8289559
r/aws_codepipeline: Tidy up Read.
ewbankkit Jan 8, 2024
ff2aff3
r/aws_codepipeline: Tidy up Update.
ewbankkit Jan 8, 2024
d73184f
r/aws_codepipeline: Tidy up Delete.
ewbankkit Jan 8, 2024
4847ebe
codepipeline: Use AWS SDK for Go v2.
ewbankkit Jan 8, 2024
63d6d82
Run 'go get github.com/aws/aws-sdk-go-v2/service/codepipeline@v1.22.6…
ewbankkit Jan 8, 2024
e796f47
Tweak CHANGELOG entry.
ewbankkit Jan 8, 2024
6179e83
Add 'names.CodePipelineEndpointID'.
ewbankkit Jan 8, 2024
231caaf
r/aws_codepipeline_webhook: Migrate to AWS SDK for Go v2.
ewbankkit Jan 8, 2024
9d9722d
r/aws_codepipeline_custom_action_type: Migrate to AWS SDK for Go v2.
ewbankkit Jan 8, 2024
be6d9f4
r/aws_codepipeline: Migrate to AWS SDK for Go v2.
ewbankkit Jan 8, 2024
3057f44
codepipeline: Migrate sweepers to AWS SDK for Go v2.
ewbankkit Jan 8, 2024
d97c6b0
codepipeline: Migrate acceptance tests to AWS SDK for Go v2.
ewbankkit Jan 8, 2024
60e8b66
Fix terrafmt errors in acceptance test configurations.
ewbankkit Jan 8, 2024
6d7773c
Fix golangci-lint 'unparam'.
ewbankkit Jan 8, 2024
8e27484
Fix semgrep 'ci.semgrep.aws.prefer-pointer-conversion-assignment'.
ewbankkit Jan 8, 2024
99f5311
r/aws_codepipeline_webhook: Fix 'missing required field, PutWebhookIn…
ewbankkit Jan 8, 2024
544e7bc
Fix golangci-lint 'unparam'.
ewbankkit Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34122.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_codepipeline: Add `pipeline_type`, `variable` attribute
```
128 changes: 128 additions & 0 deletions internal/service/codepipeline/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
validation.StringMatch(regexache.MustCompile(`[0-9A-Za-z_.@-]+`), ""),
),
},
"pipeline_type": {
Type: schema.TypeString,
Optional: true,
Default: codepipeline.PipelineTypeV1,
ValidateFunc: validation.StringInSlice(codepipeline.PipelineType_Values(), false),
},
"role_arn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -208,6 +214,26 @@
},
},
},
"variable": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_value": {
Type: schema.TypeString,
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
},
},
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},
Expand Down Expand Up @@ -285,6 +311,12 @@
d.Set("name", pipeline.Name)
d.Set("role_arn", pipeline.RoleArn)

d.Set("pipeline_type", pipeline.PipelineType)

if err := d.Set("variable", flattenVariableDeclarations(d, pipeline.Variables)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting variable: %s", err)
}

return diags
}

Expand Down Expand Up @@ -435,6 +467,10 @@
apiObject.Name = aws.String(v.(string))
}

if v, ok := d.GetOk("pipeline_type"); ok {
apiObject.PipelineType = aws.String(v.(string))
}

if v, ok := d.GetOk("role_arn"); ok {
apiObject.RoleArn = aws.String(v.(string))
}
Expand All @@ -443,6 +479,10 @@
apiObject.Stages = expandStageDeclarations(v.([]interface{}))
}

if v, ok := d.GetOk("variable"); ok && len(v.([]interface{})) > 0 {
apiObject.Variables = expandVariableDeclarations(v.([]interface{}))
}

return apiObject, nil
}

Expand Down Expand Up @@ -696,6 +736,54 @@
return apiObjects
}

func expandVariableDeclaration(tfMap map[string]interface{}) *codepipeline.PipelineVariableDeclaration {
if tfMap == nil {
return nil
}

apiObject := &codepipeline.PipelineVariableDeclaration{}

if v, ok := tfMap["default_value"].(string); ok && v != "" {
apiObject.DefaultValue = aws.String(v)
}

if v, ok := tfMap["description"].(string); ok && v != "" {
apiObject.Description = aws.String(v)
}

if v, ok := tfMap["name"].(string); ok && v != "" {
apiObject.Name = aws.String(v)
}

return apiObject
}

func expandVariableDeclarations(tfList []interface{}) []*codepipeline.PipelineVariableDeclaration {
if len(tfList) == 0 {
return nil
}

var apiObjects []*codepipeline.PipelineVariableDeclaration

for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]interface{})

if !ok {
continue
}

apiObject := expandVariableDeclaration(tfMap)

if apiObject == nil {
continue
}

apiObjects = append(apiObjects, apiObject)
}

return apiObjects
}

func flattenArtifactStore(apiObject *codepipeline.ArtifactStore) map[string]interface{} {
if apiObject == nil {
return nil
Expand Down Expand Up @@ -918,3 +1006,43 @@

return aws.StringValueSlice(tfList)
}

func flattenVariableDeclaration(d *schema.ResourceData, i int, apiObject *codepipeline.PipelineVariableDeclaration) map[string]interface{} {

Check failure on line 1010 in internal/service/codepipeline/codepipeline.go

View workflow job for this annotation

GitHub Actions / 2 of 2

`flattenVariableDeclaration` - `d` is unused (unparam)
if apiObject == nil {
return nil
}

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

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

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

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

return tfMap
}

func flattenVariableDeclarations(d *schema.ResourceData, apiObjects []*codepipeline.PipelineVariableDeclaration) []interface{} {
if len(apiObjects) == 0 {
return nil
}

var tfList []interface{}

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

tfList = append(tfList, flattenVariableDeclaration(d, i, apiObject))
}

return tfList
}