-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28254 from phzietsman/main
d/aws_lambda_functions: new data resource
- Loading branch information
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_lambda_functions | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package lambda | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/lambda" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/create" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
const ( | ||
DSNameFunctions = "Functions Data Source" | ||
) | ||
|
||
func DataSourceFunctions() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceFunctionsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"function_arns": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"function_names": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceFunctionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).LambdaConn | ||
|
||
input := &lambda.ListFunctionsInput{} | ||
|
||
var functionARNs []string | ||
var functionNames []string | ||
|
||
err := conn.ListFunctionsPagesWithContext(ctx, input, func(page *lambda.ListFunctionsOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, function := range page.Functions { | ||
if function == nil { | ||
continue | ||
} | ||
|
||
functionARNs = append(functionARNs, aws.StringValue(function.FunctionArn)) | ||
functionNames = append(functionNames, aws.StringValue(function.FunctionName)) | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return create.DiagError(names.Lambda, create.ErrActionReading, DSNameFunctions, "", err) | ||
} | ||
|
||
d.SetId(meta.(*conns.AWSClient).Region) | ||
d.Set("function_arns", functionARNs) | ||
d.Set("function_names", functionNames) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package lambda_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/lambda" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccLambdaFunctionsDataSource_basic(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
dataSourceName := "data.aws_lambda_functions.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFunctionsDataSourceConfig_basic(rName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "function_arns.#", "0"), | ||
acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "function_names.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccFunctionsDataSourceConfig_basic(rName string) string { | ||
return acctest.ConfigCompose(testAccFunctionConfig_basic(rName, rName, rName, rName), ` | ||
data "aws_lambda_functions" "test" { | ||
depends_on = [aws_lambda_function.test] | ||
} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
subcategory: "Lambda" | ||
layout: "aws" | ||
page_title: "AWS: aws_lambda_functions" | ||
description: |- | ||
Terraform data resource to get a list of Lambda Functions. | ||
--- | ||
|
||
# aws_lambda_functions | ||
|
||
Terraform data resource to get a list of Lambda Functions. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_lambda_functions" "all" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The resource does not support any arguments. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `function_names` - A list of Lambda Function names. | ||
* `function_arns` - A list of Lambda Function ARNs. |