diff --git a/README.md b/README.md index a405dba..14f38b7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # terraform-provider-hdns +[![Go Reference](https://pkg.go.dev/badge/github.com/danielr1996/terraform-provider-hdns.svg)](https://pkg.go.dev/github.com/danielr1996/terraform-provider-hdns) +[![Go Report Card](https://goreportcard.com/badge/github.com/danielr1996/hdns-go)](https://goreportcard.com/report/github.com/danielr1996/hdns-go) +![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/danielr1996/hdns-go?style=flat) +## Usage Add the provider configuration to your `terraform.tf` ```hcl diff --git a/terraform/provider.go b/terraform/provider.go index 5c7dd7e..e4f0e5a 100644 --- a/terraform/provider.go +++ b/terraform/provider.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +// Provider defines the terraform provider func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ @@ -20,7 +21,7 @@ func Provider() *schema.Provider { }, }, ConfigureContextFunc: providerConfigure, - ResourcesMap: map[string]*schema.Resource{ + ResourcesMap: map[string]*schema.Resource{ "hdns_record": record.Resource(), }, DataSourcesMap: map[string]*schema.Resource{ @@ -33,7 +34,7 @@ func Provider() *schema.Provider { func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { token := d.Get("token").(string) var diags diag.Diagnostics - if token == ""{ + if token == "" { return nil, diag.FromErr(errors.New("token must not be empty")) } return client.New().WithToken(token), diags diff --git a/terraform/record/datasource.go b/terraform/record/datasource.go index 1026ac2..bd347d9 100644 --- a/terraform/record/datasource.go +++ b/terraform/record/datasource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +// DataSource defines the terraform datasource for a record func DataSource() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceRecordRead, @@ -55,7 +56,7 @@ func dataSourceRecordRead(_ context.Context, d *schema.ResourceData, m interface c := m.(*client.Client) id, ok := d.GetOk("id") - if !ok{ + if !ok { return diag.Errorf("Please provide a id argument") } record, err := c.Record.GetById(id.(string)) diff --git a/terraform/record/resource.go b/terraform/record/resource.go index 26a41f7..841cdb4 100644 --- a/terraform/record/resource.go +++ b/terraform/record/resource.go @@ -1,6 +1,5 @@ package record - import ( "context" "github.com/danielr1996/hdns-go/client" @@ -8,12 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +// Resource defines the terraform resource for a record func Resource() *schema.Resource { return &schema.Resource{ - CreateContext: Create, - ReadContext: Read, - UpdateContext: Update, - DeleteContext: Delete, + CreateContext: create, + ReadContext: read, + UpdateContext: update, + DeleteContext: delete, Schema: map[string]*schema.Schema{ "type": { Type: schema.TypeString, @@ -38,27 +38,27 @@ func Resource() *schema.Resource { } } -func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*client.Client) recordType := d.Get("type").(string) value := d.Get("value").(string) name := d.Get("name").(string) zoneId := d.Get("zone_id").(string) - record, err := c.Record.Create(name, recordType,value,zoneId) + record, err := c.Record.Create(name, recordType, value, zoneId) if err != nil { return diag.FromErr(err) } d.SetId(record.Id) - Read(ctx, d, m) + read(ctx, d, m) return diags } -func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*client.Client) record, err := c.Record.GetById(d.Id()) - if err != nil{ + if err != nil { return diag.FromErr(err) } if err := d.Set("type", record.Type); err != nil { @@ -76,9 +76,9 @@ func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn return diags } -func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*client.Client) - if d.HasChanges("type","name","value","zone_id"){ + if d.HasChanges("type", "name", "value", "zone_id") { recordType := d.Get("type").(string) value := d.Get("value").(string) name := d.Get("name").(string) @@ -89,10 +89,10 @@ func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia } } - return Read(ctx, d, m) + return read(ctx, d, m) } -func Delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*client.Client) err := c.Record.Delete(d.Id()) diff --git a/terraform/zone/datasource.go b/terraform/zone/datasource.go index c1d87f0..af2ea82 100644 --- a/terraform/zone/datasource.go +++ b/terraform/zone/datasource.go @@ -7,9 +7,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +// DataSource defines the terraform datasource for a zone func DataSource() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceZoneRead, + ReadContext: read, Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, @@ -30,7 +31,7 @@ func DataSource() *schema.Resource { } } -func dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*client.Client) name, ok := d.GetOk("name")