-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #7438 from mbarrien/eks-cluster-auth
Add EKS cluster auth token data resource continued
- Loading branch information
Showing
191 changed files
with
51,676 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/kubernetes-sigs/aws-iam-authenticator/pkg/token" | ||
) | ||
|
||
func dataSourceAwsEksClusterAuth() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsEksClusterAuthRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.NoZeroValues, | ||
}, | ||
|
||
"token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsEksClusterAuthRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).stsconn | ||
name := d.Get("name").(string) | ||
generator, err := token.NewGenerator(false) | ||
if err != nil { | ||
return fmt.Errorf("error getting token generator: %v", err) | ||
} | ||
token, err := generator.GetWithSTS(name, conn) | ||
if err != nil { | ||
return fmt.Errorf("error getting token: %v", err) | ||
} | ||
|
||
d.SetId(time.Now().UTC().String()) | ||
d.Set("token", token.Token) | ||
|
||
return nil | ||
} |
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,61 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
"github.com/kubernetes-sigs/aws-iam-authenticator/pkg/token" | ||
) | ||
|
||
func TestAccAWSEksClusterAuthDataSource_basic(t *testing.T) { | ||
dataSourceResourceName := "data.aws_eks_cluster_auth.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAwsEksClusterAuthConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceResourceName, "name", "foobar"), | ||
resource.TestCheckResourceAttrSet(dataSourceResourceName, "token"), | ||
testAccCheckAwsEksClusterAuthToken(dataSourceResourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsEksClusterAuthToken(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No resource ID is set") | ||
} | ||
|
||
name := rs.Primary.Attributes["name"] | ||
tok := rs.Primary.Attributes["token"] | ||
verifier := token.NewVerifier(name) | ||
identity, err := verifier.Verify(tok) | ||
if err != nil { | ||
return fmt.Errorf("Error verifying token for cluster %q: %v", name, err) | ||
} | ||
if identity.ARN == "" { | ||
return fmt.Errorf("Unexpected blank ARN for token identity") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccCheckAwsEksClusterAuthConfig_basic = ` | ||
data "aws_eks_cluster_auth" "test" { | ||
name = "foobar" | ||
} | ||
` |
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
35 changes: 0 additions & 35 deletions
35
vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
vendor/github.com/aws/aws-sdk-go/service/codecommit/api.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
vendor/github.com/aws/aws-sdk-go/service/codecommit/errors.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.