func Provider() terraform.ResourceProvider { provider := aws.Provider().(*schema.Provider) awsConfig := provider.Schema awsConfig["account"] = &schema.Schema{ Type: schema.TypeString, Required: true, Description: "The Yelp AWS account that is being used.\n" + "Current known account are (dev, devb, stagea, stageb, prod)", InputDefault: "dev", } instanceResource := provider.ResourcesMap["aws_instance"] ami := instanceResource.Schema["ami"] ami.Required = false ami.Optional = true ami.Computed = true instanceResource.Schema["ubuntu"] = &schema.Schema{ Type: schema.TypeString, Optional: true, Default: "lucid", ForceNew: true, } instanceResource.Create = wrapCreate(instanceResource.Create) instanceResource.Read = wrapCRUD(instanceResource.Read) instanceResource.Update = wrapCRUD(instanceResource.Update) instanceResource.Delete = wrapCRUD(instanceResource.Delete) return &schema.Provider{ Schema: awsConfig, ResourcesMap: map[string]*schema.Resource{ "yelpaws_instance": instanceResource, }, ConfigureFunc: wrapConfigure(provider.ConfigureFunc), } }
func Provider() terraform.ResourceProvider { provider := aws.Provider().(*schema.Provider) instance := provider.ResourcesMap["aws_s3_bucket_object"] instance.Create = wrapCreate(instance.Create) instance.Update = wrapCreate(instance.Update) return provider }
func parse_aws_instance(rs *terraform.ResourceState) (*InstanceInfo, error) { info := InstanceInfo{} provider := aws.Provider().(*schema.Provider) instanceSchema := provider.ResourcesMap["aws_instance"].Schema stateReader := &schema.MapFieldReader{ Schema: instanceSchema, Map: schema.BasicMapReader(rs.Primary.Attributes), } // nameResult, err := stateReader.ReadField([]string{"id"}) // if err != nil { // return nil, fmt.Errorf("Unable to read id field: %s", err) // } // info.Name = nameResult.ValueOrZero(instanceSchema["id"]).(string) info.Name = "moose" accessResult, err := stateReader.ReadField([]string{"public_ip"}) if err != nil { return nil, fmt.Errorf("Unable to read a public_ip field: %s", err) } info.Address = accessResult.ValueOrZero(instanceSchema["public_ip"]).(string) if info.Address == "" { accessResult, err := stateReader.ReadField([]string{"private_ip"}) if err != nil { return nil, fmt.Errorf("Unable to read a private_ip field: %s", err) } info.Address = accessResult.ValueOrZero(instanceSchema["private_ip"]).(string) } return &info, nil }