Skip to content

Commit

Permalink
Merge pull request #814 from linode/dev
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
zliang-akamai committed May 10, 2023
2 parents 05f2e76 + 16d050f commit f334963
Show file tree
Hide file tree
Showing 130 changed files with 2,522 additions and 3,874 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/acctest_command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
steps:
- name: Generate App Installation Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.DX_ACCTEST_APP_ID }}
private_key: ${{ secrets.DX_ACCTEST_PRIV_KEY }}

- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
env:
TOKEN: ${{ steps.generate_token.outputs.token }}
uses: peter-evans/slash-command-dispatch@v1.2.0
with:
token: ${{ env.TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
issue-type: pull-request
commands: acctest
named-args: true
Expand Down
31 changes: 0 additions & 31 deletions linode/acceptance/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,6 @@ func CheckMySQLDatabaseExists(name string, db *linodego.MySQLDatabase) resource.
}
}

func CheckMongoDatabaseExists(name string, db *linodego.MongoDatabase) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := TestAccProvider.Meta().(*helper.ProviderMeta).Client

rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}

id, err := strconv.Atoi(rs.Primary.ID)
if err != nil {
return fmt.Errorf("Error parsing %v to int", rs.Primary.ID)
}

found, err := client.GetMongoDatabase(context.Background(), id)
if err != nil {
return fmt.Errorf("error retrieving state of mongo database %s: %s", rs.Primary.Attributes["label"], err)
}

if db != nil {
*db = *found
}

return nil
}
}

func CheckPostgresDatabaseExists(name string, db *linodego.PostgresDatabase) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := TestAccProvider.Meta().(*helper.ProviderMeta).Client
Expand Down
45 changes: 0 additions & 45 deletions linode/account/datasource.go

This file was deleted.

4 changes: 2 additions & 2 deletions linode/account/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestAccDataSourceAccount_basic(t *testing.T) {
resourceName := "data.linode_account.foo"

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.TestAccProviders,
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: tmpl.DataBasic(t),
Expand Down
105 changes: 105 additions & 0 deletions linode/account/framework_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package account

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/linode/linodego"
"github.com/linode/terraform-provider-linode/linode/helper"
)

func NewDataSource() datasource.DataSource {
return &DataSource{}
}

type DataSource struct {
client *linodego.Client
}

func (data *DataSourceModel) parseAccount(account *linodego.Account) {
data.Email = types.StringValue(account.Email)
data.FirstName = types.StringValue(account.FirstName)
data.LastName = types.StringValue(account.LastName)
data.Company = types.StringValue(account.Company)
data.Address1 = types.StringValue(account.Address1)
data.Address2 = types.StringValue(account.Address2)
data.Phone = types.StringValue(account.Phone)
data.City = types.StringValue(account.City)
data.State = types.StringValue(account.State)
data.Country = types.StringValue(account.Country)
data.Zip = types.StringValue(account.Zip)
data.Balance = types.Float64Value(float64(account.Balance))
data.ID = types.StringValue(account.Email)
}

func (d *DataSource) Configure(
ctx context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}

meta := helper.GetDataSourceMeta(req, resp)
if resp.Diagnostics.HasError() {
return
}

d.client = meta.Client
}

type DataSourceModel struct {
Email types.String `tfsdk:"email"`
FirstName types.String `tfsdk:"first_name"`
LastName types.String `tfsdk:"last_name"`
Company types.String `tfsdk:"company"`
Address1 types.String `tfsdk:"address_1"`
Address2 types.String `tfsdk:"address_2"`
Phone types.String `tfsdk:"phone"`
City types.String `tfsdk:"city"`
State types.String `tfsdk:"state"`
Country types.String `tfsdk:"country"`
Zip types.String `tfsdk:"zip"`
Balance types.Float64 `tfsdk:"balance"`
ID types.String `tfsdk:"id"`
}

func (d *DataSource) Metadata(
ctx context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = "linode_account"
}

func (d *DataSource) Schema(
ctx context.Context,
req datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = frameworkDatasourceSchema
}

func (d *DataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
client := d.client

var data DataSourceModel

account, err := client.GetAccount(ctx)
if err != nil {
resp.Diagnostics.AddError(
"Unable to get Account: %s", err.Error(),
)
return
}

data.parseAccount(account)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
65 changes: 65 additions & 0 deletions linode/account/framework_datasource_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package account

import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)

var frameworkDatasourceSchema = schema.Schema{
Attributes: map[string]schema.Attribute{
"email": schema.StringAttribute{
Description: "The email address for this Account, for account management communications, " +
"and may be used for other communications as configured.",
Computed: true,
},
"first_name": schema.StringAttribute{
Description: "The first name of the person associated with this Account.",
Computed: true,
},
"last_name": schema.StringAttribute{
Description: "The last name of the person associated with this Account.",
Computed: true,
},
"company": schema.StringAttribute{
Description: "The company name associated with this Account.",
Computed: true,
},
"address_1": schema.StringAttribute{
Description: "First line of this Account's billing address.",
Computed: true,
},
"address_2": schema.StringAttribute{
Description: "Second line of this Account's billing address.",
Computed: true,
},
"phone": schema.StringAttribute{
Description: "The phone number associated with this Account.",
Computed: true,
},
"city": schema.StringAttribute{
Description: "The city for this Account's billing address.",
Computed: true,
},
"state": schema.StringAttribute{
Description: "If billing address is in the United States, " +
"this is the State portion of the Account's billing address. " +
"If the address is outside the US, this is the Province associated with the Account's billing address.",
Computed: true,
},
"country": schema.StringAttribute{
Description: "The two-letter country code of this Account's billing address.",
Computed: true,
},
"zip": schema.StringAttribute{
Description: "The zip code of this Account's billing address.",
Computed: true,
},
"balance": schema.Float64Attribute{
Description: "This Account's balance, in US dollars.",
Computed: true,
},
"id": schema.StringAttribute{
Description: "The Email of the Account.",
Computed: true,
},
},
}
69 changes: 0 additions & 69 deletions linode/account/schema_datasource.go

This file was deleted.

4 changes: 2 additions & 2 deletions linode/accountlogin/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestAccDataSourceLinodeAccountLogin_basic(t *testing.T) {
}

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.TestAccProviders,
PreCheck: func() { acceptance.PreCheck(t) },
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: tmpl.DataBasic(t, accountID),
Expand Down

0 comments on commit f334963

Please sign in to comment.