github.com/coreos/mantle@v0.13.0/platform/api/azure/groups.go (about)

     1  // Copyright 2018 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package azure
    16  
    17  import (
    18  	"time"
    19  
    20  	"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
    21  
    22  	"github.com/coreos/mantle/util"
    23  )
    24  
    25  func (a *API) CreateResourceGroup(prefix string) (string, error) {
    26  	name := randomName(prefix)
    27  	tags := map[string]*string{
    28  		"createdAt": util.StrToPtr(time.Now().Format(time.RFC3339)),
    29  		"createdBy": util.StrToPtr("mantle"),
    30  	}
    31  
    32  	_, err := a.rgClient.CreateOrUpdate(name, resources.Group{
    33  		Location: &a.opts.Location,
    34  		Tags:     &tags,
    35  	})
    36  	if err != nil {
    37  		return "", err
    38  	}
    39  
    40  	return name, nil
    41  }
    42  
    43  func (a *API) TerminateResourceGroup(name string) error {
    44  	resp, err := a.rgClient.CheckExistence(name)
    45  	if err != nil {
    46  		return err
    47  	}
    48  	if resp.StatusCode != 204 {
    49  		return nil
    50  	}
    51  
    52  	_, err = a.rgClient.Delete(name, nil)
    53  	return err
    54  }
    55  
    56  func (a *API) ListResourceGroups(filter string) (resources.GroupListResult, error) {
    57  	return a.rgClient.List(filter, nil)
    58  }