本文整理汇总了Golang中github.com/xanzy/terraform-api/helper/schema.ResourceData.GetOk方法的典型用法代码示例。如果您正苦于以下问题:Golang ResourceData.GetOk方法的具体用法?Golang ResourceData.GetOk怎么用?Golang ResourceData.GetOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xanzy/terraform-api/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.GetOk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceDigitalOceanFloatingIpUpdate
func resourceDigitalOceanFloatingIpUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client)
if d.HasChange("droplet_id") {
if v, ok := d.GetOk("droplet_id"); ok {
log.Printf("[INFO] Assigning the Floating IP %s to the Droplet %d", d.Id(), v.(int))
action, _, err := client.FloatingIPActions.Assign(d.Id(), v.(int))
if err != nil {
return fmt.Errorf(
"Error Assigning FloatingIP (%s) to the droplet: %s", d.Id(), err)
}
_, unassignedErr := waitForFloatingIPReady(d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if unassignedErr != nil {
return fmt.Errorf(
"Error waiting for FloatingIP (%s) to be Assigned: %s", d.Id(), unassignedErr)
}
} else {
log.Printf("[INFO] Unassigning the Floating IP %s", d.Id())
action, _, err := client.FloatingIPActions.Unassign(d.Id())
if err != nil {
return fmt.Errorf(
"Error Unassigning FloatingIP (%s): %s", d.Id(), err)
}
_, unassignedErr := waitForFloatingIPReady(d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if unassignedErr != nil {
return fmt.Errorf(
"Error waiting for FloatingIP (%s) to be Unassigned: %s", d.Id(), unassignedErr)
}
}
}
return resourceDigitalOceanFloatingIpRead(d, meta)
}
示例2: resourceDigitalOceanFloatingIpDelete
func resourceDigitalOceanFloatingIpDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client)
if _, ok := d.GetOk("droplet_id"); ok {
log.Printf("[INFO] Unassigning the Floating IP from the Droplet")
action, _, err := client.FloatingIPActions.Unassign(d.Id())
if err != nil {
return fmt.Errorf(
"Error Unassigning FloatingIP (%s) from the droplet: %s", d.Id(), err)
}
_, unassignedErr := waitForFloatingIPReady(d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if unassignedErr != nil {
return fmt.Errorf(
"Error waiting for FloatingIP (%s) to be unassigned: %s", d.Id(), unassignedErr)
}
}
log.Printf("[INFO] Deleting FloatingIP: %s", d.Id())
_, err := client.FloatingIPs.Delete(d.Id())
if err != nil {
return fmt.Errorf("Error deleting FloatingIP: %s", err)
}
d.SetId("")
return nil
}
示例3: resourceDigitalOceanFloatingIpCreate
func resourceDigitalOceanFloatingIpCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*godo.Client)
log.Printf("[INFO] Create a FloatingIP In a Region")
regionOpts := &godo.FloatingIPCreateRequest{
Region: d.Get("region").(string),
}
log.Printf("[DEBUG] FloatingIP Create: %#v", regionOpts)
floatingIp, _, err := client.FloatingIPs.Create(regionOpts)
if err != nil {
return fmt.Errorf("Error creating FloatingIP: %s", err)
}
d.SetId(floatingIp.IP)
if v, ok := d.GetOk("droplet_id"); ok {
log.Printf("[INFO] Assigning the Floating IP to the Droplet %d", v.(int))
action, _, err := client.FloatingIPActions.Assign(d.Id(), v.(int))
if err != nil {
return fmt.Errorf(
"Error Assigning FloatingIP (%s) to the droplet: %s", d.Id(), err)
}
_, unassignedErr := waitForFloatingIPReady(d, "completed", []string{"new", "in-progress"}, "status", meta, action.ID)
if unassignedErr != nil {
return fmt.Errorf(
"Error waiting for FloatingIP (%s) to be Assigned: %s", d.Id(), unassignedErr)
}
}
return resourceDigitalOceanFloatingIpRead(d, meta)
}
示例4: checkVolumeConfig
func checkVolumeConfig(d *schema.ResourceData) error {
// Although a volume_id is required to attach a volume, in order to be able to report
// the attached volumes of an instance, it must be "computed" and thus "optional".
// This accounts for situations such as "boot from volume" as well as volumes being
// attached to the instance outside of Terraform.
if v := d.Get("volume"); v != nil {
vols := v.(*schema.Set).List()
if len(vols) > 0 {
for _, v := range vols {
va := v.(map[string]interface{})
if va["volume_id"].(string) == "" {
return fmt.Errorf("A volume_id must be specified when attaching volumes.")
}
}
}
}
if vL, ok := d.GetOk("block_device"); ok {
if len(vL.([]interface{})) > 1 {
return fmt.Errorf("Can only specify one block device to boot from.")
}
}
return nil
}
示例5: getImageIDFromConfig
func getImageIDFromConfig(computeClient *gophercloud.ServiceClient, d *schema.ResourceData) (string, error) {
// If block_device was used, an Image does not need to be specified.
// If an Image was specified, ignore it
if _, ok := d.GetOk("block_device"); ok {
return "", nil
}
if imageId := d.Get("image_id").(string); imageId != "" {
return imageId, nil
} else {
// try the OS_IMAGE_ID environment variable
if v := os.Getenv("OS_IMAGE_ID"); v != "" {
return v, nil
}
}
imageName := d.Get("image_name").(string)
if imageName == "" {
// try the OS_IMAGE_NAME environment variable
if v := os.Getenv("OS_IMAGE_NAME"); v != "" {
imageName = v
}
}
if imageName != "" {
imageId, err := images.IDFromName(computeClient, imageName)
if err != nil {
return "", err
}
return imageId, nil
}
return "", fmt.Errorf("Neither a boot device, image ID, or image name were able to be determined.")
}
示例6: setImageInformation
func setImageInformation(computeClient *gophercloud.ServiceClient, server *servers.Server, d *schema.ResourceData) error {
// If block_device was used, an Image does not need to be specified.
// If an Image was specified, ignore it
if _, ok := d.GetOk("block_device"); ok {
d.Set("image_id", "Attempt to boot from volume - no image supplied")
return nil
}
imageId := server.Image["id"].(string)
if imageId != "" {
d.Set("image_id", imageId)
if image, err := images.Get(computeClient, imageId).Extract(); err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return err
}
if errCode.Actual == 404 {
// If the image name can't be found, set the value to "Image not found".
// The most likely scenario is that the image no longer exists in the Image Service
// but the instance still has a record from when it existed.
d.Set("image_name", "Image not found")
return nil
} else {
return err
}
} else {
d.Set("image_name", image.Name)
}
}
return nil
}
示例7: resourceAwsDirectoryServiceDirectoryUpdate
func resourceAwsDirectoryServiceDirectoryUpdate(d *schema.ResourceData, meta interface{}) error {
dsconn := meta.(*AWSClient).dsconn
if d.HasChange("enable_sso") {
d.SetPartial("enable_sso")
var err error
if v, ok := d.GetOk("enable_sso"); ok && v.(bool) {
log.Printf("[DEBUG] Enabling SSO for DS directory %q", d.Id())
_, err = dsconn.EnableSso(&directoryservice.EnableSsoInput{
DirectoryId: aws.String(d.Id()),
})
} else {
log.Printf("[DEBUG] Disabling SSO for DS directory %q", d.Id())
_, err = dsconn.DisableSso(&directoryservice.DisableSsoInput{
DirectoryId: aws.String(d.Id()),
})
}
if err != nil {
return err
}
}
return resourceAwsDirectoryServiceDirectoryRead(d, meta)
}
示例8: createActiveDirectoryService
func createActiveDirectoryService(dsconn *directoryservice.DirectoryService, d *schema.ResourceData) (directoryId string, err error) {
input := directoryservice.CreateMicrosoftADInput{
Name: aws.String(d.Get("name").(string)),
Password: aws.String(d.Get("password").(string)),
}
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
if v, ok := d.GetOk("short_name"); ok {
input.ShortName = aws.String(v.(string))
}
input.VpcSettings, err = buildVpcSettings(d)
if err != nil {
return "", err
}
log.Printf("[DEBUG] Creating Microsoft AD Directory Service: %s", input)
out, err := dsconn.CreateMicrosoftAD(&input)
if err != nil {
return "", err
}
log.Printf("[DEBUG] Microsoft AD Directory Service created: %s", out)
return *out.DirectoryId, nil
}
示例9: resourceCloudStackLoadBalancerRuleRead
func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)
// Get the load balancer details
lb, count, err := cs.LoadBalancer.GetLoadBalancerRuleByID(d.Id())
if err != nil {
if count == 0 {
log.Printf("[DEBUG] Load balancer rule %s does no longer exist", d.Get("name").(string))
d.SetId("")
return nil
}
return err
}
d.Set("algorithm", lb.Algorithm)
d.Set("public_port", lb.Publicport)
d.Set("private_port", lb.Privateport)
setValueOrID(d, "ipaddress", lb.Publicip, lb.Publicipid)
// Only set network if user specified it to avoid spurious diffs
if _, ok := d.GetOk("network"); ok {
network, _, err := cs.Network.GetNetworkByID(lb.Networkid)
if err != nil {
return err
}
setValueOrID(d, "network", network.Name, lb.Networkid)
}
return nil
}
示例10: resourceCloudStackVPCUpdate
func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)
// Check if the name or display text is changed
if d.HasChange("name") || d.HasChange("display_text") {
// Create a new parameter struct
p := cs.VPC.NewUpdateVPCParams(d.Id())
// Set the display text
displaytext, ok := d.GetOk("display_text")
if !ok {
displaytext = d.Get("name")
}
// Set the (new) display text
p.SetDisplaytext(displaytext.(string))
// Update the VPC
_, err := cs.VPC.UpdateVPC(p)
if err != nil {
return fmt.Errorf(
"Error updating VPC %s: %s", d.Get("name").(string), err)
}
}
return resourceCloudStackVPCRead(d, meta)
}
示例11: resourceAWSEbsVolumeUpdate
func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
if _, ok := d.GetOk("tags"); ok {
setTags(conn, d)
}
return resourceAwsEbsVolumeRead(d, meta)
}
示例12: resourceAwsCloudWatchLogGroupUpdate
func resourceAwsCloudWatchLogGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).cloudwatchlogsconn
name := d.Get("name").(string)
log.Printf("[DEBUG] Updating CloudWatch Log Group: %q", name)
if d.HasChange("retention_in_days") {
var err error
if v, ok := d.GetOk("retention_in_days"); ok {
input := cloudwatchlogs.PutRetentionPolicyInput{
LogGroupName: aws.String(name),
RetentionInDays: aws.Int64(int64(v.(int))),
}
log.Printf("[DEBUG] Setting retention for CloudWatch Log Group: %q: %s", name, input)
_, err = conn.PutRetentionPolicy(&input)
} else {
log.Printf("[DEBUG] Deleting retention for CloudWatch Log Group: %q", name)
_, err = conn.DeleteRetentionPolicy(&cloudwatchlogs.DeleteRetentionPolicyInput{
LogGroupName: aws.String(name),
})
}
return err
}
return resourceAwsCloudWatchLogGroupRead(d, meta)
}
示例13: resourceArmNetworkSecurityRuleCreate
func resourceArmNetworkSecurityRuleCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
secClient := client.secRuleClient
name := d.Get("name").(string)
nsgName := d.Get("network_security_group_name").(string)
resGroup := d.Get("resource_group_name").(string)
source_port_range := d.Get("source_port_range").(string)
destination_port_range := d.Get("destination_port_range").(string)
source_address_prefix := d.Get("source_address_prefix").(string)
destination_address_prefix := d.Get("destination_address_prefix").(string)
priority := d.Get("priority").(int)
access := d.Get("access").(string)
direction := d.Get("direction").(string)
protocol := d.Get("protocol").(string)
armMutexKV.Lock(nsgName)
defer armMutexKV.Unlock(nsgName)
properties := network.SecurityRulePropertiesFormat{
SourcePortRange: &source_port_range,
DestinationPortRange: &destination_port_range,
SourceAddressPrefix: &source_address_prefix,
DestinationAddressPrefix: &destination_address_prefix,
Priority: &priority,
Access: network.SecurityRuleAccess(access),
Direction: network.SecurityRuleDirection(direction),
Protocol: network.SecurityRuleProtocol(protocol),
}
if v, ok := d.GetOk("description"); ok {
description := v.(string)
properties.Description = &description
}
sgr := network.SecurityRule{
Name: &name,
Properties: &properties,
}
resp, err := secClient.CreateOrUpdate(resGroup, nsgName, name, sgr)
if err != nil {
return err
}
d.SetId(*resp.ID)
log.Printf("[DEBUG] Waiting for Network Security Rule (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"},
Target: "Succeeded",
Refresh: securityRuleStateRefreshFunc(client, resGroup, nsgName, name),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Network Securty Rule (%s) to become available: %s", name, err)
}
return resourceArmNetworkSecurityRuleRead(d, meta)
}
示例14: resourceAwsOpsworksStackDelete
func resourceAwsOpsworksStackDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*AWSClient).opsworksconn
req := &opsworks.DeleteStackInput{
StackId: aws.String(d.Id()),
}
log.Printf("[DEBUG] Deleting OpsWorks stack: %s", d.Id())
_, err := client.DeleteStack(req)
if err != nil {
return err
}
// For a stack in a VPC, OpsWorks has created some default security groups
// in the VPC, which it will now delete.
// Unfortunately, the security groups are deleted asynchronously and there
// is no robust way for us to determine when it is done. The VPC itself
// isn't deletable until the security groups are cleaned up, so this could
// make 'terraform destroy' fail if the VPC is also managed and we don't
// wait for the security groups to be deleted.
// There is no robust way to check for this, so we'll just wait a
// nominal amount of time.
_, inVpc := d.GetOk("vpc_id")
_, useOpsworksDefaultSg := d.GetOk("use_opsworks_security_group")
if inVpc && useOpsworksDefaultSg {
log.Print("[INFO] Waiting for Opsworks built-in security groups to be deleted")
time.Sleep(30 * time.Second)
}
return nil
}
示例15: resourceDNSimpleRecordCreate
func resourceDNSimpleRecordCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*dnsimple.Client)
// Create the new record
newRecord := &dnsimple.ChangeRecord{
Name: d.Get("name").(string),
Type: d.Get("type").(string),
Value: d.Get("value").(string),
}
if ttl, ok := d.GetOk("ttl"); ok {
newRecord.Ttl = ttl.(string)
}
log.Printf("[DEBUG] DNSimple Record create configuration: %#v", newRecord)
recId, err := client.CreateRecord(d.Get("domain").(string), newRecord)
if err != nil {
return fmt.Errorf("Failed to create DNSimple Record: %s", err)
}
d.SetId(recId)
log.Printf("[INFO] record ID: %s", d.Id())
return resourceDNSimpleRecordRead(d, meta)
}