-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from linode/dev
Release v2.1.0
- Loading branch information
Showing
130 changed files
with
2,522 additions
and
3,874 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
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 was deleted.
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
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,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)...) | ||
} |
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,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, | ||
}, | ||
}, | ||
} |
This file was deleted.
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.