mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 23:54:17 -06:00
3e14f56a96
This data source provides access during configuration to the ID of the AWS account for the connection to AWS. It is primarily useful for interpolating into policy documents, for example when creating the policy for an ELB or ALB access log bucket. This will need revisiting and further testing once the work for AssumeRole is integrated.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSCallerIdentity_basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckAwsCallerIdentityConfig_basic,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAwsCallerIdentityAccountId("data.aws_caller_identity.current"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAwsCallerIdentityAccountId(n string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[n]
|
|
if !ok {
|
|
return fmt.Errorf("Can't find AccountID resource: %s", n)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("Account Id resource ID not set.")
|
|
}
|
|
|
|
expected := testAccProvider.Meta().(*AWSClient).accountid
|
|
if rs.Primary.Attributes["account_id"] != expected {
|
|
return fmt.Errorf("Incorrect Account ID: expected %q, got %q", expected, rs.Primary.ID)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
const testAccCheckAwsCallerIdentityConfig_basic = `
|
|
data "aws_caller_identity" "current" { }
|
|
`
|