Skip to content

Commit

Permalink
Implement QLDB Ledger resource and data lookup (#10394)
Browse files Browse the repository at this point in the history
* 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
Kristian Drucker authored and bflad committed Nov 1, 2019
1 parent 83bbe11 commit 5eaabea
Show file tree
Hide file tree
Showing 15 changed files with 792 additions and 0 deletions.
63 changes: 63 additions & 0 deletions aws/data_source_aws_qldb_ledger.go
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
}
52 changes: 52 additions & 0 deletions aws/data_source_aws_qldb_ledger_test.go
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)
}
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var serviceNames = []string{
"neptune",
"opsworks",
"organizations",
"qldb",
"rds",
"route53resolver",
"sagemaker",
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/servicetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var mapServiceNames = []string{
"mediapackage",
"mq",
"opsworks",
"qldb",
"pinpoint",
"resourcegroups",
"securityhub",
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var serviceNames = []string{
"neptune",
"opsworks",
"organizations",
"qldb",
"ram",
"rds",
"redshift",
Expand Down
18 changes: 18 additions & 0 deletions aws/internal/keyvaluetags/list_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/aws/aws-sdk-go/service/organizations"
"github.com/aws/aws-sdk-go/service/pinpoint"
"github.com/aws/aws-sdk-go/service/qldb"
"github.com/aws/aws-sdk-go/service/ram"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/redshift"
Expand Down Expand Up @@ -216,6 +217,8 @@ func ServiceClientType(serviceName string) string {
funcType = reflect.TypeOf(organizations.New)
case "pinpoint":
funcType = reflect.TypeOf(pinpoint.New)
case "qldb":
funcType = reflect.TypeOf(qldb.New)
case "ram":
funcType = reflect.TypeOf(ram.New)
case "rds":
Expand Down
10 changes: 10 additions & 0 deletions aws/internal/keyvaluetags/service_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions aws/internal/keyvaluetags/update_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func Provider() terraform.ResourceProvider {
"aws_partition": dataSourceAwsPartition(),
"aws_prefix_list": dataSourceAwsPrefixList(),
"aws_pricing_product": dataSourceAwsPricingProduct(),
"aws_qldb_ledger": dataSourceAwsQLDBLedger(),
"aws_ram_resource_share": dataSourceAwsRamResourceShare(),
"aws_rds_cluster": dataSourceAwsRdsCluster(),
"aws_redshift_cluster": dataSourceAwsRedshiftCluster(),
Expand Down Expand Up @@ -652,6 +653,7 @@ func Provider() terraform.ResourceProvider {
"aws_organizations_organizational_unit": resourceAwsOrganizationsOrganizationalUnit(),
"aws_placement_group": resourceAwsPlacementGroup(),
"aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(),
"aws_qldb_ledger": resourceAwsQLDBLedger(),
"aws_quicksight_group": resourceAwsQuickSightGroup(),
"aws_quicksight_user": resourceAwsQuickSightUser(),
"aws_ram_principal_association": resourceAwsRamPrincipalAssociation(),
Expand Down
Loading

0 comments on commit 5eaabea

Please sign in to comment.