Skip to content

Commit

Permalink
chore: v6_provider setup with resource_ip and datasource_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
ikadix committed Nov 8, 2023
1 parent 38a6fee commit 6c09346
Show file tree
Hide file tree
Showing 26 changed files with 6,290 additions and 26 deletions.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.19.0
github.com/hashicorp/terraform-plugin-mux v0.12.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/jimeh/rands v0.3.0
github.com/jimeh/undent v1.1.1
github.com/krystal/go-katapult v0.2.1
Expand Down Expand Up @@ -43,6 +46,8 @@ require (
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -58,6 +63,7 @@ require (
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
Expand All @@ -66,6 +72,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 15 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.6 h1:/xbKIqSHbZXHwkhbrhrt2YOHIwYJlXH94E3tI/gDlUg=
github.com/cloudflare/circl v1.3.6/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -77,6 +78,10 @@ github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81Sp
github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg=
github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA=
github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o=
github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5OckzhoiO3ig6SGxwelD2sI=
github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
github.com/hashicorp/terraform-plugin-go v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU=
github.com/hashicorp/terraform-plugin-go v0.19.0/go.mod h1:EhRSkEPNoylLQntYsk5KrDHTZJh9HQoumZXbOGOXmec=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand All @@ -85,6 +90,8 @@ github.com/hashicorp/terraform-plugin-mux v0.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gS
github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 h1:wcOKYwPI9IorAJEBLzgclh3xVolO7ZorYd6U1vnok14=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0/go.mod h1:qH/34G25Ugdj5FcM95cSoXzUgIbgfhVLXCcEcYaMwq8=
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
github.com/hashicorp/terraform-registry-address v0.2.2 h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno=
github.com/hashicorp/terraform-registry-address v0.2.2/go.mod h1:LtwNbCihUoUZ3RYriyS2wF/lGPB6gF9ICLRtuDk7hSo=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand All @@ -100,11 +107,13 @@ github.com/jimeh/undent v1.1.1 h1:ZAzvd2DDx7gxQvOMGkQjfeRx9gRPIXe2cq+8ZNiGKaM=
github.com/jimeh/undent v1.1.1/go.mod h1:oxYCIzdbyQNy8GXnCnjRJ2NS6Uq4p4yWoeawiGFqoHI=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/krystal/go-katapult v0.2.1 h1:UltHtVShIrqX/6jx7PHLKEJBH7KAsme2veHku7O5TBg=
github.com/krystal/go-katapult v0.2.1/go.mod h1:yTy0Lx0qpwK8RwhOHqmsGJhMcDlcg00AswfJWh1yw3w=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down Expand Up @@ -173,6 +182,8 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U=
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
Expand Down Expand Up @@ -245,8 +256,9 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/data_source_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/krystal/go-katapult/core"
)

//nolint:unused // being migrated to v6provider
func dataSourceIP() *schema.Resource {
ds := dataSourceSchemaFromResourceSchema(resourceIP().Schema)

Expand All @@ -27,6 +28,7 @@ func dataSourceIP() *schema.Resource {
}
}

//nolint:unused // being migrated to v6provider
func dataSourceIPRead(
ctx context.Context,
d *schema.ResourceData,
Expand Down
67 changes: 45 additions & 22 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,32 @@ func New(c *Config) func() *schema.Provider { //nolint:funlen
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"api_key": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("KATAPULT_API_KEY", nil),
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "API Key for Katapult Core API. Can be " +
"specified with the `KATAPULT_API_KEY` environment " +
"variable.",
},
"organization": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc(
"KATAPULT_ORGANIZATION", nil,
),
Optional: true,

Description: "Organization sub-domain. Can be " +
"specified with the `KATAPULT_ORGANIZATION` " +
"environment variable.",
},
"data_center": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc(
"KATAPULT_DATA_CENTER", nil,
),
Optional: true,

Description: "Data center permalink. Can be " +
"specified with the `KATAPULT_DATA_CENTER` " +
"environment variable.",
},
"skip_trash_object_purge": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc(
"KATAPULT_SKIP_TRASH_OBJECT_PURGE", false,
),
//nolint:lll
Description: strings.TrimSpace(`
Expand Down Expand Up @@ -122,7 +114,6 @@ Skip purging deleted resources from Katapult's trash when they are destroyed by
},
},
ResourcesMap: map[string]*schema.Resource{
"katapult_ip": resourceIP(),
"katapult_file_storage_volume": resourceFileStorageVolume(),
"katapult_security_group": resourceSecurityGroup(),
"katapult_security_group_rule": resourceSecurityGroupRule(),
Expand All @@ -136,7 +127,6 @@ Skip purging deleted resources from Katapult's trash when they are destroyed by
"katapult_disk_templates": dataSourceDiskTemplates(),
"katapult_file_storage_volume": dataSourceFileStorageVolume(),
"katapult_file_storage_volumes": dataSourceFileStorageVolumes(),
"katapult_ip": dataSourceIP(),
"katapult_network_speed_profile": dataSourceNetworkSpeedProfile(),
"katapult_network_speed_profiles": dataSourceNetworkSpeedProfiles(),
"katapult_security_group": dataSourceSecurityGroup(),
Expand All @@ -157,6 +147,27 @@ Skip purging deleted resources from Katapult's trash when they are destroyed by
}
}

func stringOrEnv(in string, env string) string {
if in != "" {
return in
}

return os.Getenv(env)
}

func boolOrEnv(in bool, env string) bool {
if in {
return true
}

switch strings.ToLower(os.Getenv(env)) {
case "true", "1":
return true
}

return false
}

func configure(
conf *Config,
p *schema.Provider,
Expand All @@ -171,11 +182,23 @@ func configure(
Level: hclog.LevelFromString(d.Get("log_level").(string)),
TimeFormat: "2006/01/02 15:04:05",
}),
confAPIKey: d.Get("api_key").(string),
confDataCenter: d.Get("data_center").(string),
confOrganization: d.Get("organization").(string),
SkipTrashObjectPurge: d.Get("skip_trash_object_purge").(bool),
GeneratedNamePrefix: conf.GeneratedNamePrefix,
confAPIKey: stringOrEnv(
d.Get("api_key").(string),
"KATAPULT_API_KEY",
),
confDataCenter: stringOrEnv(
d.Get("data_center").(string),
"KATAPULT_DATA_CENTER",
),
confOrganization: stringOrEnv(
d.Get("organization").(string),
"KATAPULT_ORGANIZATION",
),
SkipTrashObjectPurge: boolOrEnv(
d.Get("skip_trash_object_purge").(bool),
"KATAPULT_SKIP_TRASH_OBJECT_PURGE",
),
GeneratedNamePrefix: conf.GeneratedNamePrefix,
}

if m.GeneratedNamePrefix == "" {
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resource_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/krystal/go-katapult/core"
)

//nolint:unused // being migrated to v6provider
func resourceIP() *schema.Resource {
return &schema.Resource{
CreateContext: resourceIPCreate,
Expand Down Expand Up @@ -76,6 +77,7 @@ func resourceIP() *schema.Resource {
}
}

//nolint:unused // being migrated to v6provider
func resourceIPCreate(
ctx context.Context,
d *schema.ResourceData,
Expand Down Expand Up @@ -119,6 +121,7 @@ func resourceIPCreate(
return resourceIPRead(ctx, d, meta)
}

//nolint:unused // being migrated to v6provider
func resourceIPRead(
ctx context.Context,
d *schema.ResourceData,
Expand Down Expand Up @@ -153,6 +156,7 @@ func resourceIPRead(
return diags
}

//nolint:unused // being migrated to v6provider
func resourceIPUpdate(
ctx context.Context,
d *schema.ResourceData,
Expand Down Expand Up @@ -180,6 +184,7 @@ func resourceIPUpdate(
return resourceIPRead(ctx, d, meta)
}

//nolint:unused // being migrated to v6provider
func resourceIPDelete(
ctx context.Context,
d *schema.ResourceData,
Expand All @@ -196,6 +201,7 @@ func resourceIPDelete(
return diag.Diagnostics{}
}

//nolint:unused // being migrated to v6provider
func unflattenIPVersion(ver int) core.IPVersion {
switch ver {
case 6:
Expand All @@ -205,6 +211,7 @@ func unflattenIPVersion(ver int) core.IPVersion {
}
}

//nolint:unused // being migrated to v6provider

Check failure on line 214 in internal/provider/resource_ip.go

View workflow job for this annotation

GitHub Actions / Lint

directive `//nolint:unused // being migrated to v6provider` is unused for linter "unused" (nolintlint)
func flattenIPVersion(address string) int {
if strings.Count(address, ":") < 2 {
return 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ego102f3ucns
tnrqonoz38ec
Loading

0 comments on commit 6c09346

Please sign in to comment.