Skip to content

Commit

Permalink
Cleanup patch set (#370)
Browse files Browse the repository at this point in the history
The [next upgrade](#369)
failed because upstream changed their docs structure. We are compatible
with the new docs structure, but our patches are not.

I'm going to remove ~as much of~ the docs patch set as I can without any
loss in quality before I try to run the update.
  • Loading branch information
iwahbe authored Oct 4, 2023
1 parent 998bdb4 commit 0d21714
Show file tree
Hide file tree
Showing 63 changed files with 220 additions and 571 deletions.
81 changes: 81 additions & 0 deletions patches/0001-boot-check.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
From 40c25889d7bd84dc1991d61e14cb95daede318ff Mon Sep 17 00:00:00 2001
From: Ian Wahbe <[email protected]>
Date: Wed, 4 Oct 2023 13:19:23 -0700
Subject: [PATCH 1/2] boot check

---
linode/instance/helpers.go | 5 +++--
linode/instance/resource.go | 12 ++++--------
2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/linode/instance/helpers.go b/linode/instance/helpers.go
index 4815d968..58604619 100644
--- a/linode/instance/helpers.go
+++ b/linode/instance/helpers.go
@@ -1004,13 +1004,14 @@ func isInstanceBooted(instance *linodego.Instance) bool {

func validateBooted(ctx context.Context, d *schema.ResourceData) error {
booted := d.Get("booted").(bool)
- bootedNull := d.GetRawConfig().GetAttr("booted").IsNull()

+ // FORK: we don't need to check the rawConfig for the boote
+ // this doesn't work for us
_, imageOk := d.GetOk("image")
_, disksOk := d.GetOk("disk")
_, configsOk := d.GetOk("config")

- if !bootedNull && booted && !imageOk && !(disksOk && configsOk) {
+ if booted && !imageOk && !(disksOk && configsOk) {
return fmt.Errorf("booted requires an image or disk/config be defined")
}

diff --git a/linode/instance/resource.go b/linode/instance/resource.go
index 61446cd8..717231bd 100644
--- a/linode/instance/resource.go
+++ b/linode/instance/resource.go
@@ -200,7 +200,6 @@ func createResource(ctx context.Context, d *schema.ResourceData, meta interface{

_, disksOk := d.GetOk("disk")
_, configsOk := d.GetOk("config")
- bootedNull := d.GetRawConfig().GetAttr("booted").IsNull()
booted := d.Get("booted").(bool)

// If we don't have disks and we don't have configs, use the single API call approach
@@ -232,10 +231,6 @@ func createResource(ctx context.Context, d *schema.ResourceData, meta interface{

createOpts.Booted = &boolTrue

- if !d.GetRawConfig().GetAttr("booted").IsNull() {
- createOpts.Booted = &booted
- }
-
createOpts.BackupID = d.Get("backup_id").(int)
if swapSize := d.Get("swap_size").(int); swapSize > 0 {
createOpts.SwapSize = &swapSize
@@ -380,7 +375,7 @@ func createResource(ctx context.Context, d *schema.ResourceData, meta interface{
targetStatus := linodego.InstanceRunning

if createOpts.Booted == nil || !*createOpts.Booted {
- if disksOk && configsOk && (bootedNull || booted) {
+ if disksOk && configsOk && booted {
p, err := client.NewEventPoller(ctx, instance.ID, linodego.EntityLinode, linodego.ActionLinodeBoot)
if err != nil {
return diag.Errorf("failed to initialize event poller: %s", err)
@@ -653,11 +648,12 @@ func updateResource(ctx context.Context, d *schema.ResourceData, meta interface{
}
}

+ // FORK: we don't need to check the rawConfig for the boote
+ // this doesn't work for us
booted := d.Get("booted").(bool)
- bootedNull := d.GetRawConfig().GetAttr("booted").IsNull()

// Don't reboot if the Linode should be powered off
- if !bootedNull && !booted {
+ if !booted {
rebootInstance = false
}

--
2.42.0

277 changes: 0 additions & 277 deletions patches/0001-fork.patch

This file was deleted.

29 changes: 15 additions & 14 deletions provider/cmd/pulumi-resource-linode/schema.json

Large diffs are not rendered by default.

181 changes: 44 additions & 137 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (
// embed is used to store bridge-metadata.json in the compiled binary
_ "embed"
"path/filepath"
"regexp"
"unicode"

"github.com/linode/terraform-provider-linode/linode"
"github.com/pulumi/pulumi-linode/provider/v4/pkg/version"
pfbridge "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
tfbridgetokens "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"

"github.com/linode/terraform-provider-linode/linode"
"github.com/pulumi/pulumi-linode/provider/v4/pkg/version"
)

// all of the token components used below.
Expand Down Expand Up @@ -68,16 +68,33 @@ func makeResource(mod string, res string) tokens.Type {
return makeType(mod+"/"+fn, res)
}

// preConfigureCallback is called before the providerConfigure function of the underlying provider.
// It should validate that the provider can be configured, and provide actionable errors in the case
// it cannot be. Configuration variables can be read from `vars` using the `stringValue` function -
// for example `stringValue(vars, "accessKey")`.
func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) error {
return nil
}

func ref[T any](b T) *T {
return &b
func stripTfFromDocs() tfbridge.DocsEdit {
// Lots of docs have a "The Linode Guide, [Deploy a ... Using Terraform](...)" line. We
// don't want to include those blocks in our documentation, since they link to a TF guide
// which won't help our users.
linodeGuide := regexp.MustCompile("The Linode Guide[^\n]*[tT]erraform[^\n]*\n\n?")

// There are also a bunch of phrases that appear in the downstream docs that we
// know how to replace.
state := regexp.MustCompile("in [tT]erraform state")
thisProvider := regexp.MustCompile("this Terraform Provider")
provisioners := regexp.MustCompile("Linode Instances can also use provisioners.\n\n?")
suchAs := regexp.MustCompile(", such as [tT]erraform,")
inTf := regexp.MustCompile("in Terraform.")
itself := regexp.MustCompile("for Terraform itself")
return tfbridge.DocsEdit{
Path: "*",
Edit: func(_ string, b []byte) ([]byte, error) {
b = linodeGuide.ReplaceAllLiteral(b, nil)
b = provisioners.ReplaceAllLiteral(b, nil)
b = thisProvider.ReplaceAllLiteral(b, []byte("this provider"))
b = state.ReplaceAllLiteral(b, []byte("in Pulumi state"))
b = suchAs.ReplaceAllLiteral(b, []byte(", such as Pulumi,"))
b = inTf.ReplaceAllLiteral(b, []byte("in the provider"))
b = itself.ReplaceAllLiteral(b, []byte("for the provider itself"))
return b, nil
},
}
}

// Provider returns additional overlaid schema and metadata associated with the provider..
Expand All @@ -100,6 +117,11 @@ func Provider() tfbridge.ProviderInfo {
GitHubOrg: "linode",
UpstreamRepoPath: "./upstream",
Version: version.Version,
DocRules: &tfbridge.DocRuleInfo{
EditRules: func(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit {
return append(defaults, stripTfFromDocs())
},
},

Config: map[string]*tfbridge.SchemaInfo{
"url": {
Expand All @@ -118,45 +140,17 @@ func Provider() tfbridge.ProviderInfo {
},
},
},
PreConfigureCallback: preConfigureCallback,
IgnoreMappings: []string{
"linode_instance_config", // Mapping causes a panic due to duplicate types
},
Resources: map[string]*tfbridge.ResourceInfo{
// Map each resource in the Terraform provider to a Pulumi type. An example
// is below.
"linode_image": {
Tok: makeResource(mainMod, "Image"),
},
"linode_instance": {
Tok: makeResource(mainMod, "Instance"),
Fields: map[string]*tfbridge.SchemaInfo{
"specs": {
MaxItemsOne: ref(true),
},
"backups": {
MaxItemsOne: ref(true),
Elem: &tfbridge.SchemaInfo{
Fields: map[string]*tfbridge.SchemaInfo{
"schedule": {
MaxItemsOne: ref(true),
},
},
},
},
},
},
"linode_domain": {
Tok: makeResource(mainMod, "Domain"),
Fields: map[string]*tfbridge.SchemaInfo{
"domain": {
CSharpName: "DomainName",
},
},
},
"linode_domain_record": {
Tok: makeResource(mainMod, "DomainRecord"),
},
"linode_nodebalancer": {
Tok: makeResource(mainMod, "NodeBalancer"),
},
Expand All @@ -167,119 +161,32 @@ func Provider() tfbridge.ProviderInfo {
Tok: makeResource(mainMod, "NodeBalancerNode"),
},
"linode_rdns": {
Tok: makeResource(mainMod, "Rdns"),
Fields: map[string]*tfbridge.SchemaInfo{
"rdns": {
CSharpName: "RdnsName",
},
"rdns": {CSharpName: "RdnsName"},
},
},
"linode_sshkey": {
Tok: makeResource(mainMod, "SshKey"),
Fields: map[string]*tfbridge.SchemaInfo{
"ssh_key": {
CSharpName: "SshKeyName",
},
"ssh_key": {CSharpName: "SshKeyName"},
},
},
"linode_stackscript": {
Tok: makeResource(mainMod, "StackScript"),
},
"linode_volume": {
Tok: makeResource(mainMod, "Volume"),
},
"linode_object_storage_bucket": {
Tok: makeResource(mainMod, "ObjectStorageBucket"),
},
"linode_object_storage_key": {
Tok: makeResource(mainMod, "ObjectStorageKey"),
},
"linode_lke_cluster": {Tok: makeResource(mainMod, "LkeCluster")},
"linode_firewall": {Tok: makeResource(mainMod, "Firewall")},
"linode_object_storage_object": {Tok: makeResource(mainMod, "ObjectStorageObject")},
"linode_instance_ip": {Tok: makeResource(mainMod, "InstanceIp")},
"linode_user": {Tok: makeResource(mainMod, "User")},
"linode_firewall_device": {Tok: makeResource(mainMod, "FirewallDevice")},
"linode_ipv6_range": {Tok: makeResource(mainMod, "Ipv6Range")},
"linode_database_mysql": {Tok: makeResource(mainMod, "DatabaseMysql")},
"linode_database_postgresql": {Tok: makeResource(mainMod, "DatabasePostgresql")},
"linode_database_access_controls": {Tok: makeResource(mainMod, "DatabaseAccessControls")},
"linode_instance_shared_ips": {Tok: makeResource(mainMod, "InstanceSharedIps")},
"linode_instance_disk": {Tok: makeResource(mainMod, "InstanceDisk")},
"linode_token": {
Tok: makeResource(mainMod, "Token"),
Fields: map[string]*tfbridge.SchemaInfo{
"token": {CSharpName: "ApiToken"},
},
},
},
DataSources: map[string]*tfbridge.DataSourceInfo{
"linode_vlans": {Tok: makeDataSource(mainMod, "getVlans")},
"linode_account": {Tok: makeDataSource(mainMod, "getAccount")},
"linode_domain": {Tok: makeDataSource(mainMod, "getDomain")},
"linode_image": {Tok: makeDataSource(mainMod, "getImage")},
"linode_instance_type": {
Tok: makeDataSource(mainMod, "getInstanceType"),
Fields: map[string]*tfbridge.SchemaInfo{
"price": {
MaxItemsOne: ref(true),
},
"addons": {
MaxItemsOne: ref(true),
Elem: &tfbridge.SchemaInfo{
Fields: map[string]*tfbridge.SchemaInfo{
"backups": {
MaxItemsOne: ref(true),
Elem: &tfbridge.SchemaInfo{
Fields: map[string]*tfbridge.SchemaInfo{
"price": {
MaxItemsOne: ref(true),
},
},
},
},
},
},
},
},
},
"linode_networking_ip": {Tok: makeDataSource(mainMod, "getNetworkingIp")},
"linode_profile": {
Tok: makeDataSource(mainMod, "getProfile"),
Fields: map[string]*tfbridge.SchemaInfo{
"referrals": {
MaxItemsOne: ref(true),
},
},
},
"linode_region": {Tok: makeDataSource(mainMod, "getRegion")},
"linode_sshkey": {Tok: makeDataSource(mainMod, "getSshKey")},
"linode_user": {Tok: makeDataSource(mainMod, "getUser")},
"linode_object_storage_cluster": {
Tok: makeDataSource(mainMod, "getObjectStorageCluster"),
},
"linode_stackscript": {Tok: makeDataSource(mainMod, "getStackScript")},
"linode_domain_record": {Tok: makeDataSource(mainMod, "getDomainRecord")},
"linode_volume": {Tok: makeDataSource(mainMod, "getVolume")},
"linode_lke_cluster": {Tok: makeDataSource(mainMod, "getLkeCluster")},
"linode_firewall": {Tok: makeDataSource(mainMod, "getFirewall")},
"linode_images": {Tok: makeDataSource(mainMod, "getImages")},
"linode_instance_backups": {Tok: makeDataSource(mainMod, "getInstanceBackups")},
"linode_instances": {Tok: makeDataSource(mainMod, "getInstances")},
"linode_kernel": {Tok: makeDataSource(mainMod, "getKernel")},
"linode_nodebalancer": {Tok: makeDataSource(mainMod, "getNodeBalancer")},
"linode_nodebalancer_config": {Tok: makeDataSource(mainMod, "getNodeBalancerConfig")},
"linode_nodebalancer_node": {Tok: makeDataSource(mainMod, "getNodeBalancerNode")},
"linode_instance_types": {Tok: makeDataSource(mainMod, "getInstanceTypes")},
"linode_stackscripts": {Tok: makeDataSource(mainMod, "getStackScripts")},
"linode_database_engines": {Tok: makeDataSource(mainMod, "getDatabaseEngines")},
"linode_database_mysql_backups": {Tok: makeDataSource(mainMod, "getDatabaseMysqlBackups")},
"linode_databases": {Tok: makeDataSource(mainMod, "getDatabases")},
"linode_database_backups": {Tok: makeDataSource(mainMod, "getDatabaseBackups")},
"linode_database_mysql": {Tok: makeDataSource(mainMod, "getDatabaseMysql")},
"linode_database_postgresql": {Tok: makeDataSource(mainMod, "getDatabasePostgresql")},
"linode_ipv6_range": {Tok: makeDataSource(mainMod, "getIpv6Range")},
"linode_domain_zonefile": {Tok: makeDataSource(mainMod, "getDomainZonefile")},
"linode_sshkey": {Tok: makeDataSource(mainMod, "getSshKey")},
"linode_stackscript": {Tok: makeDataSource(mainMod, "getStackScript")},
"linode_nodebalancer": {Tok: makeDataSource(mainMod, "getNodeBalancer")},
"linode_nodebalancer_config": {Tok: makeDataSource(mainMod, "getNodeBalancerConfig")},
"linode_nodebalancer_node": {Tok: makeDataSource(mainMod, "getNodeBalancerNode")},
"linode_stackscripts": {Tok: makeDataSource(mainMod, "getStackScripts")},
"linode_object_storage_bucket": {
Tok: makeDataSource(mainMod, "getLinodeObjectStorageBucket"),
Docs: &tfbridge.DocInfo{Markdown: []byte{' '}},
Expand Down
2 changes: 0 additions & 2 deletions sdk/dotnet/Domain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ namespace Pulumi.Linode
/// ```sh
/// $ pulumi import linode:index/domain:Domain foobar 1234567
/// ```
///
/// The Linode Guide, [Import Existing Infrastructure to Terraform](https://www.linode.com/docs/applications/configuration-management/import-existing-infrastructure-to-terraform/), offers resource importing examples for Domains and other Linode resource types.
/// </summary>
[LinodeResourceType("linode:index/domain:Domain")]
public partial class Domain : global::Pulumi.CustomResource
Expand Down
2 changes: 0 additions & 2 deletions sdk/dotnet/DomainRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ namespace Pulumi.Linode
/// ```sh
/// $ pulumi import linode:index/domainRecord:DomainRecord www-foobar 1234567,7654321
/// ```
///
/// The Linode Guide, [Import Existing Infrastructure to Terraform](https://www.linode.com/docs/applications/configuration-management/import-existing-infrastructure-to-terraform/), offers resource importing examples for Domain Records and other Linode resource types.
/// </summary>
[LinodeResourceType("linode:index/domainRecord:DomainRecord")]
public partial class DomainRecord : global::Pulumi.CustomResource
Expand Down
2 changes: 1 addition & 1 deletion sdk/dotnet/Inputs/InstanceDiskArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public InputList<string> AuthorizedUsers
private Input<string>? _rootPass;

/// <summary>
/// The initial password for the `root` user account. *This value can not be imported.* *Changing `root_pass` forces the creation of a new Linode Instance.* *If omitted, a random password will be generated but will not be stored in state.*
/// The initial password for the `root` user account. *This value can not be imported.* *Changing `root_pass` forces the creation of a new Linode Instance.* *If omitted, a random password will be generated but will not be stored in Pulumi state.*
/// </summary>
public Input<string>? RootPass
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/dotnet/Inputs/InstanceDiskGetArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public InputList<string> AuthorizedUsers
private Input<string>? _rootPass;

/// <summary>
/// The initial password for the `root` user account. *This value can not be imported.* *Changing `root_pass` forces the creation of a new Linode Instance.* *If omitted, a random password will be generated but will not be stored in state.*
/// The initial password for the `root` user account. *This value can not be imported.* *Changing `root_pass` forces the creation of a new Linode Instance.* *If omitted, a random password will be generated but will not be stored in Pulumi state.*
/// </summary>
public Input<string>? RootPass
{
Expand Down
Loading

0 comments on commit 0d21714

Please sign in to comment.