本文整理匯總了Golang中github.com/hashicorp/terraform/helper/schema.ResourceData.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceData.Id方法的具體用法?Golang ResourceData.Id怎麽用?Golang ResourceData.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.Id方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getVolumeAttachments
func getVolumeAttachments(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) error {
var attachments []volumeattach.VolumeAttachment
err := volumeattach.List(computeClient, d.Id()).EachPage(func(page pagination.Page) (bool, error) {
actual, err := volumeattach.ExtractVolumeAttachments(page)
if err != nil {
return false, err
}
attachments = actual
return true, nil
})
if err != nil {
return err
}
vols := make([]map[string]interface{}, len(attachments))
for i, attachment := range attachments {
vols[i] = make(map[string]interface{})
vols[i]["id"] = attachment.ID
vols[i]["volume_id"] = attachment.VolumeID
vols[i]["device"] = attachment.Device
}
log.Printf("[INFO] Volume attachments: %v", vols)
d.Set("volume", vols)
return nil
}
示例2: resourceComputeTargetPoolDelete
func resourceComputeTargetPoolDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region, err := getRegion(d, config)
if err != nil {
return err
}
project, err := getProject(d, config)
if err != nil {
return err
}
// Delete the TargetPool
op, err := config.clientCompute.TargetPools.Delete(
project, region, d.Id()).Do()
if err != nil {
return fmt.Errorf("Error deleting TargetPool: %s", err)
}
err = computeOperationWaitRegion(config, op, region, "Deleting Target Pool")
if err != nil {
return err
}
d.SetId("")
return nil
}
示例3: resourceAwsInternetGatewayRead
func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
igRaw, _, err := IGStateRefreshFunc(conn, d.Id())()
if err != nil {
return err
}
if igRaw == nil {
// Seems we have lost our internet gateway
d.SetId("")
return nil
}
ig := igRaw.(*ec2.InternetGateway)
if len(ig.Attachments) == 0 {
// Gateway exists but not attached to the VPC
d.Set("vpc_id", "")
} else {
d.Set("vpc_id", ig.Attachments[0].VpcId)
}
d.Set("tags", tagsToMap(ig.Tags))
return nil
}
示例4: resourceAwsLambdaEventSourceMappingUpdate
// resourceAwsLambdaEventSourceMappingUpdate maps to:
// UpdateEventSourceMapping in the API / SDK
func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lambdaconn
log.Printf("[DEBUG] Updating Lambda event source mapping: %s", d.Id())
params := &lambda.UpdateEventSourceMappingInput{
UUID: aws.String(d.Id()),
BatchSize: aws.Int64(int64(d.Get("batch_size").(int))),
FunctionName: aws.String(d.Get("function_name").(string)),
Enabled: aws.Bool(d.Get("enabled").(bool)),
}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateEventSourceMapping(params)
if err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "InvalidParameterValueException" {
return resource.RetryableError(awserr)
}
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error updating Lambda event source mapping: %s", err)
}
return resourceAwsLambdaEventSourceMappingRead(d, meta)
}
示例5: resourceAwsInternetGatewayDelete
func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
// Detach if it is attached
if err := resourceAwsInternetGatewayDetach(d, meta); err != nil {
return err
}
log.Printf("[INFO] Deleting Internet Gateway: %s", d.Id())
return resource.Retry(5*time.Minute, func() error {
_, err := conn.DeleteInternetGateway(&ec2.DeleteInternetGatewayInput{
InternetGatewayId: aws.String(d.Id()),
})
if err == nil {
return nil
}
ec2err, ok := err.(awserr.Error)
if !ok {
return err
}
switch ec2err.Code() {
case "InvalidInternetGatewayID.NotFound":
return nil
case "DependencyViolation":
return err // retry
}
return resource.RetryError{Err: err}
})
}
示例6: resourceAwsIamAccessKeyRead
func resourceAwsIamAccessKeyRead(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn
request := &iam.ListAccessKeysInput{
UserName: aws.String(d.Get("user").(string)),
}
getResp, err := iamconn.ListAccessKeys(request)
if err != nil {
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { // XXX TEST ME
// the user does not exist, so the key can't exist.
d.SetId("")
return nil
}
return fmt.Errorf("Error reading IAM acces key: %s", err)
}
for _, key := range getResp.AccessKeyMetadata {
if key.AccessKeyID != nil && *key.AccessKeyID == d.Id() {
return resourceAwsIamAccessKeyReadResult(d, key)
}
}
// Guess the key isn't around anymore.
d.SetId("")
return nil
}
示例7: resourceComputeDiskDelete
func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
// Delete the disk
op, err := config.clientCompute.Disks.Delete(
config.Project, d.Get("zone").(string), d.Id()).Do()
if err != nil {
return fmt.Errorf("Error deleting disk: %s", err)
}
// Wait for the operation to complete
w := &OperationWaiter{
Service: config.clientCompute,
Op: op,
Project: config.Project,
Zone: d.Get("zone").(string),
Type: OperationWaitZone,
}
state := w.Conf()
state.Timeout = 2 * time.Minute
state.MinTimeout = 1 * time.Second
opRaw, err := state.WaitForState()
if err != nil {
return fmt.Errorf("Error waiting for disk to delete: %s", err)
}
op = opRaw.(*compute.Operation)
if op.Error != nil {
// Return the error
return OperationError(*op.Error)
}
d.SetId("")
return nil
}
示例8: resourceAwsLambdaEventSourceMappingRead
// resourceAwsLambdaEventSourceMappingRead maps to:
// GetEventSourceMapping in the API / SDK
func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).lambdaconn
log.Printf("[DEBUG] Fetching Lambda event source mapping: %s", d.Id())
params := &lambda.GetEventSourceMappingInput{
UUID: aws.String(d.Id()),
}
eventSourceMappingConfiguration, err := conn.GetEventSourceMapping(params)
if err != nil {
return err
}
d.Set("batch_size", eventSourceMappingConfiguration.BatchSize)
d.Set("event_source_arn", eventSourceMappingConfiguration.EventSourceArn)
d.Set("function_arn", eventSourceMappingConfiguration.FunctionArn)
d.Set("last_modified", eventSourceMappingConfiguration.LastModified)
d.Set("last_processing_result", eventSourceMappingConfiguration.LastProcessingResult)
d.Set("state", eventSourceMappingConfiguration.State)
d.Set("state_transition_reason", eventSourceMappingConfiguration.StateTransitionReason)
d.Set("uuid", eventSourceMappingConfiguration.UUID)
return nil
}
示例9: resourceComputeFirewallUpdate
func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
d.Partial(true)
firewall, err := resourceFirewall(d, meta)
if err != nil {
return err
}
op, err := config.clientCompute.Firewalls.Update(
config.Project, d.Id(), firewall).Do()
if err != nil {
return fmt.Errorf("Error updating firewall: %s", err)
}
err = computeOperationWaitGlobal(config, op, "Updating Firewall")
if err != nil {
return err
}
d.Partial(false)
return resourceComputeFirewallRead(d, meta)
}
示例10: setTagsR53
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsR53(conn *route53.Route53, d *schema.ResourceData, resourceType string) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsR53(tagsFromMapR53(o), tagsFromMapR53(n))
// Set tags
r := make([]*string, len(remove))
for i, t := range remove {
r[i] = t.Key
}
log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:%#v", create, remove)
req := &route53.ChangeTagsForResourceInput{
ResourceID: aws.String(d.Id()),
ResourceType: aws.String(resourceType),
}
if len(create) > 0 {
req.AddTags = create
}
if len(r) > 0 {
req.RemoveTagKeys = r
}
_, err := conn.ChangeTagsForResource(req)
if err != nil {
return err
}
}
return nil
}
示例11: resourceArmNetworkSecurityGroupRead
func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
secGroupClient := meta.(*ArmClient).secGroupClient
id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resGroup := id.ResourceGroup
name := id.Path["networkSecurityGroups"]
resp, err := secGroupClient.Get(resGroup, name, "")
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
}
if resp.Properties.SecurityRules != nil {
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
}
flattenAndSetTags(d, resp.Tags)
return nil
}
示例12: resourceLBMemberV1Delete
func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
err = members.Delete(networkingClient, d.Id()).ExtractErr()
if err != nil {
CheckDeleted(d, err, "LB member")
}
stateConf := &resource.StateChangeConf{
Pending: []string{"ACTIVE", "PENDING_DELETE"},
Target: []string{"DELETED"},
Refresh: waitForLBMemberDelete(networkingClient, d.Id()),
Timeout: 2 * time.Minute,
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForState()
if err != nil {
return fmt.Errorf("Error deleting OpenStack LB member: %s", err)
}
d.SetId("")
return nil
}
示例13: resourceAwsAutoscalingGroupDrain
func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn
// First, set the capacity to zero so the group will drain
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
opts := autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: aws.String(d.Id()),
DesiredCapacity: aws.Long(0),
MinSize: aws.Long(0),
MaxSize: aws.Long(0),
}
if _, err := conn.UpdateAutoScalingGroup(&opts); err != nil {
return fmt.Errorf("Error setting capacity to zero to drain: %s", err)
}
// Next, wait for the autoscale group to drain
log.Printf("[DEBUG] Waiting for group to have zero instances")
return resource.Retry(10*time.Minute, func() error {
g, err := getAwsAutoscalingGroup(d, meta)
if err != nil {
return resource.RetryError{Err: err}
}
if g == nil {
return nil
}
if len(g.Instances) == 0 {
return nil
}
return fmt.Errorf("group still has %d instances", len(g.Instances))
})
}
示例14: getAwsAutoscalingGroup
func getAwsAutoscalingGroup(
d *schema.ResourceData,
meta interface{}) (*autoscaling.Group, error) {
conn := meta.(*AWSClient).autoscalingconn
describeOpts := autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: []*string{aws.String(d.Id())},
}
log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
if err != nil {
autoscalingerr, ok := err.(awserr.Error)
if ok && autoscalingerr.Code() == "InvalidGroup.NotFound" {
d.SetId("")
return nil, nil
}
return nil, fmt.Errorf("Error retrieving AutoScaling groups: %s", err)
}
// Search for the autoscaling group
for idx, asc := range describeGroups.AutoScalingGroups {
if *asc.AutoScalingGroupName == d.Id() {
return describeGroups.AutoScalingGroups[idx], nil
}
}
// ASG not found
d.SetId("")
return nil, nil
}
示例15: resourceArmNetworkSecurityRuleRead
func resourceArmNetworkSecurityRuleRead(d *schema.ResourceData, meta interface{}) error {
secRuleClient := meta.(*ArmClient).secRuleClient
id, err := parseAzureResourceID(d.Id())
if err != nil {
return err
}
resGroup := id.ResourceGroup
networkSGName := id.Path["networkSecurityGroups"]
sgRuleName := id.Path["securityRules"]
resp, err := secRuleClient.Get(resGroup, networkSGName, sgRuleName)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on Azure Network Security Rule %s: %s", sgRuleName, err)
}
d.Set("resource_group_name", resGroup)
d.Set("access", resp.Properties.Access)
d.Set("destination_address_prefix", resp.Properties.DestinationAddressPrefix)
d.Set("destination_port_range", resp.Properties.DestinationPortRange)
d.Set("direction", resp.Properties.Direction)
d.Set("description", resp.Properties.Description)
d.Set("name", resp.Name)
d.Set("priority", resp.Properties.Priority)
d.Set("protocol", resp.Properties.Protocol)
d.Set("source_address_prefix", resp.Properties.SourceAddressPrefix)
d.Set("source_port_range", resp.Properties.SourcePortRange)
return nil
}