本文整理汇总了Golang中github.com/xanzy/terraform-api/helper/schema.ResourceData.HasChange方法的典型用法代码示例。如果您正苦于以下问题:Golang ResourceData.HasChange方法的具体用法?Golang ResourceData.HasChange怎么用?Golang ResourceData.HasChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xanzy/terraform-api/helper/schema.ResourceData
的用法示例。
在下文中一共展示了ResourceData.HasChange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceAwsDbSubnetGroupUpdate
func resourceAwsDbSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
if d.HasChange("subnet_ids") {
_, n := d.GetChange("subnet_ids")
if n == nil {
n = new(schema.Set)
}
ns := n.(*schema.Set)
var sIds []*string
for _, s := range ns.List() {
sIds = append(sIds, aws.String(s.(string)))
}
_, err := conn.ModifyDBSubnetGroup(&rds.ModifyDBSubnetGroupInput{
DBSubnetGroupName: aws.String(d.Id()),
SubnetIds: sIds,
})
if err != nil {
return err
}
}
if arn, err := buildRDSsubgrpARN(d, meta); err == nil {
if err := setTagsRDS(conn, d, arn); err != nil {
return err
} else {
d.SetPartial("tags")
}
}
return resourceAwsDbSubnetGroupRead(d, meta)
}
示例2: resourceAwsIamUserUpdate
func resourceAwsIamUserUpdate(d *schema.ResourceData, meta interface{}) error {
if d.HasChange("name") || d.HasChange("path") {
iamconn := meta.(*AWSClient).iamconn
on, nn := d.GetChange("name")
_, np := d.GetChange("path")
request := &iam.UpdateUserInput{
UserName: aws.String(on.(string)),
NewUserName: aws.String(nn.(string)),
NewPath: aws.String(np.(string)),
}
log.Println("[DEBUG] Update IAM User request:", request)
_, err := iamconn.UpdateUser(request)
if err != nil {
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
log.Printf("[WARN] No IAM user by name (%s) found", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("Error updating IAM User %s: %s", d.Id(), err)
}
return resourceAwsIamUserRead(d, meta)
}
return nil
}
示例3: 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
}
示例4: 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)
}
示例5: 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)
}
示例6: resourceAwsRedshiftSubnetGroupUpdate
func resourceAwsRedshiftSubnetGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).redshiftconn
if d.HasChange("subnet_ids") {
_, n := d.GetChange("subnet_ids")
if n == nil {
n = new(schema.Set)
}
ns := n.(*schema.Set)
var sIds []*string
for _, s := range ns.List() {
sIds = append(sIds, aws.String(s.(string)))
}
_, err := conn.ModifyClusterSubnetGroup(&redshift.ModifyClusterSubnetGroupInput{
ClusterSubnetGroupName: aws.String(d.Id()),
SubnetIds: sIds,
})
if err != nil {
return err
}
}
return nil
}
示例7: 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)
}
示例8: resourceAzureAffinityGroupUpdate
// resourceAzureAffinityGroupUpdate does all the necessary API calls to
// update the state of the affinity group on Azure.
func resourceAzureAffinityGroupUpdate(d *schema.ResourceData, meta interface{}) error {
affinityGroupClient := meta.(*Client).affinityGroupClient
name := d.Get("name").(string)
clabel := d.HasChange("label")
cdesc := d.HasChange("description")
if clabel || cdesc {
log.Println("[INFO] Beginning Affinity Group update process.")
params := affinitygroup.UpdateAffinityGroupParams{}
if clabel {
params.Label = d.Get("label").(string)
}
if cdesc {
params.Description = d.Get("description").(string)
}
log.Println("[INFO] Sending Affinity Group update request to Azure.")
err := affinityGroupClient.UpdateAffinityGroup(name, params)
if err != nil {
return fmt.Errorf("Error updating Azure Affinity Group parameters: %s", err)
}
}
return nil
}
示例9: resourceAwsSqsQueueUpdate
func resourceAwsSqsQueueUpdate(d *schema.ResourceData, meta interface{}) error {
sqsconn := meta.(*AWSClient).sqsconn
attributes := make(map[string]*string)
resource := *resourceAwsSqsQueue()
for k, s := range resource.Schema {
if attrKey, ok := AttributeMap[k]; ok {
if d.HasChange(k) {
log.Printf("[DEBUG] Updating %s", attrKey)
_, n := d.GetChange(k)
if s.Type == schema.TypeInt {
attributes[attrKey] = aws.String(strconv.Itoa(n.(int)))
} else {
attributes[attrKey] = aws.String(n.(string))
}
}
}
}
if len(attributes) > 0 {
req := &sqs.SetQueueAttributesInput{
QueueUrl: aws.String(d.Id()),
Attributes: attributes,
}
sqsconn.SetQueueAttributes(req)
}
return resourceAwsSqsQueueRead(d, meta)
}
示例10: resourceAwsSubnetUpdate
func resourceAwsSubnetUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
d.Partial(true)
if err := setTags(conn, d); err != nil {
return err
} else {
d.SetPartial("tags")
}
if d.HasChange("map_public_ip_on_launch") {
modifyOpts := &ec2.ModifySubnetAttributeInput{
SubnetId: aws.String(d.Id()),
MapPublicIpOnLaunch: &ec2.AttributeBooleanValue{
Value: aws.Bool(d.Get("map_public_ip_on_launch").(bool)),
},
}
log.Printf("[DEBUG] Subnet modify attributes: %#v", modifyOpts)
_, err := conn.ModifySubnetAttribute(modifyOpts)
if err != nil {
return err
} else {
d.SetPartial("map_public_ip_on_launch")
}
}
d.Partial(false)
return resourceAwsSubnetRead(d, meta)
}
示例11: 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)
}
示例12: setAutoscalingTags
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tag"
func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) error {
if d.HasChange("tag") {
oraw, nraw := d.GetChange("tag")
o := setToMapByKey(oraw.(*schema.Set), "key")
n := setToMapByKey(nraw.(*schema.Set), "key")
resourceID := d.Get("name").(string)
c, r := diffAutoscalingTags(
autoscalingTagsFromMap(o, resourceID),
autoscalingTagsFromMap(n, resourceID),
resourceID)
create := autoscaling.CreateOrUpdateTagsInput{
Tags: c,
}
remove := autoscaling.DeleteTagsInput{
Tags: r,
}
// Set tags
if len(r) > 0 {
log.Printf("[DEBUG] Removing autoscaling tags: %#v", r)
if _, err := conn.DeleteTags(&remove); err != nil {
return err
}
}
if len(c) > 0 {
log.Printf("[DEBUG] Creating autoscaling tags: %#v", c)
if _, err := conn.CreateOrUpdateTags(&create); err != nil {
return err
}
}
}
return nil
}
示例13: resourceComputeTargetHttpProxyUpdate
func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
d.Partial(true)
if d.HasChange("url_map") {
url_map := d.Get("url_map").(string)
url_map_ref := &compute.UrlMapReference{UrlMap: url_map}
op, err := config.clientCompute.TargetHttpProxies.SetUrlMap(
config.Project, d.Id(), url_map_ref).Do()
if err != nil {
return fmt.Errorf("Error updating target: %s", err)
}
err = computeOperationWaitGlobal(config, op, "Updating Target Http Proxy")
if err != nil {
return err
}
d.SetPartial("url_map")
}
d.Partial(false)
return resourceComputeTargetHttpProxyRead(d, meta)
}
示例14: resourceComputeForwardingRuleUpdate
func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region := getOptionalRegion(d, config)
d.Partial(true)
if d.HasChange("target") {
target_name := d.Get("target").(string)
target_ref := &compute.TargetReference{Target: target_name}
op, err := config.clientCompute.ForwardingRules.SetTarget(
config.Project, region, d.Id(), target_ref).Do()
if err != nil {
return fmt.Errorf("Error updating target: %s", err)
}
err = computeOperationWaitRegion(config, op, region, "Updating Forwarding Rule")
if err != nil {
return err
}
d.SetPartial("target")
}
d.Partial(false)
return resourceComputeForwardingRuleRead(d, meta)
}
示例15: setTagsS3
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsS3(conn *s3.S3, d *schema.ResourceData) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsS3(tagsFromMapS3(o), tagsFromMapS3(n))
// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove)
_, err := conn.DeleteBucketTagging(&s3.DeleteBucketTaggingInput{
Bucket: aws.String(d.Get("bucket").(string)),
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
req := &s3.PutBucketTaggingInput{
Bucket: aws.String(d.Get("bucket").(string)),
Tagging: &s3.Tagging{
TagSet: create,
},
}
_, err := conn.PutBucketTagging(req)
if err != nil {
return err
}
}
}
return nil
}