本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.Provider.Meta方法的典型用法代碼示例。如果您正苦於以下問題:Golang Provider.Meta方法的具體用法?Golang Provider.Meta怎麽用?Golang Provider.Meta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.Provider
的用法示例。
在下文中一共展示了Provider.Meta方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testAccCheckInstanceDestroyWithProvider
func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).ec2conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_instance" {
continue
}
// Try to find the resource
var err error
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{aws.String(rs.Primary.ID)},
})
if err == nil {
if len(resp.Reservations) > 0 {
return fmt.Errorf("still exist.")
}
return nil
}
// Verify the error is what we want
ec2err, ok := err.(awserr.Error)
if !ok {
return err
}
if ec2err.Code() != "InvalidInstanceID.NotFound" {
return err
}
}
return nil
}
示例2: testAccCheckInstanceDestroyWithProvider
func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).ec2conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_instance" {
continue
}
// Try to find the resource
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{aws.String(rs.Primary.ID)},
})
if err == nil {
for _, r := range resp.Reservations {
for _, i := range r.Instances {
if i.State != nil && *i.State.Name != "terminated" {
return fmt.Errorf("Found unterminated instance: %s", i)
}
}
}
}
// Verify the error is what we want
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidInstanceID.NotFound" {
continue
}
return err
}
return nil
}
示例3: testAccCheckRoute53ZoneAssociationExistsWithProvider
func testAccCheckRoute53ZoneAssociationExistsWithProvider(s *terraform.State, n string, zone *route53.HostedZone, provider *schema.Provider) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No zone association ID is set")
}
zone_id, vpc_id := resourceAwsRoute53ZoneAssociationParseId(rs.Primary.ID)
conn := provider.Meta().(*AWSClient).r53conn
resp, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone_id)})
if err != nil {
return fmt.Errorf("Hosted zone err: %v", err)
}
exists := false
for _, vpc := range resp.VPCs {
if vpc_id == *vpc.VPCId {
exists = true
}
}
if !exists {
return fmt.Errorf("Hosted zone association not found")
}
*zone = *resp.HostedZone
return nil
}
示例4: testAccCheckRoute53ZoneDestroyWithProvider
func testAccCheckRoute53ZoneDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_zone" {
continue
}
_, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(rs.Primary.ID)})
if err == nil {
return fmt.Errorf("Hosted zone still exists")
}
}
return nil
}
示例5: testAccCheckRoute53DelegationSetDestroy
func testAccCheckRoute53DelegationSetDestroy(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_delegation_set" {
continue
}
_, err := conn.GetReusableDelegationSet(&route53.GetReusableDelegationSetInput{Id: aws.String(rs.Primary.ID)})
if err == nil {
return fmt.Errorf("Delegation set still exists")
}
}
return nil
}
示例6: testAccCheckAWSS3BucketDestroyWithProvider
func testAccCheckAWSS3BucketDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).s3conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_s3_bucket" {
continue
}
_, err := conn.DeleteBucket(&s3.DeleteBucketInput{
Bucket: aws.String(rs.Primary.ID),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoSuchBucket" {
return nil
}
return err
}
}
return nil
}
示例7: testAccCheckRoute53ZoneExistsWithProvider
func testAccCheckRoute53ZoneExistsWithProvider(s *terraform.State, n string, zone *route53.GetHostedZoneOutput, provider *schema.Provider) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No hosted zone ID is set")
}
conn := provider.Meta().(*AWSClient).r53conn
resp, err := conn.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(rs.Primary.ID)})
if err != nil {
return fmt.Errorf("Hosted zone err: %v", err)
}
aws_comment := *resp.HostedZone.Config.Comment
rs_comment := rs.Primary.Attributes["comment"]
if rs_comment != "" && rs_comment != aws_comment {
return fmt.Errorf("Hosted zone with comment '%s' found but does not match '%s'", aws_comment, rs_comment)
}
if !*resp.HostedZone.Config.PrivateZone {
sorted_ns := make([]string, len(resp.DelegationSet.NameServers))
for i, ns := range resp.DelegationSet.NameServers {
sorted_ns[i] = *ns
}
sort.Strings(sorted_ns)
for idx, ns := range sorted_ns {
attribute := fmt.Sprintf("name_servers.%d", idx)
dsns := rs.Primary.Attributes[attribute]
if dsns != ns {
return fmt.Errorf("Got: %v for %v, Expected: %v", dsns, attribute, ns)
}
}
}
*zone = *resp
return nil
}
示例8: testAccCreateRandomRoute53RecordsInZoneId
func testAccCreateRandomRoute53RecordsInZoneId(provider *schema.Provider, zone *route53.GetHostedZoneOutput, recordsCount int) error {
conn := provider.Meta().(*AWSClient).r53conn
var changes []*route53.Change
if recordsCount > 100 {
return fmt.Errorf("Route53 API only allows 100 record sets in a single batch")
}
for i := 0; i < recordsCount; i++ {
changes = append(changes, &route53.Change{
Action: aws.String("UPSERT"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(fmt.Sprintf("%d-tf-acc-random.%s", acctest.RandInt(), *zone.HostedZone.Name)),
Type: aws.String("CNAME"),
ResourceRecords: []*route53.ResourceRecord{
&route53.ResourceRecord{Value: aws.String(fmt.Sprintf("random.%s", *zone.HostedZone.Name))},
},
TTL: aws.Int64(int64(30)),
},
})
}
req := &route53.ChangeResourceRecordSetsInput{
HostedZoneId: zone.HostedZone.Id,
ChangeBatch: &route53.ChangeBatch{
Comment: aws.String("Generated by Terraform"),
Changes: changes,
},
}
log.Printf("[DEBUG] Change set: %s\n", *req)
resp, err := changeRoute53RecordSet(conn, req)
if err != nil {
return err
}
changeInfo := resp.(*route53.ChangeResourceRecordSetsOutput).ChangeInfo
err = waitForRoute53RecordSetToSync(conn, cleanChangeID(*changeInfo.Id))
return err
}
示例9: testAccCheckRoute53ZoneAssociationDestroyWithProvider
func testAccCheckRoute53ZoneAssociationDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
conn := provider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_zone_association" {
continue
}
zone_id, vpc_id := resourceAwsRoute53ZoneAssociationParseId(rs.Primary.ID)
resp, err := conn.GetHostedZone(&route53.GetHostedZoneInput{Id: aws.String(zone_id)})
if err != nil {
exists := false
for _, vpc := range resp.VPCs {
if vpc_id == *vpc.VPCId {
exists = true
}
}
if exists {
return fmt.Errorf("VPC: %v is still associated to HostedZone: %v", vpc_id, zone_id)
}
}
}
return nil
}