-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk: Rename aws session related functions for clarity
- Loading branch information
Showing
12 changed files
with
124 additions
and
20 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
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,8 @@ | ||
package sdk | ||
|
||
type Config struct { | ||
Region string | ||
Profile string | ||
AssumeRole *AssumeRoleConfig | ||
} | ||
|
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,18 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"github.com/mumoshu/terraform-provider-eksctl/pkg/sdk" | ||
"github.com/mumoshu/terraform-provider-eksctl/pkg/sdk/api" | ||
) | ||
|
||
func ConfigFromResourceData(d api.Getter, opts ...SchemaOption) *sdk.Config { | ||
region, profile := GetAWSRegionAndProfile(d, opts...) | ||
|
||
assumeRoleConfig := GetAssumeRoleConfig(d, opts...) | ||
|
||
return &sdk.Config{ | ||
Region: region, | ||
Profile: profile, | ||
AssumeRole: assumeRoleConfig, | ||
} | ||
} |
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,65 @@ | ||
package tfsdk | ||
|
||
type Schema struct { | ||
KeyAWSRegion string | ||
KeyAWSProfile string | ||
KeyAWSAssumeRole string | ||
} | ||
|
||
func defaultSchema() *Schema { | ||
return &Schema{ | ||
KeyAWSRegion: KeyRegion, | ||
KeyAWSProfile: KeyProfile, | ||
KeyAWSAssumeRole: KeyAssumeRole, | ||
} | ||
} | ||
|
||
type SchemaOption interface { | ||
Apply(*Schema) | ||
} | ||
|
||
func (s *Schema) Apply(other *Schema) { | ||
*other = *s | ||
} | ||
|
||
type schemaOptionFunc struct { | ||
f func(*Schema) | ||
} | ||
|
||
func (f *schemaOptionFunc) Apply(schema *Schema) { | ||
f.f(schema) | ||
} | ||
|
||
func SchemaOptionFunc(f func(*Schema)) SchemaOption { | ||
return &schemaOptionFunc{ | ||
f: f, | ||
} | ||
} | ||
|
||
func SchemaOptionAWSRegionKey(k string) SchemaOption { | ||
return SchemaOptionFunc(func(schema *Schema) { | ||
schema.KeyAWSRegion = k | ||
}) | ||
} | ||
|
||
func SchemaOptionAWSProfileKey(k string) SchemaOption { | ||
return SchemaOptionFunc(func(schema *Schema) { | ||
schema.KeyAWSProfile = k | ||
}) | ||
} | ||
|
||
func SchemaOptionAWSAssumeRole(k string) SchemaOption { | ||
return SchemaOptionFunc(func(schema *Schema) { | ||
schema.KeyAWSAssumeRole = k | ||
}) | ||
} | ||
|
||
func CreateSchema(opts ...SchemaOption) *Schema { | ||
schema := defaultSchema() | ||
|
||
for _, o := range opts { | ||
o.Apply(schema) | ||
} | ||
|
||
return schema | ||
} |