Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement QLDB Ledger resource and data lookup #10394

Merged
merged 6 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
kristiandrucker marked this conversation as resolved.
Show resolved Hide resolved
deletion_protection = false
}

resource "aws_qldb_ledger" "tf_test" {
name = "%[1]s1"
deletion_protection = false
}

resource "aws_qldb_ledger" "tf_wrong2" {
name = "%[1]s1"
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 @@ -73,6 +73,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 @@ -67,6 +67,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 @@ -213,6 +214,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 @@ -241,6 +241,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 @@ -634,6 +635,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_ram_principal_association": resourceAwsRamPrincipalAssociation(),
"aws_ram_resource_association": resourceAwsRamResourceAssociation(),
Expand Down
Loading