-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement QLDB Ledger resource and data lookup (#10394)
* Implement QLDB Ledger resource and data lookup * Format QLDB Ledger and fix code * Move resource tagging for QLDB resource to generated tags * Resolve issues in PR for QLDB Ledger implementation * Removed hardcoded permissions_mode and unused test retry func * Remove permissions_mode argument from docs
- Loading branch information
Showing
15 changed files
with
792 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,63 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/qldb" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
|
||
"log" | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceAwsQLDBLedger() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsQLDBLedgerRead, | ||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.All( | ||
validation.StringLenBetween(1, 32), | ||
validation.StringMatch(regexp.MustCompile(`^[A-Za-z0-9_-]+`), "must contain only alphanumeric characters, underscores, and hyphens"), | ||
), | ||
}, | ||
|
||
"deletion_protection": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsQLDBLedgerRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).qldbconn | ||
|
||
target := d.Get("name") | ||
|
||
req := &qldb.DescribeLedgerInput{ | ||
Name: aws.String(target.(string)), | ||
} | ||
|
||
log.Printf("[DEBUG] Reading QLDB Ledger: %s", req) | ||
resp, err := conn.DescribeLedger(req) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error describing ledger: %s", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(resp.Name)) | ||
d.Set("arn", resp.Arn) | ||
d.Set("deletion_protection", resp.DeletionProtection) | ||
|
||
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,52 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsQLDBLedger(t *testing.T) { | ||
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(7)) // QLDB name cannot be longer than 32 characters | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsQLDBLedgerConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair("data.aws_qldb_ledger.by_name", "arn", "aws_qldb_ledger.tf_test", "arn"), | ||
resource.TestCheckResourceAttrPair("data.aws_qldb_ledger.by_name", "deletion_protection", "aws_qldb_ledger.tf_test", "deletion_protection"), | ||
resource.TestCheckResourceAttrPair("data.aws_qldb_ledger.by_name", "name", "aws_qldb_ledger.tf_test", "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsQLDBLedgerConfig(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_qldb_ledger" "tf_wrong1" { | ||
name = "%[1]s1" | ||
deletion_protection = false | ||
} | ||
resource "aws_qldb_ledger" "tf_test" { | ||
name = "%[1]s2" | ||
deletion_protection = false | ||
} | ||
resource "aws_qldb_ledger" "tf_wrong2" { | ||
name = "%[1]s3" | ||
deletion_protection = false | ||
} | ||
data "aws_qldb_ledger" "by_name" { | ||
name = "${aws_qldb_ledger.tf_test.name}" | ||
} | ||
`, rName) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.