-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add provider config generation (#20)
* feat: add provider config generation * feat: add gpg figning to goreleaser
- Loading branch information
1 parent
7034eff
commit 70ab6ce
Showing
15 changed files
with
179 additions
and
54 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 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,5 @@ | ||
# kops_aws_config | ||
|
||
| attribute | type | optional | required | computed | | ||
| --- | --- | --- | --- | --- | | ||
| `profile` | String | | :white_check_mark: | | |
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,6 @@ | ||
# kops_provider_config | ||
|
||
| attribute | type | optional | required | computed | | ||
| --- | --- | --- | --- | --- | | ||
| `state_store` | String | :white_check_mark: | | | | ||
| `aws` | [AwsConfig](./AwsConfig.generated.md) | | :white_check_mark: | | |
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 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,5 @@ | ||
package api | ||
|
||
type AwsConfig struct { | ||
Profile string | ||
} |
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,6 @@ | ||
package api | ||
|
||
type ProviderConfig struct { | ||
StateStore string | ||
Aws *AwsConfig | ||
} |
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 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,13 @@ | ||
package schemas | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func AwsConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"profile": OptionalString(), | ||
}, | ||
} | ||
} |
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,14 @@ | ||
package schemas | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func ProviderConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"state_store": RequiredString(), | ||
"aws": OptionalStruct(AwsConfig()), | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package structures | ||
|
||
import ( | ||
"github.com/eddycharly/terraform-provider-kops/pkg/api" | ||
) | ||
|
||
func ExpandAwsConfig(in map[string]interface{}) api.AwsConfig { | ||
if in == nil { | ||
panic("expand AwsConfig failure, in is nil") | ||
} | ||
return api.AwsConfig{ | ||
Profile: func(in interface{}) string { | ||
return string(ExpandString(in)) | ||
}(in["profile"]), | ||
} | ||
} | ||
|
||
func FlattenAwsConfig(in api.AwsConfig) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"profile": func(in string) interface{} { | ||
return FlattenString(string(in)) | ||
}(in.Profile), | ||
} | ||
} |
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,54 @@ | ||
package structures | ||
|
||
import ( | ||
"github.com/eddycharly/terraform-provider-kops/pkg/api" | ||
) | ||
|
||
func ExpandProviderConfig(in map[string]interface{}) api.ProviderConfig { | ||
if in == nil { | ||
panic("expand ProviderConfig failure, in is nil") | ||
} | ||
return api.ProviderConfig{ | ||
StateStore: func(in interface{}) string { | ||
return string(ExpandString(in)) | ||
}(in["state_store"]), | ||
Aws: func(in interface{}) *api.AwsConfig { | ||
return func(in interface{}) *api.AwsConfig { | ||
if in == nil { | ||
return nil | ||
} | ||
if _, ok := in.([]interface{}); ok && len(in.([]interface{})) == 0 { | ||
return nil | ||
} | ||
return func(in api.AwsConfig) *api.AwsConfig { | ||
return &in | ||
}(func(in interface{}) api.AwsConfig { | ||
if len(in.([]interface{})) == 0 || in.([]interface{})[0] == nil { | ||
return api.AwsConfig{} | ||
} | ||
return (ExpandAwsConfig(in.([]interface{})[0].(map[string]interface{}))) | ||
}(in)) | ||
}(in) | ||
}(in["aws"]), | ||
} | ||
} | ||
|
||
func FlattenProviderConfig(in api.ProviderConfig) map[string]interface{} { | ||
return map[string]interface{}{ | ||
"state_store": func(in string) interface{} { | ||
return FlattenString(string(in)) | ||
}(in.StateStore), | ||
"aws": func(in *api.AwsConfig) interface{} { | ||
return func(in *api.AwsConfig) interface{} { | ||
if in == nil { | ||
return nil | ||
} | ||
return func(in api.AwsConfig) interface{} { | ||
return func(in api.AwsConfig) []map[string]interface{} { | ||
return []map[string]interface{}{FlattenAwsConfig(in)} | ||
}(in) | ||
}(*in) | ||
}(in) | ||
}(in.Aws), | ||
} | ||
} |