-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #25781 from sasidhar-aws/f-aws_s3_account_public_a…
…ccess_block d/aws_s3_account_public_access_block - new data source
- Loading branch information
Showing
5 changed files
with
164 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-data-source | ||
aws_s3_account_public_access_block | ||
``` |
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
76 changes: 76 additions & 0 deletions
76
internal/service/s3control/account_public_access_block_data_source.go
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,76 @@ | ||
package s3control | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/s3control" | ||
"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/verify" | ||
) | ||
|
||
func DataSourceAccountPublicAccessBlock() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceAccountPublicAccessBlockRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"account_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: verify.ValidAccountID, | ||
}, | ||
"block_public_acls": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"block_public_policy": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"ignore_public_acls": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"restrict_public_buckets": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).S3ControlConn | ||
|
||
accountID := meta.(*conns.AWSClient).AccountID | ||
if v, ok := d.GetOk("account_id"); ok { | ||
accountID = v.(string) | ||
} | ||
|
||
input := &s3control.GetPublicAccessBlockInput{ | ||
AccountId: aws.String(accountID), | ||
} | ||
|
||
log.Printf("[DEBUG] Reading Account access block: %s", input) | ||
|
||
output, err := conn.GetPublicAccessBlock(input) | ||
|
||
if err != nil { | ||
return diag.Errorf("error reading S3 Account Public Access Block: %s", err) | ||
} | ||
|
||
if output == nil || output.PublicAccessBlockConfiguration == nil { | ||
return diag.Errorf("error reading S3 Account Public Access Block (%s): missing public access block configuration", accountID) | ||
} | ||
|
||
d.SetId(accountID) | ||
d.Set("block_public_acls", output.PublicAccessBlockConfiguration.BlockPublicAcls) | ||
d.Set("block_public_policy", output.PublicAccessBlockConfiguration.BlockPublicPolicy) | ||
d.Set("ignore_public_acls", output.PublicAccessBlockConfiguration.IgnorePublicAcls) | ||
d.Set("restrict_public_buckets", output.PublicAccessBlockConfiguration.RestrictPublicBuckets) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
internal/service/s3control/account_public_access_block_data_source_test.go
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,49 @@ | ||
package s3control_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/s3control" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccS3ControlAccountPublicAccessBlockDataSource_basic(t *testing.T) { | ||
resourceName := "aws_s3_account_public_access_block.test" | ||
dataSourceName := "data.aws_s3_account_public_access_block.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), | ||
ProviderFactories: acctest.ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccountPublicAccessBlockDataSourceConfig_basic(), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(resourceName, "block_public_acls", dataSourceName, "block_public_acls"), | ||
resource.TestCheckResourceAttrPair(resourceName, "block_public_policy", dataSourceName, "block_public_policy"), | ||
resource.TestCheckResourceAttrPair(resourceName, "ignore_public_acls", dataSourceName, "ignore_public_acls"), | ||
resource.TestCheckResourceAttrPair(resourceName, "restrict_public_buckets", dataSourceName, "restrict_public_buckets"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAccountPublicAccessBlockDataSourceConfig_base() string { | ||
return ` | ||
resource "aws_s3_account_public_access_block" "test" { | ||
block_public_acls = false | ||
block_public_policy = false | ||
ignore_public_acls = false | ||
restrict_public_buckets = false | ||
} | ||
` | ||
} | ||
|
||
func testAccAccountPublicAccessBlockDataSourceConfig_basic() string { | ||
return acctest.ConfigCompose(testAccAccountPublicAccessBlockDataSourceConfig_base(), ` | ||
data "aws_s3_account_public_access_block" "test" { | ||
depends_on = [aws_s3_account_public_access_block.test] | ||
} | ||
`) | ||
} |
34 changes: 34 additions & 0 deletions
34
website/docs/d/s3_account_public_access_block.html.markdown
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,34 @@ | ||
--- | ||
subcategory: "S3 Control" | ||
layout: "aws" | ||
page_title: "AWS: aws_s3_account_public_access_block" | ||
description: |- | ||
Provides S3 account-level Public Access Block Configuration | ||
--- | ||
|
||
# Data Source: aws_s3_account_public_access_block | ||
|
||
The S3 account public access block data source returns account-level public access block configuration. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_s3_account_public_access_block" "example" { | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `account_id` - (Optional) AWS account ID to configure. Defaults to automatically determined account ID of the Terraform AWS provider. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - AWS account ID | ||
* `block_public_acls` - Whether or not Amazon S3 should block public ACLs for buckets in this account is enabled. Returns as `true` or `false`. | ||
* `block_public_policy` - Whether or not Amazon S3 should block public bucket policies for buckets in this account is enabled. Returns as `true` or `false`. | ||
* `ignore_public_acls` - Whether or not Amazon S3 should ignore public ACLs for buckets in this account is enabled. Returns as `true` or `false`. | ||
* `restrict_public_buckets` - Whether or not Amazon S3 should restrict public bucket policies for buckets in this account is enabled. Returns as `true` or `false`. |